45 lines
1.5 KiB
JavaScript
Vendored
45 lines
1.5 KiB
JavaScript
Vendored
const utils = new Utils('errorMessage'),
|
|
imageInput = document.getElementById('imageInput'),
|
|
fileInput = document.getElementById('fileInput');
|
|
|
|
fileInput.addEventListener('change', (e) => {
|
|
imageInput.src = URL.createObjectURL(e.target.files[0])
|
|
});
|
|
|
|
imageInput.onload = function () {
|
|
let src = cv.imread('imageInput');
|
|
let gray = new cv.Mat();
|
|
cv.cvtColor(src, gray, cv.COLOR_RGBA2GRAY, 0);
|
|
let faces = new cv.RectVector();
|
|
let faceCascade = new cv.CascadeClassifier();
|
|
faceCascade.load('haarcascade_frontalface_default.xml');
|
|
let msize = new cv.Size(0, 0);
|
|
faceCascade.detectMultiScale(gray, faces, 1.1, 3, 0, msize, msize);
|
|
|
|
for (let i = 0; i < faces.size(); ++i) {
|
|
console.log(faces)
|
|
let roiGray = gray.roi(faces.get(i));
|
|
let roiSrc = src.roi(faces.get(i));
|
|
let point1 = new cv.Point(faces.get(i).x, faces.get(i).y);
|
|
let point2 = new cv.Point(faces.get(i).x + faces.get(i).width,
|
|
faces.get(i).y + faces.get(i).height);
|
|
cv.rectangle(src, point1, point2, [255, 0, 0, 255]);
|
|
roiGray.delete();
|
|
roiSrc.delete();
|
|
}
|
|
cv.imshow('imageResult', src);
|
|
faces.delete();
|
|
src.delete();
|
|
gray.delete();
|
|
faceCascade.delete();
|
|
};
|
|
|
|
fileInput.setAttribute('disabled', 'true')
|
|
|
|
utils.loadOpenCv(() => {
|
|
let faceCascadeFile = 'haarcascade_frontalface_default.xml'
|
|
utils.createFileFromUrl(faceCascadeFile, faceCascadeFile, () => {
|
|
fileInput.removeAttribute('disabled');
|
|
});
|
|
});
|