human/demo/demo-esm-webworker.js

24 lines
679 B
JavaScript
Raw Normal View History

2020-10-14 02:52:30 +02:00
import human from '../dist/human.esm.js';
2020-10-15 21:25:58 +02:00
let config;
const log = (...msg) => {
// eslint-disable-next-line no-console
if (config.console) console.log(...msg);
};
2020-10-14 02:52:30 +02:00
onmessage = async (msg) => {
2020-10-16 00:16:05 +02:00
// worker.postMessage({ image: image.data.buffer, width: canvas.width, height: canvas.height, config }, [image.data.buffer]);
const image = new ImageData(new Uint8ClampedArray(msg.data.image), msg.data.width, msg.data.height);
2020-10-15 21:25:58 +02:00
config = msg.data.config;
let result = {};
try {
2020-10-16 00:16:05 +02:00
// result = await human.detect(image, config);
result = {};
2020-10-15 21:25:58 +02:00
} catch (err) {
result.error = err.message;
log('Worker thread error:', err.message);
}
2020-10-14 02:52:30 +02:00
postMessage(result);
};