opencv4nodejs: Can't install opencv4nodejs
- I tried to install into RasberryPi.
- I installed CMake already
- I set
export OPENCV4NODEJS_DISABLE_AUTOBUILD=0export OPENCV4NODEJS_AUTOBUILD_OPENCV_VERSION=4.1.0
- I tried to install opencv4nodejs via
npm i opencv4nodejs - I got the below error.
Error Message
$ npm i opencv4nodejs
> opencv4nodejs@5.6.0 install /home/pi/opencv-virtualuvc/node_modules/opencv4nodejs
> node ./install/install.js
info the following opencv4nodejs environment variables are set in the package.json:
info autoBuildFlags: -DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_PC_FILE_NAME=opencv.pc
info autoBuildOpencvVersion: 4.1.0
info install OPENCV_LIB_DIR is not set, looking for default lib dir
info install using lib dir: /usr/local/lib
/home/pi/opencv-virtualuvc/node_modules/opencv4nodejs/install/install.js:45
throw new Error('no OpenCV libraries found in lib dir: ' + libDir)
^
Error: no OpenCV libraries found in lib dir: /usr/local/lib
at Object.<anonymous> (/home/pi/opencv-virtualuvc/node_modules/opencv4nodejs/install/install.js:45:9)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! opencv4nodejs@5.6.0 install: `node ./install/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the opencv4nodejs@5.6.0 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! /home/pi/.npm/_logs/2020-06-19T22_35_51_386Z-debug.log
Auto Build - Full Error Log
I’d like Auto Build. But I don’t know where Auto Build Error Log is.
OpenCV version (example 3.4.1): ?.?.?
With OpenCV-contrib? (extra modules): ?
OS: Raspbian GNU/Linux 10 (buster)
$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 10 (buster)
Release: 10
Codename: buster
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 41 (2 by maintainers)
My steps for Mac using Intel chip
Worked fine, using node v16.13.1
I have done the manual installation steps and was able to make it work: https://github.com/justadudewhohacks/opencv4nodejs#installing-opencv-manually
set OPENCV4NODEJS_DISABLE_AUTOBUILD=1choco install OpenCV -y -version 4.1.0By default it installed OpenCV on my
C:\toolsfolder, so change the folders below according to your needsset OPENCV_INCLUDE_DIR=C:\tools\opencv\build\includeset OPENCV_LIB_DIR=C:\tools\opencv\build\x64\vc15\libset OPENCV_BIN_DIR=C:\tools\opencv\build\x64\vc15\binset PATH=%PATH%;%OPENCV_BIN_DIR%;set OPENCV4NODEJS_AUTOBUILD_OPENCV_VERSION=4.1.0npm i -g --save opencv4nodejsWith this I was able to get a successful installation of opencv4nodejs.
I did this installation to be able to use Appium findByImage feature, if you are trying to achieve the same then you might face more issues as I did, I was also able to get those solved but I did so much digging that I can’t remember every step I’ve done, but I found the problem was that node was having an issue finding the location of opencv in modules.
If you wanna do a quick check if you opencv is properly installed, create a project with the following content:
On app.js enter the following:
Then try to run this using node:
node app.js, if it works then you just need to do the npm link between appium and opencv4nodejs.macOS M1
brew install opencv export OPENCV_LIB_DIR=/opt/homebrew/opt/opencv@4/lib && export OPENCV4NODEJS_DISABLE_AUTOBUILD=1 npm i opencv4nodejs --save
throw new Error('no OpenCV libraries found in lib dir: ' + libDir)indicate that it is looking for thelibDir-folder which should be set when not using autobuild.Does the error persist if you
unset OPENCV4NODEJS_DISABLE_AUTOBUILD? I experienced that the mere presence of the env variable was interpreted as “truthy” no matter the value.Edit: Which I have opened a PR to solve - https://github.com/justadudewhohacks/npm-opencv-build/pull/42
specify environment variables or add them to the package.json
For Mac OS: Add following settings to
package.json. then runnpm i opencv4nodejsMust linux version install opencv on /usr/lib folder instead of /usr/local/lib. And the opencv-build dont´t autodetect folder from cmake files installed by opencv.
Maybe a quick solution just inform the environment variable OPENCV_LIB_DIR according to the opencv4nodejs documentation.
For me, this solution solved the problem.
export OPENCV_LIB_DIR=/usr/lib && export OPENCV4NODEJS_DISABLE_AUTOBUILD=1 && npm install opencv4nodejs
Assuming you’re not using autobuild, the issue is you aren’t telling npm where your OpenCV libraries are located!
I’m using Ubuntu 22. Here were my steps:
Install opencv using package manage: apt install libopencv-dev python3-opencv
Find location of where apt has installed the libraries using dpkg -L libopencv-dev (in my case, libraries were in /usr/lib/x86_64-linux-gnu )
Set autobuild off and set location of libraries: export OPENCV4NODEJS_DISABLE_AUTOBUILD=1 export OPENCV_LIB_DIR=/usr/lib/x86_64-linux-gnu
Install node module npm install opencv4nodejs
Good luck!
As my researching, there are no dylib files in
node_modules/opencv-build/opencv/build/libfolder on my MacOS. That is the reason why we getno OpenCV libraries found in lib direrror message. When I usebrewto installopencv,dylibfiles exist.This seemed to resolve this particular issue for me. Thank you 👍
its work
change npm i opencv4nodejs --save to npm i -g opencv4nodejs and appium-doctor all fun
brew install opencv
export OPENCV_LIB_DIR=/opt/homebrew/opt/opencv@4/lib export OPENCV4NODEJS_DISABLE_AUTOBUILD=1 export OPENCV_BIN_DIR=/opt/homebrew/opt/opencv@4/bin export OPENCV_INCLUDE_DIR=/opt/homebrew/opt/opencv@4/include/opencv4
npm install --save @u4/opencv4nodejs
node -e “console.log(require(‘@u4/opencv4nodejs’))”
And guess what… It doesn’t work for me
This should be the solution even in 2023.
doesn’t work on my m1 monterey too