Windows上的opencv wasm构建失败

时间:2019-01-17 11:40:33

标签: c++ windows opencv webassembly

我正在尝试在Windows 10上构建OpenCV 4.0.0的wasm版本,但无法成功。我在这里和有关opencv和emscripten的github问题页面上阅读了很多有关类似问题的文章,尝试了建议的解决方案,但似乎没有一个适合我。

我的设置是:
操作系统-Windows 10 64位
OpenCV-v4.0.0(稳定)-我尝试从github克隆并下载预构建的二进制文件,也为v3.4.5
脚本-v1.38.22
python-与emscripten(2.7.13.1_64bit)捆绑在一起,还尝试了3.6.4
C ++编译器-minGW64
cmake-3.13.0
openCL标头-来自github
binaryen-来自github的version_63-我也尝试使用emsdk install命令进行安装
git-GitBash Windows版本

能起作用的东西:
-cmake(如某些帖子所建议,在GUI和命令行中)
-minGW64 g ++可以为win64生成适当的可执行文件
-opencv适用于g ++
-emscripten可以编译[hello world] .cpp

不起作用的东西:
-emscripten无法从opencv库生成LLVM位代码,但对于zlib可以正常工作-在这里,我按照emscripten docs中的说明进行操作
-它也无法编译使用像imread和imshow这样的opencv函数的简单.cpp文件:

error: undefined symbol: _ZN2cv17destroyAllWindowsEv
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
error: undefined symbol: _ZN2cv3Mat10deallocateEv
error: undefined symbol: _ZN2cv6imreadERKNSt3__212basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEi
error: undefined symbol: _ZN2cv6imshowERKNSt3__212basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERKNS_11_InputArrayE
error: undefined symbol: _ZN2cv7waitKeyEi
error: undefined symbol: _ZN2cv8fastFreeEPv
error: undefined symbol: _ZN2cv9thresholdERKNS_11_InputArrayERKNS_12_OutputArrayEddi
Error: Aborting compilation due to previous errors

在这里,我尝试按照github问题中的建议尝试使用标志-s ERROR_ON_UNDEFINED_SYMBOLS=0,确实将错误转为警告,但是生成的.js仍然不起作用,并且将这些确切的错误视为未定义的函数。

当我尝试构建带有或不带有--build_wasm选项的opencv.js 时,我得到:

