-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
20 lines (14 loc) · 654 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { createImage, getImageInBase64, createFacebox, cleanFaceDetector } from "./utils/index.js";
const iptEl = document.querySelector('#ipt-file');
iptEl.addEventListener('change', async () => {
cleanFaceDetector();
const imgSource = await getImageInBase64(iptEl.files[0]);
const imgEl = await createImage(imgSource);
const scale = imgEl.width / imgEl.naturalWidth;
const faceDetector = new FaceDetector();
const faceDetectorData = await faceDetector.detect(imgEl);
faceDetectorData.forEach(({ boundingBox }) => {
const { width, height, top, left } = boundingBox;
createFacebox(width, height, top, left, scale);
});
});