fix safari incopatibility

pull/280/head
Vladimir Mandic 2021-01-12 08:24:00 -05:00
parent caa414835f
commit 44ae1b517a
3 changed files with 54 additions and 15 deletions

View File

@ -144,14 +144,14 @@ export default {
modelType: 'MobileNet', // Human includes MobileNet version, but you can switch to ResNet
},
pose: {
pose: { // TBD: not currently in use
enabled: false,
scoreThreshold: 0.6, // threshold for deciding when to remove boxes based on score
// in non-maximum suppression
iouThreshold: 0.3, // threshold for deciding whether boxes overlap too much
// in non-maximum suppression
modelPath: '../models/blazepose.json',
inputSize: 128, // fixed value
inputSize: 256, // fixed value
},
hand: {

View File

@ -446,27 +446,66 @@ class Human {
});
}
async warmup(userConfig) {
async warmupBitmap() {
const b64toBlob = (base64, type = 'application/octet-stream') => fetch(`data:${type};base64,${base64}`).then((res) => res.blob());
if (userConfig) this.config = mergeDeep(this.config, userConfig);
const video = this.config.videoOptimized;
this.config.videoOptimized = false;
let blob;
let res;
switch (this.config.warmup) {
case 'face': blob = await b64toBlob(sample.face); break;
case 'full': blob = await b64toBlob(sample.body); break;
default: blob = null;
}
if (!blob) return null;
const bitmap = await createImageBitmap(blob);
if (blob) {
const bitmap = await createImageBitmap(blob);
res = await this.detect(bitmap, config);
bitmap.close();
}
return res;
}
async warmupCanvas() {
return new Promise((resolve) => {
let src;
let size = 0;
switch (this.config.warmup) {
case 'face':
size = 256;
src = 'data:image/jpeg;base64,' + sample.face;
break;
case 'full':
size = 1200;
src = 'data:image/jpeg;base64,' + sample.body;
break;
default:
src = null;
}
const img = new Image(size, size);
img.onload = () => {
const canvas = (typeof OffscreenCanvas !== 'undefined') ? new OffscreenCanvas(size, size) : document.createElement('canvas');
canvas.width = size;
canvas.height = size;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
const data = ctx.getImageData(0, 0, size, size);
this.detect(data, config).then((res) => resolve(res));
};
if (src) img.src = src;
else resolve(null);
});
}
async warmup(userConfig) {
const t0 = now();
const warmup = await this.detect(bitmap, config);
const t1 = now();
bitmap.close();
log('Warmup', this.config.warmup, (t1 - t0), warmup);
if (userConfig) this.config = mergeDeep(this.config, userConfig);
const video = this.config.videoOptimized;
this.config.videoOptimized = false;
let res;
if (typeof createImageBitmap === 'function') res = await this.warmupBitmap();
else res = await this.warmupCanvas();
this.config.videoOptimized = video;
return warmup;
const t1 = now();
log('Warmup', this.config.warmup, (t1 - t0), res);
return res;
}
}

2
wiki

@ -1 +1 @@
Subproject commit 5aa552da6706eb513e7dc6b49302b689b682ca40
Subproject commit f31fa056967450ba8427bb2768db92cbe9b8cd8e