opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

Issue building Face module for JS platform

Open svgorin opened this issue 5 years ago • 1 comments

System information (version)
Detailed description

opencv_js.config.py : face = {'': ['createFacemarkLBF', 'createFacemarkAAM', 'createFacemarkKazemi', 'drawFacemarks'], 'Facemark': ['fit', 'loadModel'], 'FacemarkLBF': [], 'FacemarkAAM': [], 'FacemarkKazemi': [], }

JS enabled in Face module make file.

Error:

100%] Generating bindings.cpp cd /home/svg/opencv/build_wasm/modules/js && /usr/bin/python2.7 /home/svg/opencv/modules/js/src/embindgen.py /home/svg/opencv/modules/js/../python/src2/hdr_parser.py /home/svg/opencv/build_wasm/modules/js/bindings.cpp /home/svg/opencv/build_wasm/modules/js/headers.txt /home/svg/opencv/modules/js/src/core_bindings.cpp Generator error: unable to resolve base face::Facemark for face_FacemarkKazemi make[3]: *** [modules/js/CMakeFiles/opencv_js.dir/build.make:143: modules/js/bindings.cpp] Error 255 make[3]: Leaving directory '/home/svg/opencv/build_wasm' make[2]: *** [CMakeFiles/Makefile2:3856: modules/js/CMakeFiles/opencv_js.dir/all] Error 2 make[2]: Leaving directory '/home/svg/opencv/build_wasm' make[1]: *** [CMakeFiles/Makefile2:3825: modules/js/CMakeFiles/opencv.js.dir/rule] Error 2 make[1]: Leaving directory '/home/svg/opencv/build_wasm' make: *** [Makefile:691: opencv.js] Error 2 Traceback (most recent call last): File "./platforms/js/build_js.py", line 284, in builder.build_opencvjs() File "./platforms/js/build_js.py", line 202, in build_opencvjs execute(["make", "-j", str(multiprocessing.cpu_count()), "opencv.js"]) File "./platforms/js/build_js.py", line 23, in execute raise Fail("Child returned: %s" % retcode) main.Fail: Child returned: 2

svgorin avatar Jul 11 '20 13:07 svgorin

The program embindgen.py assumes that the list of header filenames is being sorted in order of usage. It looks like the list is not sorted as such which causes facemark.hpp and facemark_train.hpp to be processed after face_alignment.hpp.

https://github.com/opencv/opencv/blob/9fcf0152140c449f74678add820e81de3e69b8b0/modules/js/generator/embindgen.py#L738

From what I can see there are two solutions:

  1. Parse the #include macros in the header files and make sure any dependencies are being processed first.
  2. Remove the check around line 328 that makes sure the base class exists.

Here's some quick and dirty code that allows you to compile without fixing this properly:

    def gen(self, dst_file, src_files, core_bindings):
        # step 0: sort headers
        filenameOrder = ['face_alignment.hpp', 'facemarkAAM.hpp', 'facemarkLBF.hpp']
        for filename in filenameOrder:
            index = next(i for i, v in enumerate(src_files) if v.endswith(filename))
            src_files.append(src_files.pop(index))

iclemens avatar Aug 17 '22 13:08 iclemens