Skip to content

Instantly share code, notes, and snippets.

@adwellj
Last active January 28, 2023 09:52
Show Gist options
  • Save adwellj/61e7f202bcfe5b96f312293e9c812ca6 to your computer and use it in GitHub Desktop.
Save adwellj/61e7f202bcfe5b96f312293e9c812ca6 to your computer and use it in GitHub Desktop.
Windows Global Install for opencv4nodejs

Installation

Start with node-gyp

You can install with npm:

$ npm install -g node-gyp

You will also need to install:

On Windows

Option 1 (what I've used)

From an elevated PowerShell or CMD.exe (run as Administrator), install all the required tools and configurations using Microsoft's windows-build-tools using npm install --global --production windows-build-tools.

If you already have Visual Studio installed, then Visual Studio Build Tools may fail. In that case launch cmd and enter npm config set msvs_version 2017.

Option 2

Install tools and configuration manually:

  • Install Visual C++ Build Environment: Visual Studio Build Tools (using "Visual C++ build tools" workload) or Visual Studio 2017 Community (using the "Desktop development with C++" workload)
  • Install Python 2.7 (v3.x.x is not supported), and run npm config set python python2.7 (or see below for further instructions on specifying the proper Python version and path.)
  • Launch cmd, npm config set msvs_version 2017

If the above steps didn't work for you, please visit Microsoft's Node.js Guidelines for Windows for additional tips.

If you have multiple Python versions installed, you can identify which Python version node-gyp uses by setting the '--python' variable:

$ node-gyp --python /path/to/python2.7

If node-gyp is called by way of npm, and you have multiple versions of Python installed, then you can set npm's 'python' config key to the appropriate value:

$ npm config set python /path/to/executable/python2.7

If windows-build-tools was installed, the Python 2.7 path should be C:\Users\<user>\.windows-build-tools\python27\.

Use the command below to check npm's 'python' config key value:

$ npm config get python

Install CMake

Download and install x64 version from: CMake Downloads

Add to PATH during install

Will need to execute remaining commands in new terminal for cmake to be recognized. Use cmake --version to confirm that it's installed and available.


Install opencv4nodejs:

Auto build

Verify that git is installed by using git --version; install if necessary.

If you do not want to set up OpenCV on your own you can simply let this package auto install OpenCV 3.4 + OpenCV contrib 3.4 (might take some time):

$ npm i -g opencv4nodejs

I've gotten errors about Visual Studio on a clean install (using just the windows-build-tools; not Visual Studio), and resolved that with a restart. I had also installed Visual Studio Build Tools, but the restart might have been all that was needed.

In order to prevent build errors during an npm install, your package.json should not include opencv4nodejs, and instead should include/require the global package either by requiring it by absolute path or setting the NODE_PATH environment variable to /usr/lib/node_modules in your Dockerfile and requiring the package as you normally would.

I chose to add a NODE_PATH environment variable. The install path will be displayed in the output of the previous command, but for me it was in C:\Users\<user>\AppData\Roaming\npm\node_modules.

@femto11
Copy link

femto11 commented Aug 8, 2019

Because I had problems getting my electron app running (it comlained about a module not being found in the temp folder although it was there), I also tried to manually install opencv and disable auto build as described here. The app is working now but only on my dev machine where opencv is installed. It seems like that electron builder did not move these dependencies into the packaged app. What I'm doing wrong here?

@adwellj
Copy link
Author

adwellj commented Aug 8, 2019

@femto11, I'm sorry to hear that. I'm not involved with opencv4nodejs, so you might try posting on that repo if you're looking for help. I created this document mostly to help me recall my steps for installation.

Unsure if it helps, but there is a section in the README for Usage with Electron.

@Kwaiyu
Copy link

Kwaiyu commented Jul 4, 2021

Regardless of manual or automatic construction, when the curl network is not good, the file size is 0, try to add raw.githubusercontent.com to the proxy rules to continue curl, otherwise manually download the file to the directory:

#!/bin/bash
cd ./cache/xfeatures2d/
cd boostdesc
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_lbgm.i> 0ae0675534aa318d9668f2a179c2a052-boostdesc_lbgm.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_256.i> e6dcfa9f647779eb1ce446a8d759b6ea-boostdesc_binboost_256.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_128.i> 98ea99d399965c03d555cef3ea502a0b-boostdesc_binboost_128.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_064.i> 202e1b3e9fec871b04da31f7f016679f-boostdesc_binboost_064.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_hd.i> 324426a24fa56ad9c5b8e3e0b3e5303e-boostdesc_bgm_hd.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_bi.i> 232c966b13651bd0e46a1497b0852191-boostdesc_bgm_bi.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm.i> 0ea90e7a8f3f7876d450e4149c97c74f-boostdesc_bgm.i
cd ../vgg
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_120.i> 151805e03568c9f490a5e3a872777b75-vgg_generated_120.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_64.i> 7126a5d9a8884ebca5aea5d63d677225-vgg_generated_64.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_48.i> e8d0dcd54d1bcfdc29203d011a797179-vgg_generated_48.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_80.i> 7cd47228edec52b6d82f46511af325c5-vgg_generated_80.i

Add these files to the “npm\node_modules\opencv4nodejs\node_modules\opencv-build\opencv\opencv_contrib\modules\xfeatures2d\src" folder if cache not available

@Shiju94253
Copy link

Shiju94253 commented Sep 29, 2022

Hi need help, I am new to testing and trying to work with Appium. When I run appium doctor I am getting the following result, kindly advice:
Kindly help me with "opencv4nodejs cannot be found." I am using Windows 11.
C:\Users\nshij>appium-doctor
WARN AppiumDoctor [Deprecated] Please use appium-doctor installed with "npm install @appium/doctor --location=global"
info AppiumDoctor Appium Doctor v.1.16.2
info AppiumDoctor ### Diagnostic for necessary dependencies starting ###
info AppiumDoctor ✔ The Node.js binary was found at: C:\Program Files\nodejs\node.EXE
info AppiumDoctor ✔ Node version is 18.9.1
info AppiumDoctor ✔ ANDROID_HOME is set to: C:\Users\nshij\AppData\Local\Android\Sdk
info AppiumDoctor ✔ JAVA_HOME is set to: C:\Program Files\Java\jdk-19
info AppiumDoctor Checking adb, android, emulator, apkanalyzer.bat
info AppiumDoctor 'adb' is in C:\Users\nshij\AppData\Local\Android\Sdk\platform-tools\adb.exe
info AppiumDoctor 'android' is in C:\Users\nshij\AppData\Local\Android\Sdk\tools\android.bat
info AppiumDoctor 'emulator' is in C:\Users\nshij\AppData\Local\Android\Sdk\emulator\emulator.exe
info AppiumDoctor 'apkanalyzer.bat' is in C:\Users\nshij\AppData\Local\Android\Sdk\cmdline-tools\latest\bin\apkanalyzer.bat
info AppiumDoctor ✔ adb, android, emulator, apkanalyzer.bat exist: C:\Users\nshij\AppData\Local\Android\Sdk
info AppiumDoctor ✔ 'bin' subfolder exists under 'C:\Program Files\Java\jdk-19'
info AppiumDoctor ### Diagnostic for necessary dependencies completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor ### Diagnostic for optional dependencies starting ###
WARN AppiumDoctor ✖ opencv4nodejs cannot be found.
info AppiumDoctor ✔ ffmpeg is installed at: C:\Program Files\ffmpeg\ffmpeg-5.1.2-essentials_build\bin\ffmpeg.EXE. ffmpeg version 5.1.2-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
info AppiumDoctor ✔ mjpeg-consumer is installed at: C:\Users\nshij\AppData\Roaming\npm. Installed version is: 2.0.0
info AppiumDoctor ✔ bundletool.jar is installed at: C:\Users\nshij\AppData\Local\Android\Sdk\bundle-tools\bundletool.jar
info AppiumDoctor ✔ gst-launch-1.0.exe and gst-inspect-1.0.exe are installed at: D:\gstreamer\1.0\msvc_x86_64\bin\gst-launch-1.0.exe and D:\gstreamer\1.0\msvc_x86_64\bin\gst-inspect-1.0.exe
info AppiumDoctor ### Diagnostic for optional dependencies completed, one fix possible. ###
info AppiumDoctor
info AppiumDoctor ### Optional Manual Fixes ###
info AppiumDoctor The configuration can install optionally. Please do the following manually:
WARN AppiumDoctor ➜ Why opencv4nodejs is needed and how to install it: http://appium.io/docs/en/writing-running-appium/image-comparison/
info AppiumDoctor
info AppiumDoctor ###
info AppiumDoctor
info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!

@adwellj
Copy link
Author

adwellj commented Sep 29, 2022

@Shiju94253, I'm not involved in this project; this is just a document I created a few years ago to help me recall my steps for installation. It's likely outdated at this point for various reasons. I would suggest going to the opencv4nodejs repo and checking there for help

I assume you tried the installation instructions below found in the link in the warning:
npm i -g opencv4nodejs

@Shiju94253
Copy link

Hi adwellj, tried all methods, was able to fix other otional dependencies like : ffmpeg, mjpeg,bundletool and gst, but I am unable to install opencv4nodejs. Kindly guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment