mirror of https://github.com/vladmandic/human
fix safari incopatibility
parent
caa414835f
commit
44ae1b517a
|
@ -144,14 +144,14 @@ export default {
|
||||||
modelType: 'MobileNet', // Human includes MobileNet version, but you can switch to ResNet
|
modelType: 'MobileNet', // Human includes MobileNet version, but you can switch to ResNet
|
||||||
},
|
},
|
||||||
|
|
||||||
pose: {
|
pose: { // TBD: not currently in use
|
||||||
enabled: false,
|
enabled: false,
|
||||||
scoreThreshold: 0.6, // threshold for deciding when to remove boxes based on score
|
scoreThreshold: 0.6, // threshold for deciding when to remove boxes based on score
|
||||||
// in non-maximum suppression
|
// in non-maximum suppression
|
||||||
iouThreshold: 0.3, // threshold for deciding whether boxes overlap too much
|
iouThreshold: 0.3, // threshold for deciding whether boxes overlap too much
|
||||||
// in non-maximum suppression
|
// in non-maximum suppression
|
||||||
modelPath: '../models/blazepose.json',
|
modelPath: '../models/blazepose.json',
|
||||||
inputSize: 128, // fixed value
|
inputSize: 256, // fixed value
|
||||||
},
|
},
|
||||||
|
|
||||||
hand: {
|
hand: {
|
||||||
|
|
63
src/human.js
63
src/human.js
|
@ -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());
|
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 blob;
|
||||||
|
let res;
|
||||||
switch (this.config.warmup) {
|
switch (this.config.warmup) {
|
||||||
case 'face': blob = await b64toBlob(sample.face); break;
|
case 'face': blob = await b64toBlob(sample.face); break;
|
||||||
case 'full': blob = await b64toBlob(sample.body); break;
|
case 'full': blob = await b64toBlob(sample.body); break;
|
||||||
default: blob = null;
|
default: blob = null;
|
||||||
}
|
}
|
||||||
if (!blob) return null;
|
if (blob) {
|
||||||
const bitmap = await createImageBitmap(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 t0 = now();
|
||||||
const warmup = await this.detect(bitmap, config);
|
if (userConfig) this.config = mergeDeep(this.config, userConfig);
|
||||||
const t1 = now();
|
const video = this.config.videoOptimized;
|
||||||
bitmap.close();
|
this.config.videoOptimized = false;
|
||||||
log('Warmup', this.config.warmup, (t1 - t0), warmup);
|
let res;
|
||||||
|
if (typeof createImageBitmap === 'function') res = await this.warmupBitmap();
|
||||||
|
else res = await this.warmupCanvas();
|
||||||
this.config.videoOptimized = video;
|
this.config.videoOptimized = video;
|
||||||
return warmup;
|
const t1 = now();
|
||||||
|
log('Warmup', this.config.warmup, (t1 - t0), res);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
wiki
2
wiki
|
@ -1 +1 @@
|
||||||
Subproject commit 5aa552da6706eb513e7dc6b49302b689b682ca40
|
Subproject commit f31fa056967450ba8427bb2768db92cbe9b8cd8e
|
Loading…
Reference in New Issue