C:\opencv>python platforms\js\build_js.py build_wasm --build_wasm --emscripten_dir d:\Download\gitEMSDK\emsdk\emscripten\1.38.22
Args: Namespace(build_dir='build_wasm', build_doc=False, build_test=False, build_wasm=True, clean_build_dir=False, config_only=False, disable_wasm=False, emscripten_dir='d:\\Download\\gitEMSDK\\emsdk\\emscripten\\1.38.22', enable_exception=False, opencv_dir='C:\\opencv', skip_config=False)
Check dir C:\opencv\build_wasm (create: True, clean: False)
Check dir C:\opencv (create: False, clean: False)
Check dir d:\Download\gitEMSDK\emsdk\emscripten\1.38.22 (create: False, clean: False)
=====
===== Config OpenCV.js build for wasm
=====
Executing: ['cmake', '-DCMAKE_BUILD_TYPE=Release', "-DCMAKE_TOOLCHAIN_FILE='d:\\Download\\gitEMSDK\\emsdk\\emscripten\\1.38.22\\cmake\\Modules\\Platform\\Emscripten.cmake'", "-DCPU_BASELINE=''", "-DCPU_DISPATCH=''", '-DCV_TRACE=OFF', '-DBUILD_SHARED_LIBS=OFF', '-DWITH_1394=OFF', '-DWITH_ADE=OFF', '-DWITH_VTK=OFF', '-DWITH_EIGEN=OFF', '-DWITH_FFMPEG=OFF', '-DWITH_GSTREAMER=OFF', '-DWITH_GTK=OFF', '-DWITH_GTK_2_X=OFF', '-DWITH_IPP=OFF', '-DWITH_JASPER=OFF', '-DWITH_JPEG=OFF', '-DWITH_WEBP=OFF', '-DWITH_OPENEXR=OFF', '-DWITH_OPENGL=OFF', '-DWITH_OPENVX=OFF', '-DWITH_OPENNI=OFF', '-DWITH_OPENNI2=OFF', '-DWITH_PNG=OFF', '-DWITH_TBB=OFF', '-DWITH_PTHREADS_PF=OFF', '-DWITH_TIFF=OFF', '-DWITH_V4L=OFF', '-DWITH_OPENCL=OFF', '-DWITH_OPENCL_SVM=OFF', '-DWITH_OPENCLAMDFFT=OFF', '-DWITH_OPENCLAMDBLAS=OFF', '-DWITH_GPHOTO2=OFF', '-DWITH_LAPACK=OFF', '-DWITH_ITT=OFF', '-DBUILD_ZLIB=ON', '-DBUILD_opencv_apps=OFF', '-DBUILD_opencv_calib3d=ON', '-DBUILD_opencv_dnn=ON', '-DBUILD_opencv_features2d=ON', '-DBUILD_opencv_flann=ON', '-DBUILD_opencv_gapi=OFF', '-DBUILD_opencv_ml=OFF', '-DBUILD_opencv_photo=ON', '-DBUILD_opencv_imgcodecs=OFF', '-DBUILD_opencv_shape=OFF', '-DBUILD_opencv_videoio=OFF', '-DBUILD_opencv_videostab=OFF', '-DBUILD_opencv_highgui=OFF', '-DBUILD_opencv_superres=OFF', '-DBUILD_opencv_stitching=OFF', '-DBUILD_opencv_java=OFF', '-DBUILD_opencv_js=ON', '-DBUILD_opencv_python2=OFF', '-DBUILD_opencv_python3=OFF', '-DBUILD_EXAMPLES=OFF', '-DBUILD_PACKAGE=OFF', '-DBUILD_TESTS=OFF', '-DBUILD_PERF_TESTS=OFF', '-DBUILD_DOCS=OFF', "-DCMAKE_C_FLAGS='-s WASM=1 '", "-DCMAKE_CXX_FLAGS='-s WASM=1 '", 'C:\\opencv']
Re-run cmake no build system arguments
-- Building for: Visual Studio 15 2017
-- Found PythonInterp: D:/Download/gitEMSDK/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/python.exe (found suitable version "2.7.13", minimum required is "2.7")
-- Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) (Required is at least version "2.7")
-- Cannot probe for Python/Numpy support (because we are cross-compiling OpenCV)
-- If you want to enable Python/Numpy support, set the following variables:
--   PYTHON2_INCLUDE_PATH
--   PYTHON2_LIBRARIES (optional on Unix-like systems)
--   PYTHON2_NUMPY_INCLUDE_DIRS
--   PYTHON3_INCLUDE_PATH
--   PYTHON3_LIBRARIES (optional on Unix-like systems)
--   PYTHON3_NUMPY_INCLUDE_DIRS
-- Could NOT find PythonInterp: Found unsuitable version "2.7.13", but required is at least "3.2" (found D:/Download/gitEMSDK/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/python.exe)
-- Performing Test HAVE_CXX_FSIGNED_CHAR
-- Performing Test HAVE_CXX_FSIGNED_CHAR - Failed
-- Performing Test HAVE_C_FSIGNED_CHAR
-- Performing Test HAVE_C_FSIGNED_CHAR - Failed
-- Performing Test HAVE_CXX_W
-- Performing Test HAVE_CXX_W - Failed
-- Performing Test HAVE_C_W
-- Performing Test HAVE_C_W - Failed
-- Performing Test HAVE_CXX_WALL
-- Performing Test HAVE_CXX_WALL - Failed
-- Performing Test HAVE_C_WALL
-- Performing Test HAVE_C_WALL - Failed
-- Performing Test HAVE_CXX_WERROR_RETURN_TYPE
-- Performing Test HAVE_CXX_WERROR_RETURN_TYPE - Failed
-- Performing Test HAVE_C_WERROR_RETURN_TYPE
-- Performing Test HAVE_C_WERROR_RETURN_TYPE - Failed
-- Performing Test HAVE_CXX_WERROR_NON_VIRTUAL_DTOR
-- Performing Test HAVE_CXX_WERROR_NON_VIRTUAL_DTOR - Failed
-- Performing Test HAVE_C_WERROR_NON_VIRTUAL_DTOR
-- Performing Test HAVE_C_WERROR_NON_VIRTUAL_DTOR - Failed
-- Performing Test HAVE_CXX_WERROR_ADDRESS
-- Performing Test HAVE_CXX_WERROR_ADDRESS - Failed
-- Performing Test HAVE_C_WERROR_ADDRESS
-- Performing Test HAVE_C_WERROR_ADDRESS - Failed
-- Performing Test HAVE_CXX_WERROR_SEQUENCE_POINT
-- Performing Test HAVE_CXX_WERROR_SEQUENCE_POINT - Failed
-- Performing Test HAVE_C_WERROR_SEQUENCE_POINT
-- Performing Test HAVE_C_WERROR_SEQUENCE_POINT - Failed
-- Performing Test HAVE_CXX_WFORMAT
-- Performing Test HAVE_CXX_WFORMAT - Failed
-- Performing Test HAVE_C_WFORMAT
-- Performing Test HAVE_C_WFORMAT - Failed
-- Performing Test HAVE_CXX_WERROR_FORMAT_SECURITY
-- Performing Test HAVE_CXX_WERROR_FORMAT_SECURITY - Failed
-- Performing Test HAVE_C_WERROR_FORMAT_SECURITY
-- Performing Test HAVE_C_WERROR_FORMAT_SECURITY - Failed
-- Performing Test HAVE_CXX_WMISSING_DECLARATIONS
-- Performing Test HAVE_CXX_WMISSING_DECLARATIONS - Failed
-- Performing Test HAVE_C_WMISSING_DECLARATIONS
-- Performing Test HAVE_C_WMISSING_DECLARATIONS - Failed
-- Performing Test HAVE_CXX_WMISSING_PROTOTYPES
-- Performing Test HAVE_CXX_WMISSING_PROTOTYPES - Failed
-- Performing Test HAVE_C_WMISSING_PROTOTYPES
-- Performing Test HAVE_C_WMISSING_PROTOTYPES - Failed
-- Performing Test HAVE_CXX_WSTRICT_PROTOTYPES
-- Performing Test HAVE_CXX_WSTRICT_PROTOTYPES - Failed
-- Performing Test HAVE_C_WSTRICT_PROTOTYPES
-- Performing Test HAVE_C_WSTRICT_PROTOTYPES - Failed
-- Performing Test HAVE_CXX_WUNDEF
-- Performing Test HAVE_CXX_WUNDEF - Failed
-- Performing Test HAVE_C_WUNDEF
-- Performing Test HAVE_C_WUNDEF - Failed
-- Performing Test HAVE_CXX_WINIT_SELF
-- Performing Test HAVE_CXX_WINIT_SELF - Failed
-- Performing Test HAVE_C_WINIT_SELF
-- Performing Test HAVE_C_WINIT_SELF - Failed
-- Performing Test HAVE_CXX_WPOINTER_ARITH
-- Performing Test HAVE_CXX_WPOINTER_ARITH - Failed
-- Performing Test HAVE_C_WPOINTER_ARITH
-- Performing Test HAVE_C_WPOINTER_ARITH - Failed
-- Performing Test HAVE_CXX_WSHADOW
-- Performing Test HAVE_CXX_WSHADOW - Failed
-- Performing Test HAVE_C_WSHADOW
-- Performing Test HAVE_C_WSHADOW - Failed
-- Performing Test HAVE_CXX_WSIGN_PROMO
-- Performing Test HAVE_CXX_WSIGN_PROMO - Failed
-- Performing Test HAVE_C_WSIGN_PROMO
-- Performing Test HAVE_C_WSIGN_PROMO - Failed
-- Performing Test HAVE_CXX_WUNINITIALIZED
-- Performing Test HAVE_CXX_WUNINITIALIZED - Failed
-- Performing Test HAVE_C_WUNINITIALIZED
-- Performing Test HAVE_C_WUNINITIALIZED - Failed
-- Performing Test HAVE_CXX_WINCONSISTENT_MISSING_OVERRIDE
-- Performing Test HAVE_CXX_WINCONSISTENT_MISSING_OVERRIDE - Failed
-- Performing Test HAVE_C_WINCONSISTENT_MISSING_OVERRIDE
-- Performing Test HAVE_C_WINCONSISTENT_MISSING_OVERRIDE - Failed
-- Performing Test HAVE_CXX_WNO_NARROWING
-- Performing Test HAVE_CXX_WNO_NARROWING - Failed
-- Performing Test HAVE_C_WNO_NARROWING
-- Performing Test HAVE_C_WNO_NARROWING - Failed
-- Performing Test HAVE_CXX_WNO_DELETE_NON_VIRTUAL_DTOR
-- Performing Test HAVE_CXX_WNO_DELETE_NON_VIRTUAL_DTOR - Failed
-- Performing Test HAVE_C_WNO_DELETE_NON_VIRTUAL_DTOR
-- Performing Test HAVE_C_WNO_DELETE_NON_VIRTUAL_DTOR - Failed
-- Performing Test HAVE_CXX_WNO_UNNAMED_TYPE_TEMPLATE_ARGS
-- Performing Test HAVE_CXX_WNO_UNNAMED_TYPE_TEMPLATE_ARGS - Failed
-- Performing Test HAVE_C_WNO_UNNAMED_TYPE_TEMPLATE_ARGS
-- Performing Test HAVE_C_WNO_UNNAMED_TYPE_TEMPLATE_ARGS - Failed
-- Performing Test HAVE_CXX_WNO_COMMENT
-- Performing Test HAVE_CXX_WNO_COMMENT - Failed
-- Performing Test HAVE_C_WNO_COMMENT
-- Performing Test HAVE_C_WNO_COMMENT - Failed
-- Performing Test HAVE_CXX_FDIAGNOSTICS_SHOW_OPTION
-- Performing Test HAVE_CXX_FDIAGNOSTICS_SHOW_OPTION - Failed
-- Performing Test HAVE_C_FDIAGNOSTICS_SHOW_OPTION
-- Performing Test HAVE_C_FDIAGNOSTICS_SHOW_OPTION - Failed
-- Performing Test HAVE_CXX_PTHREAD
-- Performing Test HAVE_CXX_PTHREAD - Failed
-- Performing Test HAVE_C_PTHREAD
-- Performing Test HAVE_C_PTHREAD - Failed
-- Performing Test HAVE_CXX_QUNUSED_ARGUMENTS
-- Performing Test HAVE_CXX_QUNUSED_ARGUMENTS - Failed
-- Performing Test HAVE_C_QUNUSED_ARGUMENTS
-- Performing Test HAVE_C_QUNUSED_ARGUMENTS - Failed
-- Performing Test HAVE_CXX_FFUNCTION_SECTIONS
-- Performing Test HAVE_CXX_FFUNCTION_SECTIONS - Failed
-- Performing Test HAVE_C_FFUNCTION_SECTIONS
-- Performing Test HAVE_C_FFUNCTION_SECTIONS - Failed
-- Performing Test HAVE_CXX_FDATA_SECTIONS
-- Performing Test HAVE_CXX_FDATA_SECTIONS - Failed
-- Performing Test HAVE_C_FDATA_SECTIONS
-- Performing Test HAVE_C_FDATA_SECTIONS - Failed
-- Performing Test HAVE_CPU_BASELINE_FLAGS
-- Performing Test HAVE_CPU_BASELINE_FLAGS - Failed
CMake Error at cmake/OpenCVCompilerOptimizations.cmake:524 (message):
  Compiler doesn't support baseline optimization flags:
