OpenCV JavaScript version (NPM package) for node.js or browser. Get started guide OpenCV.js Tutorials.
The file opencv.js was downloaded from https://docs.opencv.org/4.11.0/opencv.js
TypeScript is supported (thanks to mirada).
import cvReadyPromise from "@techstark/opencv-js";
async function main() {
const cv = await cvReadyPromise;
console.log("OpenCV.js is ready!");
// You can now use OpenCV functions here
console.log(cv.getBuildInformation());
}import cv from "@techstark/opencv-js";
cv.onRuntimeInitialized = () => {
console.log("OpenCV.js is ready!");
// You can now use OpenCV functions here
console.log(cv.getBuildInformation());
};- See code examples (React, Angular, Node.js) in opencv-js-examples
- See live demo and code here

- Get the test image from here Lenna.png
- See code here
npm install @techstark/opencv-js- or
yarn add @techstark/opencv-js import cv from "@techstark/opencv-js"- for TypeScript, set
"esModuleInterop": trueintsconfig.json
- for TypeScript, set
- or
import * as cv from "@techstark/opencv-js"
If you use this package for browsers, you need to set some polyfills. In the file "webpack.config.js", set
module.exports = {
resolve: {
modules: [...],
fallback: {
fs: false,
path: false,
crypto: false
}
}
};The TypeScript type declarations may not be up to date with the latest OpenCV.js. Refer to cvKeys.json to check the available methods and properties at runtime.
