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;
|
2020-10-18 20:14:05 +02:00
|
|
|
let busy = false;
|
2020-10-15 21:25:58 +02:00
|
|
|
|
|
|
|
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-18 20:14:05 +02:00
|
|
|
if (busy) return;
|
|
|
|
busy = true;
|
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 02:20:37 +02:00
|
|
|
result = await human.detect(image, config);
|
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);
|
2020-10-18 20:14:05 +02:00
|
|
|
busy = false;
|
2020-10-14 02:52:30 +02:00
|
|
|
};
|