Call Stack (most recent call first):
  cmake/OpenCVCompilerOptions.cmake:270 (ocv_compiler_optimization_options)
  CMakeLists.txt:682 (include)


-- Configuring incomplete, errors occurred!
See also "C:/opencv/build_wasm/CMakeFiles/CMakeOutput.log".
See also "C:/opencv/build_wasm/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
  File "platforms\js\build_js.py", line 224, in <module>
    builder.config()
  File "platforms\js\build_js.py", line 164, in config
    execute(cmd)
  File "platforms\js\build_js.py", line 23, in execute
    raise Fail("Child returned: %s" % retcode)
__main__.Fail: Child returned: 1

即使我遵循this post并在python2中使用了opencl,binaryen,cmake,emscripten_dir,

我还尝试了使用选项from here的直接cmake命令,例如:

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE='d:/microSoft/emsdk/emscripten/1.38.21/cmake/Modules/Platform/Emscripten.cmake' -DCPU_BASELINE='' -DCPU_DISPATCH='' -DCV_TRACE=OFF -DBUILD_SHARED_LIBS=OFF -DWITH_1394=OFF -DWITH_ADE=OFF -DWITH_VTK=OFF -DWITH_EIGEN=OFF -DWITH_FFMPEG=OFF -DWITH_GSTREAMER=OFF -DWITH_GTK=OFF -DWITH_GTK_2_X=OFF -DWITH_IPP=OFF -DWITH_JASPER=OFF -DWITH_JPEG=OFF -DWITH_WEBP=OFF -DWITH_OPENEXR=OFF -DWITH_OPENGL=OFF -DWITH_OPENVX=OFF -DWITH_OPENNI=OFF -DWITH_OPENNI2=OFF -DWITH_PNG=OFF -DWITH_TBB=OFF -DWITH_PTHREADS_PF=OFF -DWITH_TIFF=OFF -DWITH_V4L=OFF -DWITH_OPENCL=OFF -DWITH_OPENCL_SVM=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_GPHOTO2=OFF -DWITH_LAPACK=OFF -DWITH_ITT=OFF -DBUILD_ZLIB=ON -DBUILD_opencv_apps=OFF -DBUILD_opencv_calib3d=ON -DBUILD_opencv_dnn=ON -DBUILD_opencv_features2d=ON -DBUILD_opencv_flann=ON -DBUILD_opencv_gapi=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_photo=ON -DBUILD_opencv_imgcodecs=OFF -DBUILD_opencv_shape=OFF -DBUILD_opencv_videoio=OFF -DBUILD_opencv_videostab=OFF -DBUILD_opencv_highgui=OFF -DBUILD_opencv_superres=OFF -DBUILD_opencv_stitching=OFF -DBUILD_opencv_java=OFF -DBUILD_opencv_js=ON -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DBUILD_EXAMPLES=OFF -DBUILD_PACKAGE=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DPYTHON_EXECUTABLE=d:/microSoft/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/python.exe -DPYTHON_INCLUDE_DIRS=d:/microSoft/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/include -DPYTHON_LIBRARY=d:/microSoft/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/libs/libpython27.a -S . -B build_js

这完成了,但是mingw32-make失败了

如果您在我的设置或我尝试的命令中发现任何异常,请告诉我。任何建议都欢迎。 非常感谢。

1 个答案:

答案 0 :(得分:0)

似乎没有人在Windows下构建它。

仅启用Linux的Windows子系统,然后从商店中安装Ubuntu 1804 LTS。然后安装emsdk(WebAssembly)并在其下构建。

显然,OpenCV 4 .js构建包括WASM代码作为“ opencv.js”文件(https://github.com/opencv/opencv/issues/13356)中的变量(“ wasmBinaryFile”)。

https://docs.microsoft.com/en-us/windows/wsl/install-win10

https://webassembly.org/getting-started/developers-guide/

https://docs.opencv.org/trunk/d4/da1/tutorial_js_setup.html