opencv.js building WASM cv.face.createFacemarkLBF()
When using the detectMultiScale function, it throws a binding error.
I understand that OpenCV.js loads and fires the onload event before it's really initialized. To wait until OpenCV.js is really ready, we have to do: cv['onRuntimeInitialized']=()=>{ // do all your work here };
I understand that files need to be created in memory and OpenCV.js has an non-advertised utility class called Utils that can be used for exactly that and other useful operations.
So I did the following;
cv['onRuntimeInitialized']=()=>{
// do all your work here
let utils = new Utils('errorMessage');
let faceCascadeFile = 'haarcascade_frontalface_alt2.xml';
let faceCascade = new cv.CascadeClassifier();
let src = cv.imread('imageSrc');
let gray = new cv.Mat();
cv.cvtColor(src, gray, cv.COLOR_RGBA2GRAY, 0);
let faces = new cv.RectVector();
let msize = new cv.Size(0, 0);
console.log("face CascadeClassifier");
utils.createFileFromUrl(faceCascadeFile, faceCascadeFile, () => {
faceCascade.load(faceCascadeFile);
faceCascade.detectMultiScale(gray, faces, 1.1, 3, 0, msize, msize);
let facemark = new cv.face.createFacemarkLBF();
console.log('yes cascade ready to load.');
});
};
I get the following error: Uncaught TypeError: Cannot read property 'createFacemarkLBF' of undefined
Is there any work around solution to solve this?
Thanks in advance!
wait, wait, the opencv_contrib face module was never wrapped for javascript, you cannot use the facemark code without adding your own bindings for it here
Added the following def get_cmake_cmd(self): of opencv/platforms/js/build_js.py:
-DOPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules
Appended
js
inside ocv_define_module of opencv_contrib/modules/face/CMakeLists.txt.Added the face module in the opencv/modules/js/src/embindgen.py
face = {'': ['createFacemarkLBF', 'createFacemarkAAM', 'createFacemarkKazemi', 'drawFacemarks'], 'Facemark': ['fit', 'loadModel'], 'FacemarkLBF': [], 'FacemarkAAM'': [], 'FacemarkKazemi': [], }
Added the face module to the makeWhiteList in the opencv/modules/js/src/embindgen.py
white_list = makeWhiteList([core, imgproc, objdetect, video, dnn, features2d, photo, aruco, calib3d, face])
Added "using namespace face;" in core_bindings.cpp
Keep in mind that the facemark code was developed during GSoC2017 and is still since then in contrib module because of the fact it was not fully complete. Furthermore, in current GSoC2019, there is an active project rearranging everything, so watch out with putting in to much effort. that being said, the opencv.js bindings for this module have never been tested/debugged so far, so no guarantee it will work at all.