Registry / ai-ml / opencv-build

opencv-build

JSON →
library0.1.9jsnpmunverified

opencv-build is an npm package designed to automate the compilation of the native OpenCV library, including its `contrib` modules, from source code. It primarily serves as a crucial build dependency for Node.js projects that integrate with OpenCV, most notably `opencv4nodejs`. This package abstracts away the complex, platform-specific steps of fetching OpenCV source, configuring the build with CMake, and compiling the binaries, which is vital for enabling computer vision capabilities in Node.js applications across different operating systems. While the specific version `0.1.9` is older, the underlying build automation approach is still actively maintained and evolved, often through similar packages like `@u4/opencv-build` for current `opencv4nodejs` versions. Its key differentiator is providing a configurable, automated native build process for a significant external dependency, streamlining development workflows by minimizing manual native compilation efforts and ensuring compatibility with the Node.js runtime. Releases are typically tied to the needs of `opencv4nodejs` and OpenCV's own release cycle, without a strict independent cadence.

npm install opencv-build
INSTALL
IMPORT
SIG · OPENCV-BUILD
O
opencv-build
ai-mljavascriptv0.1.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

This quickstart demonstrates how to configure `opencv-build` via the `package.json` for an `opencv4nodejs` project, enabling custom OpenCV versions and build flags. `opencv-build` executes during `npm install` of `opencv4nodejs`.

{ "name": "my-opencv-project", "version": "1.0.0", "description": "Example project using opencv4nodejs with custom build flags", "main": "index.js", "scripts": { "start": "node index.js" }, "dependencies": { "opencv4nodejs": "^7.0.0", "opencv-build": "^0.1.9" }, "opencv4nodejs": { "autoBuildFlags": "-DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_PC_FILE_NAME=opencv.pc -DBUILD_EXAMPLES=OFF", "autoBuildOpencvVersion": "4.5.5", "autoBuildWithoutContrib": false, "autoBuildBuildCuda": false }, "keywords": [], "author": "", "license": "MIT" } // In index.js (demonstrates opencv4nodejs usage, not opencv-build directly) const cv = require('opencv4nodejs'); async function runOpenCV() { // Ensure OpenCV is built by opencv-build when opencv4nodejs is installed console.log('OpenCV version:', cv.version); const mat = new cv.Mat(100, 100, cv.CV_8UC3, [0, 0, 0]); // Black image mat.drawCircle(new cv.Point(50, 50), 20, new cv.Vec(0, 255, 0), -1); // Green circle cv.imshowWait('Image', mat); cv.destroyAllWindows(); console.log('Image displayed and closed.'); } runOpenCV().catch(err => console.error(err));
Debug
Known issues
breakingThe `opencv-build` package is an auto-build script for native OpenCV binaries. It requires `cmake` to be installed and available in the system's PATH. On Windows, Visual Studio Build Tools (or `windows-build-tools`) are also necessary for successful compilation. Absence of these prerequisites will lead to build failures during `npm install`.
fix
Ensure `cmake` is installed globally (`npm install -g cmake` or via system package manager). On Windows, run `npm install --global windows-build-tools` or install Visual Studio with C++ development workload.
affects: >=0.1.0
gotchaBuilding OpenCV from source is a resource-intensive process. It can take a significant amount of time (often 10-30 minutes or more, depending on system specs) and consume several gigabytes of disk space for source files, build artifacts, and intermediate compilation outputs. This is a common point of frustration for developers, especially on CI/CD systems or less powerful machines.
fix
Allocate sufficient time and disk space. Consider using a dedicated build directory outside `node_modules` (e.g., via `OPENCV_BUILD_ROOT` environment variable) to prevent duplicate builds and allow sharing between projects or for persistence. For production, consider pre-built binaries if available.
affects: >=0.1.0
gotchaConfiguration of the OpenCV build process (e.g., specifying OpenCV version, enabling/disabling contrib modules, or passing custom CMake flags) is done through environment variables or a specific `opencv4nodejs` section in `package.json`. Incorrectly setting these variables or `package.json` properties can lead to unexpected build configurations or failures.
fix
Refer to the `opencv4nodejs` documentation for the most up-to-date and correct environment variable names and `package.json` structure (e.g., `autoBuildOpencvVersion`, `autoBuildWithoutContrib`, `autoBuildFlags`). Ensure that environment variables are correctly set for your shell/OS before running `npm install`.
affects: >=0.1.0
deprecatedThe `opencv-build` package (version 0.1.9) is significantly older. While it is still listed with dependents on npm, newer `opencv4nodejs` installations typically rely on more actively maintained forks or versions, such as `@u4/opencv-build`. Using this older version might lead to compatibility issues with recent Node.js versions or the latest OpenCV releases.
fix
For new projects or if encountering issues, consider using the more current `@u4/opencv4nodejs` which often bundles its own up-to-date build script or uses `@u4/opencv-build` internally. Migrate to modern `opencv4nodejs` versions and their recommended build mechanisms.
affects: <=0.1.9
Errors
Common errors & fixes
Error: Command failed: cmake --version
`cmake` is not installed or not available in the system's PATH.
fix
Install `cmake` globally. On Linux/macOS: `sudo apt-get install cmake` or `brew install cmake`. On Windows: download from `cmake.org` or use `npm install -g windows-build-tools` (which helps with Visual Studio) and ensure `cmake` is added to PATH.
fatal error C1083: Cannot open include file: 'opencv2/core.hpp'
During compilation on Windows, the Visual Studio Build Tools (MSVC compiler) are either not installed, not correctly configured, or the build environment lacks necessary paths to OpenCV headers.
fix
Run `npm install --global windows-build-tools` to install VS2015 build tools, or ensure a compatible Visual Studio version with C++ development workload is installed. Also, check that the installation directory for `opencv4nodejs` is not `C:\Program Files` or similar restricted path.
Error: `make` failed with exit code: 2
A generic compilation failure during the `make` or build step of OpenCV, often due to missing development headers, incorrect environment variables, or insufficient system resources.
fix
Review the full error log for more specific details. Ensure all required development packages (e.g., `build-essential`, `pkg-config`, image/video libraries on Linux) are installed. Check for sufficient RAM and disk space. Verify `package.json` configuration or environment variables for `opencv-build` are correct.
EACCES: permission denied, mkdir '.../node_modules/opencv-build/build'
The `npm install` process, or specifically the `opencv-build` script, lacks write permissions to create directories in the `node_modules` folder or a temporary build location.
fix
Run `npm install` with appropriate permissions (e.g., `sudo npm install` on Linux/macOS, or ensuring your user has write access to the project directory). Alternatively, configure an `OPENCV_BUILD_ROOT` environment variable to point to a user-writable directory outside `node_modules`.
Upgrade
Version history
0.1.9latest on npm
Audit
Dependencies
cmakerequiredRequired at runtime for configuring and generating the OpenCV build system.
windows-build-toolsoptionalOptional, but highly recommended for Windows environments to provide the necessary MSVC compiler toolchain.
Agent activity
2 hits · last 30 days
node
2
Resources
opencv-build — npm install opencv-build · libregistry