opencv4nodejs: macOS Big Sur Install ALMOST THERE!!! (but fails because of Tracker / MultiTracker)

Trying the manual install, as per below (because the easier npm install opencv4nodejs fails in all sorts of ways!)

[march 23 notation: see next comment on this thread for possible culprit (was api changed to a legacy api by opencv.org?)]

[But now this seems important] brew-installed OpenCV4 (version 4.5.1_3)

But first, some info:

ProductName:	macOS
ProductVersion:	11.2.3 (Big Sur) [so, up to date]
BuildVersion:	20D91

uname -a: Darwin xxxxx.local 20.3.0 Darwin Kernel Version 20.3.0: xxxxxxnu-7195.81.3~1/RELEASE_X86_64 x86_64 node -v: v15.12.0 node-gyp -v: v7.1.2 python --version: Python 3.9.2

Added to ~/.zshrc for command line:

export OPENCV4NODEJS_DISABLE_AUTOBUILD=1
export OPENCV4NODEJS_DISABLE_EXTERNAL_MEM_TRACKING=1
export OPENCV_INCLUDE_DIR=/usr/local/Cellar/opencv/4.5.1_3/include/opencv4
export OPENCV_LIB_DIR=/usr/local/Cellar/opencv/4.5.1_3/lib
export OPENCV_BIN_DIR=/usr/local/Cellar/opencv/4.5.1_3/bin
export PATH=/usr/local/Cellar/opencv/4.5.1_3/bin:$PATH
set | grep OPEN
echo "\nall set for opencv4nodejs\nPATH=$PATH\n"

WITH OUTPUT (for new shell):

HELLO frederico, you b in ZSH mode, NOT bash

OPENCV4NODEJS_DISABLE_AUTOBUILD=1
OPENCV4NODEJS_DISABLE_EXTERNAL_MEM_TRACKING=1
OPENCV_BIN_DIR=/usr/local/Cellar/opencv/4.5.1_3/bin
OPENCV_INCLUDE_DIR=/usr/local/Cellar/opencv/4.5.1_3/include/opencv4
OPENCV_LIB_DIR=/usr/local/Cellar/opencv/4.5.1_3/lib

all set for opencv4nodejs

PATH=/usr/local/Cellar/opencv/4.5.1_3/bin:/Users/freddy/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands

THEN, npm install opencv4nodejs RESULTS:

added 30 packages, and audited 33 packages in 44s
found 0 vulnerabilities

THEN cd node_modules/opencv4nodejs/build and make V=1 RESULTS:

c++ -o Release/obj.target/opencv4nodejs/cc/tracking/tracking.o ../cc/tracking/tracking.cc '-DNODE_GYP_MODULE_NAME=opencv4nodejs' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DOPENCV4NODEJS_FOUND_LIBRARY_CORE' '-DOPENCV4NODEJS_FOUND_LIBRARY_HIGHGUI' '-DOPENCV4NODEJS_FOUND_LIBRARY_IMGCODECS' '-DOPENCV4NODEJS_FOUND_LIBRARY_IMGPROC' '-DOPENCV4NODEJS_FOUND_LIBRARY_FEATURES2D' '-DOPENCV4NODEJS_FOUND_LIBRARY_CALIB3D' '-DOPENCV4NODEJS_FOUND_LIBRARY_PHOTO' '-DOPENCV4NODEJS_FOUND_LIBRARY_OBJDETECT' '-DOPENCV4NODEJS_FOUND_LIBRARY_ML' '-DOPENCV4NODEJS_FOUND_LIBRARY_VIDEO' '-DOPENCV4NODEJS_FOUND_LIBRARY_VIDEOIO' '-DOPENCV4NODEJS_FOUND_LIBRARY_VIDEOSTAB' '-DOPENCV4NODEJS_FOUND_LIBRARY_DNN' '-DOPENCV4NODEJS_FOUND_LIBRARY_FACE' '-DOPENCV4NODEJS_FOUND_LIBRARY_TEXT' '-DOPENCV4NODEJS_FOUND_LIBRARY_TRACKING' '-DOPENCV4NODEJS_FOUND_LIBRARY_XFEATURES2D' '-DOPENCV4NODEJS_FOUND_LIBRARY_XIMGPROC' '-DBUILDING_NODE_EXTENSION' -I/Users/freddy/Library/Caches/node-gyp/15.12.0/include/node -I/Users/freddy/Library/Caches/node-gyp/15.12.0/src -I/Users/freddy/Library/Caches/node-gyp/15.12.0/deps/openssl/config -I/Users/freddy/Library/Caches/node-gyp/15.12.0/deps/openssl/openssl/include -I/Users/freddy/Library/Caches/node-gyp/15.12.0/deps/uv/include -I/Users/freddy/Library/Caches/node-gyp/15.12.0/deps/zlib -I/Users/freddy/Library/Caches/node-gyp/15.12.0/deps/v8/include -I/usr/local/Cellar/opencv/4.5.1_3/include/opencv4 -I../cc -I../cc/core -I../../nan -I/Users/freddy/devx/test-python-video-app1/node_modules/native-node-utils/src  -O3 -gdwarf-2 -mmacosx-version-min=10.9 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-strict-aliasing -std=c++11 -stdlib=libc++ -MMD -MF ./Release/.deps/Release/obj.target/opencv4nodejs/cc/tracking/tracking.o.d.raw   -c
In file included from ../cc/tracking/tracking.cc:6:
../cc/tracking/./Trackers/TrackerBoosting.h:8:14: error: no member named 'TrackerBoosting' in namespace 'cv'
        cv::Ptr<cv::TrackerBoosting> tracker;
                ~~~~^
