opencv4nodejs mac install
- Install Homebrew: Open Terminal and run the following command to install Homebrew, a package manager for macOS:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install OpenCV dependencies: Use Homebrew to install necessary dependencies for OpenCV:
brew install cmake pkg-config
brew install ffmpeg
brew install opencv
- Install opencv4nodejs: Run the following command to install the opencv4nodejs package via npm, the Node.js package manager:
npm install --save opencv4nodejs
- Set path variables: Ensure that OpenCV and its dependencies can be found by Node.js by setting the
PKG_CONFIG_PATH
environment variable. In your terminal, execute:
export PKG_CONFIG_PATH=/usr/local/opt/opencv@4/lib/pkgconfig
- Test installation: Verify that opencv4nodejs is correctly installed by writing a small Node.js script that imports and uses it:
```javascript const cv = require('opencv4nodejs');
// Test code const mat = new cv.Mat(5, 5, cv.CV_8UC3, [255, 0, 0]); console.log(mat); ```
Save this script into a file (e.g., test.js
) and execute it using Node.js:
node test.js
If no errors occur, and you see the output related to the created matrix, the installation is successful.