如何安装opencv4nodejs模块

时间:2019-09-07 06:00:14

标签: c++ node.js opencv npm cmake

嗨,我正在尝试在Node.js项目中使用opencv,因此我决定使用opencv4nodejs。我尝试通过npm安装此模块,但发现一些与计算机上缺少cmake有关的错误。因此,我决定通过cmake安装brew。但是在此过程之后,当我尝试安装此模块时,会发生以下错误:

MacBook-Air-Micha:webcam-myidea michalkukielka$ npm install opencv4nodejs

> opencv-build@0.1.8 install /Users/michalkukielka/Documents/webcam-myidea/node_modules/opencv-build
> node ./install.js

info No package.json in folder. 
info install if you want to use an own OpenCV installation set OPENCV4NODEJS_DISABLE_AUTOBUILD
info readAutoBuildFile file does not exists: /Users/michalkukielka/Documents/webcam-myidea/node_modules/opencv-build/opencv/auto-build.json /Users/michalkukielka/Documents/webcam-myidea/node_modules/opencv-build/opencv/auto-build.json
info install failed to find auto-build.json: /Users/michalkukielka/Documents/webcam-myidea/node_modules/opencv-build/opencv/auto-build.json
info install 
info install running install script...
info install 
info install opencv version: 3.4.6
info install with opencv contrib: yes
info install custom build flags: 
info install 
info install executing: git --version
info install git --version: git version 2.20.1
info install 
info install executing: cmake --version
info install cmake --version: cmake version 3.15.3
info install 
info install CMake suite maintained and supported by Kitware (kitware.com/cmake).
info install 
info install installing opencv version 3.4.6 into directory: /Users/michalkukielka/Documents/webcam-myidea/node_modules/opencv-build/opencv
Cloning into 'opencv_contrib'...
remote: Enumerating objects: 2160, done.
remote: Counting objects: 100% (2160/2160), done.
remote: Compressing objects: 100% (1916/1916), done.
remote: Total 2160 (delta 365), reused 1101 (delta 134), pack-reused 0
Receiving objects: 100% (2160/2160), 50.82 MiB | 1.57 MiB/s, done.
Resolving deltas: 100% (365/365), done.
Note: checking out 'f26c98365da6af93cb5e49397b571190fca7bb55'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

Checking out files: 100% (1780/1780), done.
Cloning into 'opencv'...
remote: Enumerating objects: 7328, done.
remote: Counting objects: 100% (7328/7328), done.
remote: Compressing objects: 100% (6260/6260), done.
remote: Total 7328 (delta 1166), reused 3907 (delta 692), pack-reused 0
Receiving objects: 100% (7328/7328), 81.33 MiB | 1.62 MiB/s, done.
Resolving deltas: 100% (1166/1166), done.
Note: checking out '33b765d7979fd8a6038026aa44f6ff1a9c082b7b'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

Checking out files: 100% (6080/6080), done.
info install running cmake /Users/michalkukielka/Documents/webcam-myidea/node_modules/opencv-build/opencv/opencv,-DCMAKE_INSTALL_PREFIX=/Users/michalkukielka/Documents/webcam-myidea/node_modules/opencv-build/opencv/build,-DCMAKE_BUILD_TYPE=Release,-DBUILD_EXAMPLES=OFF,-DBUILD_DOCS=OFF,-DBUILD_TESTS=OFF,-DBUILD_PERF_TESTS=OFF,-DBUILD_JAVA=OFF,-DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr,-DBUILD_opencv_apps=OFF,-DBUILD_opencv_aruco=OFF,-DBUILD_opencv_bgsegm=OFF,-DBUILD_opencv_bioinspired=OFF,-DBUILD_opencv_ccalib=OFF,-DBUILD_opencv_datasets=OFF,-DBUILD_opencv_dnn_objdetect=OFF,-DBUILD_opencv_dpm=OFF,-DBUILD_opencv_fuzzy=OFF,-DBUILD_opencv_hfs=OFF,-DBUILD_opencv_java_bindings_generator=OFF,-DBUILD_opencv_js=OFF,-DBUILD_opencv_img_hash=OFF,-DBUILD_opencv_line_descriptor=OFF,-DBUILD_opencv_optflow=OFF,-DBUILD_opencv_phase_unwrapping=OFF,-DBUILD_opencv_python3=OFF,-DBUILD_opencv_python_bindings_generator=OFF,-DBUILD_opencv_reg=OFF,-DBUILD_opencv_rgbd=OFF,-DBUILD_opencv_saliency=OFF,-DBUILD_opencv_shape=OFF,-DBUILD_opencv_stereo=OFF,-DBUILD_opencv_stitching=OFF,-DBUILD_opencv_structured_light=OFF,-DBUILD_opencv_superres=OFF,-DBUILD_opencv_surface_matching=OFF,-DBUILD_opencv_ts=OFF,-DBUILD_opencv_xobjdetect=OFF,-DBUILD_opencv_xphoto=OFF,-DWITH_VTK=OFF,-DOPENCV_ENABLE_NONFREE=ON,-DOPENCV_EXTRA_MODULES_PATH=/Users/michalkukielka/Documents/webcam-myidea/node_modules/opencv-build/opencv/opencv_contrib/modules
-- The CXX compiler identification is unknown
-- The C compiler identification is unknown
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
CMake Error at CMakeLists.txt:153 (message):
  CMake fails to determine the bitness of the target platform.

    Please check your CMake and compiler installation. If you are cross-compiling then ensure that your CMake toolchain file correctly sets the compiler details.


-- Configuring incomplete, errors occurred!
See also "/Users/michalkukielka/Documents/webcam-myidea/node_modules/opencv-build/opencv/build/CMakeFiles/CMakeOutput.log".
See also "/Users/michalkukielka/Documents/webcam-myidea/node_modules/opencv-build/opencv/build/CMakeFiles/CMakeError.log".
ERR! child process exited with code 1 (for more info, set '--loglevel silly') 

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! opencv-build@0.1.8 install: `node ./install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the opencv-build@0.1.8 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/michalkukielka/.npm/_logs/2019-09-07T05_38_02_479Z-debug.log

据我了解,cmake存在一些新问题,但我找不到解决方案。

您能帮我完成安装过程opencv4nodejs吗?

1 个答案:

答案 0 :(得分:1)

首先:本机节点模块是通过node-gyp构建的,默认情况下,npm已经附带了该模块。但是,node-gyp要求您安装python。如果您遇到node-gyp的特定问题,请首先查看node-gyp的已知问题。

重要说明: node-gyp无法正确处理空格,因此请确保项目目录的路径中不包含空格。在“ C:\ Program Files \ some_dir”或类似目录下安装opencv4nodejs将无法正常工作,并且将失败并显示:“致命错误C1083:无法打开包含文件:'opencv2 / core.hpp'”!**

在Windows上,您还将需要Windows Build Tools来编译OpenCV和opencv4nodejs。如果您没有安装Visual Studio或Windows生成工具,则可以轻松安装VS2015生成工具:

npm install --global windows-build-tools

第二步:您应该检查CMake和编译器的安装。如果要交叉编译,请确保CMake工具链文件正确设置了编译器详细信息。

CMake不(总是)收听CC和CXX。而是使用CMAKE_C_COMPILER和CMAKE_CXX_COMPILER:

cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ ...

另请参阅documentation

或者,您可以提供toolchain file,但是在这种情况下可能会显得过分。

最后:在OSX下,我们可以通过brew简单地安装OpenCV:

brew update
brew install opencv@4
brew link --force opencv@4