In file included from ../cc/tracking/tracking.cc:7:
../cc/tracking/./Trackers/TrackerMedianFlow.h:8:14: error: no member named 'TrackerMedianFlow' in namespace 'cv'
        cv::Ptr<cv::TrackerMedianFlow> tracker;
                ~~~~^
In file included from ../cc/tracking/tracking.cc:9:
../cc/tracking/./Trackers/TrackerTLD.h:8:14: error: no member named 'TrackerTLD' in namespace 'cv'
        cv::Ptr<cv::TrackerTLD> tracker;
                ~~~~^
In file included from ../cc/tracking/tracking.cc:13:
../cc/tracking/MultiTracker.h:11:70: error: no member named 'MultiTracker' in namespace 'cv'
class MultiTracker : public FF::ObjectWrap<MultiTracker, cv::Ptr<cv::MultiTracker>> {
                                                                 ~~~~^
../cc/tracking/MultiTracker.h:30:2: error: expected a type
};
 ^
../cc/tracking/MultiTracker.h:30:2: error: expected '{' after base class list
In file included from ../cc/tracking/tracking.cc:21:
../cc/tracking/./Trackers/TrackerMOSSE.h:10:14: error: no member named 'TrackerMOSSE' in namespace 'cv'
        cv::Ptr<cv::TrackerMOSSE> tracker;
                ~~~~^
../cc/tracking/tracking.cc:35:16: error: no type named 'Init' in 'MultiTracker'
        MultiTracker::Init(target);
        ~~~~~~~~~~~~~~^
8 errors generated.
make: *** [Release/obj.target/opencv4nodejs/cc/tracking/tracking.o] Error 1

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 5
  • Comments: 19

Most upvoted comments

@frudman I found a solution for myself by removing SIFT 🎉, as I understand everything now on the 3 sides: OpenCV - OpenCV4NodeJS - Node-Gyp. I stick with OpenCV 4.5.0, only SIFT is the problem with this version, I build it without SIFT because SURF is an alternative and faster.

I compile opencv and opencv_contrib 4.5.0 manually following this tutorial: https://www.pyimagesearch.com/2018/08/17/install-opencv-4-on-macos/ . But I think brew install opencv@4 should work, if not installing 4.5.1 which causes MultiTracker problem.

1- Seems like there is a pause. 2 years is like abandon for me. I think 95% of what you want in Deep Learning can be achieved by this. It’s just that they did not update the codes to match lastest OpenCV structure changing, specially SIFT, SURF that are now patented (Non Commercial use only unless obtaining the right), MultiTracker algorithms that is moved, and FAST, FREAK that are alternative to SIFT and SURF.

2- I think there is a way. But easy or medium might depend on how the feature is called on other files. I just built it by disabling SIFT. I go to node_modules/opencv4nodejs/binding.gyp, and remove or comment the line: #"cc/xfeatures2d/SIFTDetector.cc",. And then:

cd node_modules/opencv4nodejs
node-gyp configure

then your file: node_modules/opencv4nodejs/build/opencv4nodejs.target.mk will go from:

$(obj).target/$(TARGET)/cc/xfeatures2d/xfeatures2d.o \
$(obj).target/$(TARGET)/cc/xfeatures2d/SIFTDetector.o
$(obj).target/$(TARGET)/cc/xfeatures2d/SURFDetector.o

to

$(obj).target/$(TARGET)/cc/xfeatures2d/xfeatures2d.o \
$(obj).target/$(TARGET)/cc/xfeatures2d/SURFDetector.o

But 1 other file in the code include SIFT file as hard coded, because they are still bound in this package. I commented out 2 lines, and node_modules/opencv4nodejs/cc/xfeatures2d/xfeatures2d.cc became:

#include "opencv_modules.h"

#ifdef HAVE_OPENCV_XFEATURES2D

#include "xfeatures2d.h"
// #include "SIFTDetector.h"
#include "SURFDetector.h"

