opencv4nodejs
opencv4nodejs copied to clipboard
Can't install opencv4nodejs
- I tried to install into RasberryPi.
- I installed CMake already
- I set
-
export OPENCV4NODEJS_DISABLE_AUTOBUILD=0
-
export 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
> [email protected] 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! [email protected] install: `node ./install/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
I am also getting this same error whenever trying to npm install.
throw new Error('no OpenCV libraries found in lib dir: ' + libDir)
indicate that it is looking for the libDir
-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
unset OPENCV4NODEJS_DISABLE_AUTOBUILD
This seemed to resolve this particular issue for me. Thank you :+1:
As someone mentioned in one of the previous issues, manually building it worked for me.
First, go to the corresponding directory.
cd node_modules/opencv4nodejs/build
Then build manually.
make
Finally, add this to your package.json file, inside your "scripts"
"postinstall": "cd node_modules/opencv4nodejs/build; make"
I believe the problem is caused by a faulty autobuild.
I got solution.
Don't try to run npm from any of C:/Windows/... folder inside Windows
specify environment variables or add them to the package.json
"dependencies": {
"opencv4nodejs": "^5.6.0"
},
"opencv4nodejs": {
"disableAutoBuild": 1,
"opencvIncludeDir": "C:\\tools\\opencv\\build\\include",
"opencvLibDir": "C:\\tools\\opencv\\build\\x64\\vc14\\lib",
"opencvBinDir": "C:\\tools\\opencv\\build\\x64\\vc14\\bin"
},
Where can I find this> unset OPENCV4NODEJS_DISABLE_AUTOBUILD
Where can I find this> unset OPENCV4NODEJS_DISABLE_AUTOBUILD
Just type unset OPENCV4NODEJS_DISABLE_AUTOBUILD
in your terminal where you try to install opencv4nodejs
the same issue here
path /Users/mohamedgamal/node_modules/opencv4nodejs
npm ERR! command failed
npm ERR! command sh -c node ./install/install.js
npm ERR! info install OPENCV_LIB_DIR is not set, looking for default lib dir
npm ERR! info install using lib dir: /usr/local/lib
npm ERR! /Users/mohamedgamal/node_modules/opencv4nodejs/install/install.js:45
npm ERR! throw new Error('no OpenCV libraries found in lib dir: ' + libDir)
npm ERR! ^
npm ERR!
npm ERR! Error: no OpenCV libraries found in lib dir: /usr/local/lib
npm ERR! at Object.
npm ERR! A complete log of this run can be found in:
I am receiving this error as well, on the latest macos. Issuing unset OPENCV4NODEJS_DISABLE_AUTOBUILD
does not seem to have any affect.
is there any fix for this issue? I am doing unset OPENCV4NODEJS_DISABLE_AUTOBUILD
as well and it is still failing
$ npm i -g opencv4nodejs
npm ERR! code 1
npm ERR! path /opt/homebrew/lib/node_modules/opencv4nodejs
npm ERR! command failed
npm ERR! command sh -c node ./install/install.js
npm ERR! info install using lib dir: /opt/homebrew/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/build/lib
npm ERR! /opt/homebrew/lib/node_modules/opencv4nodejs/install/install.js:37
npm ERR! throw new Error('library dir does not exist: ' + libDir)
npm ERR! ^
npm ERR!
npm ERR! Error: library dir does not exist: /opt/homebrew/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/build/lib
npm ERR! at Object.<anonymous> (/opt/homebrew/lib/node_modules/opencv4nodejs/install/install.js:37:9)
npm ERR! at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR! at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR! at Module.load (node:internal/modules/cjs/loader:981:32)
npm ERR! at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR! at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
npm ERR! at node:internal/main/run_main_module:17:47
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/fbernaly/.npm/_logs/2021-09-17T20_17_41_740Z-debug.log
Is there a genuine solution to this problem? I cannot find the opencv4nodejs under lib/node_modules PS: I'm using Linuxbrew on Ubuntu 20.0.04
Fedora 34, same issue
[user@user-pc cardet]$ npm install --save opencv4nodejs
npm ERR! code 1
npm ERR! path /home/user/WebstormProjects/cardet/node_modules/opencv4nodejs
npm ERR! command failed
npm ERR! command sh -c node ./install/install.js
npm ERR! info install using lib dir: /home/user/WebstormProjects/cardet/node_modules/opencv-build/opencv/build/lib
npm ERR! /home/user/WebstormProjects/cardet/node_modules/opencv4nodejs/install/install.js:37
npm ERR! throw new Error('library dir does not exist: ' + libDir)
npm ERR! ^
npm ERR!
npm ERR! Error: library dir does not exist: /home/user/WebstormProjects/cardet/node_modules/opencv-build/opencv/build/lib
npm ERR! at Object.<anonymous> (/home/user/WebstormProjects/cardet/node_modules/opencv4nodejs/install/install.js:37:9)
npm ERR! at Module._compile (node:internal/modules/cjs/loader:1095:14)
npm ERR! at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
npm ERR! at Module.load (node:internal/modules/cjs/loader:975:32)
npm ERR! at Function.Module._load (node:internal/modules/cjs/loader:816:12)
npm ERR! at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
npm ERR! at node:internal/main/run_main_module:17:47
npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2021-10-12T13_29_52_707Z-debug.log
I have done the manual installation steps and was able to make it work: https://github.com/justadudewhohacks/opencv4nodejs#installing-opencv-manually
- Install Chocolatey
- Open cmd and set his env variable
set OPENCV4NODEJS_DISABLE_AUTOBUILD=1
- Install OpenCV with this command:
choco install OpenCV -y -version 4.1.0
By default it installed OpenCV on my C:\tools
folder, so change the folders below according to your needs
- Set more env vars:
set OPENCV_INCLUDE_DIR=C:\tools\opencv\build\include
set OPENCV_LIB_DIR=C:\tools\opencv\build\x64\vc15\lib
set OPENCV_BIN_DIR=C:\tools\opencv\build\x64\vc15\bin
set PATH=%PATH%;%OPENCV_BIN_DIR%;
set OPENCV4NODEJS_AUTOBUILD_OPENCV_VERSION=4.1.0
- Run
npm i -g --save opencv4nodejs
With 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:
root/node_modules/
root/app.js
On app.js enter the following:
let opencv = require('opencv4nodejs');
console.log("success")
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.
I am facing the same installation failure issue in mac. Can someone please guide me on how to install opencv4nodejs in MAC device? Error log: code 1 npm ERR! path /Users/mac/node_modules/opencv4nodejs npm ERR! command failed npm ERR! command sh -c node ./install/install.js npm ERR! info install using lib dir: /Users/mac/node_modules/opencv-build/opencv/build/lib npm ERR! /Users/mac/node_modules/opencv4nodejs/install/install.js:37 npm ERR! throw new Error('library dir does not exist: ' + libDir) npm ERR! ^ npm ERR! npm ERR! Error: library dir does not exist: /Users/mac/node_modules/opencv-build/opencv/build/lib
node
i got this error too, and spent almost one day to search and try solutions for that, but i failed to solve the error.
node
i got this error too, and spent almost one day to search and try solutions for that, but i failed to solve the error.
First, install opencv on your machine
apt install libopencv-dev python3-opencv
Second, checking if opencv is avaiable
python3
import cv2 as cv
print(cv.__version__)
Then install opencv4nodejs
sudo npm install opencv4nodejs --save
I have done the manual installation steps and was able to make it work: https://github.com/justadudewhohacks/opencv4nodejs#installing-opencv-manually
- Install Chocolatey
- Open cmd and set his env variable
set OPENCV4NODEJS_DISABLE_AUTOBUILD=1
- Install OpenCV with this command:
choco install OpenCV -y -version 4.1.0
By default it installed OpenCV on my
C:\tools
folder, so change the folders below according to your needs
- Set more env vars:
set OPENCV_INCLUDE_DIR=C:\tools\opencv\build\include
set OPENCV_LIB_DIR=C:\tools\opencv\build\x64\vc15\lib
set OPENCV_BIN_DIR=C:\tools\opencv\build\x64\vc15\bin
set PATH=%PATH%;%OPENCV_BIN_DIR%;
set OPENCV4NODEJS_AUTOBUILD_OPENCV_VERSION=4.1.0
- Run
npm i -g --save opencv4nodejs
With 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:
root/node_modules/ root/app.js
On app.js enter the following:
let opencv = require('opencv4nodejs'); console.log("success")
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.
Everyone who is coming to this at a later date this is the only working solution I found
As my researching, there are no dylib files in node_modules/opencv-build/opencv/build/lib
folder on my MacOS. That is the reason why we get no OpenCV libraries found in lib dir
error message.
When I use brew
to install opencv
, dylib
files exist.
My steps for Mac using Intel chip
- brew install opencv
- export OPENCV4NODEJS_DISABLE_AUTOBUILD=1
- npm i -g opencv4nodejs
Worked fine, using node v16.13.1
Must 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
My steps for Mac using Intel chip
- brew install opencv
- export OPENCV4NODEJS_DISABLE_AUTOBUILD=1
- npm i -g opencv4nodejs
Worked fine, using node v16.13.1
worked fine for me on mac M1, thanks!
My steps for Mac using Intel chip
- brew install opencv
- export OPENCV4NODEJS_DISABLE_AUTOBUILD=1
- npm i -g opencv4nodejs
Worked fine, using node v16.13.1
worked fine for me on mac M1, thanks!
this does not work for me in my mac monterary
My steps for Mac using Intel chip
- brew install opencv
- export OPENCV4NODEJS_DISABLE_AUTOBUILD=1
- npm i -g opencv4nodejs
Worked fine, using node v16.13.1
worked fine for me on mac M1, thanks!
doesn't work on my m1 monterey too
Is this issue solved?
at least it works with my fork, but you should only use a prebuilt openCV (the one from brew working fine) building from source is complicated due to the FFmpeg 5 compatibility issue.
Must 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
That solved my issue except for the path to my lib folder was at /opt/homebrew/lib
the code is here
it look for open CV in /opt/homebrew/Cellar/opencv/*
if you are using a standard setup, I can add a new search path.
Personally, I don't think we should use open cv with nodejs. It's a hectic job to set up it. I would prefer opencv with python.
specify environment variables or add them to the package.json
"dependencies": { "opencv4nodejs": "^5.6.0" }, "opencv4nodejs": { "disableAutoBuild": 1, "opencvIncludeDir": "C:\\tools\\opencv\\build\\include", "opencvLibDir": "C:\\tools\\opencv\\build\\x64\\vc14\\lib", "opencvBinDir": "C:\\tools\\opencv\\build\\x64\\vc14\\bin" },
This was the one that worked for me did "npm install robotjs" first to get the framework file then removed the "node_modules" replaced package.json content with { "opencv4nodejs": { "disableAutoBuild": 1, "opencvIncludeDir": "C:\tools\opencv\build\include", "opencvLibDir": "C:\tools\opencv\build\x64\vc14\lib", "opencvBinDir": "C:\tools\opencv\build\x64\vc14\bin" }, "dependencies": { "opencv4nodejs": "^5.6.0" } } and after that I ran "npm install opencv4nodejs" and it got downloaded in 3m. Download opencv from a website and make those tools/opencv.... system variables to make it all work. Hopefully this helped anyone.