NAN_MODULE_INIT(XFeatures2d::Init) {
	// SIFTDetector::Init(target);
	SURFDetector::Init(target);
};

#endif // HAVE_OPENCV_XFEATURES2D

And now I just install it with:

node install/install.js

And BOOM (you can see the generated : node_modules/opencv4nodejs/build/Release/opencv4nodejs.node file Screen Shot 2021-03-24 at 10 04 28 PM

3- I know some but I’m no expert in c/c++, but instead Javascript. As it appears, there is 2 places to handle it, either you add missing Multitracker back in it’s place, which can be cumbersome the way I see it in OpenCV, or you just change opencv4nodejs codes to adapt it to new emplacement, which is even harder the way Node-Gyp work to build native code into JS. OpenCV 4.5.0 and 4.5.1 has just been out, so if you don’t really have the obligation to use 4.5.1, I would suggest you to go with 4.5.0 instead. I was up for version 4.2 or even 3.4.6 if 4.5.0 couldn’t work, because old versions would match better with this package. What I’ve seen done with OpenCV 2.4 and 3 since 2016 is just incredible.

opencv4nodejs is tied to OpenCV classes and methods. It uses internally https://github.com/justadudewhohacks/native-node-utils, from the same hacker dude, and depends like you said from package node-gyp to build native code with native-code-utils codes implemented in opencv4nodejs.

4- OpenCV seems to be from a bunch of super genius guys that are more like Algorithm experts, System Engineers, Mathematicians, than normal Software Engineers. If it’s the case, that would explain those kind of quick changes that keep breaking tied packages from minor versions.

for Monterey, there were the same issues and more but finally have managed to solve opencv4nodejs installation issues and successfully installed it. (Xcode 13.2.1) it seems that cmake version can be the latest What have worked for me:

unset OPENCV4NODEJS_DISABLE_AUTOBUILD=1

npm -g uninstall opencv4nodejs
brew uninstall opencv
brew uninstall ffmpeg

if you have n:
n 14.18.1
or just have a node version of 14.18.1

brew install ffmpeg@4
npm i -g npm@6.14.11
brew unlink tesseract
export CXXFLAGS="-std=c++14 -Wno-c++11-narrowing"
npm -g install opencv4nodejs
brew link tesseract

@frudman I got the same issue this morning, OpenCV 4.5.1 put MultiTracker in a legacy directory of opencv2/tracking directory 4 months ago, which means opencv4nodejs package that has been updated 15 months ago, didn’t know about legacy of MultiTracker.

OpenCV 4.5.0 doesn’t have it in legacy, but whole version was updated 6 months ago.

Now I’m trying to find a version of OpenCV, between 4.1 (as example in the README) and 4.5.0 that is recent enough to compile correctly and old enough to be built with opencv4nodejs.

I first tried compiled with Brew brew installed opencv@4 (4.5.0_5), but wasn’t built in opencv4nodejs because CONTRIB modules SIFT and SURF were not found

I then tried compile manually OpenCV 4.5.1, success. But failed to be built in opencv4nodejs because of MultiTracker not found, which is now in Legacy.

Then I tried OpenCV 4.2.0, couldn’t compile, due to DNN module, Deep Neural Network for integration of external models like Tensorflow, Yolo, etc.

Now I’m gonna try version 4.5.0, because with Brew, those DNN compilation passed. I’m taking a chance with it.

If you find any version that fit, please tell me.

Those are others algorithms for image that are not implemented yet with opencv4nodejs: https://stackoverflow.com/a/33670318/5565544

You can try ORB (Oriented FAST and Rotated BRIEF) as an alternate to SURF in open cv. It almost works as good as SURF and SIFT and it’s free unlike SIFT and SURF which are patented and can’t be used commercially.

There is many of them.

SURF Feature Dectector example in case you decide like me to drop SIFT (it’s not that I had a choice, lol): https://docs.opencv.org/3.4/d7/d66/tutorial_feature_detection.html

Ok so I was able to get the full installation of opencv4nodejs working. I needed to downgrade node from version 16 to version 14 and do a little bit of compiler option digging!

Current Setup macOS Big Sur v11.6.1 Homebrew 3.3.2 opencv 4.5.3_2 node v14.18.1

Node installation (with Homebrew) brew install node@14

opencv installation (with Homebrew) brew install opencv

opencv4nodejs installtion (with node installer)

  • Before installing set both the following compiler flags export CXXFLAGS=“-std=c++14 -Wno-c++11-narrowing”
  • In the same terminal where you have set the above environment variables run the installation npm install opencv4nodejs

@seba-murillo it’s a good solution, passing the features build list instead of hacking package code directly. However, wouldn’t we loose the Tracker feature? Not everyone might need it though, but they’re gonna lose it, they gotta be aware of that.