OpenCV JavaScript version for node.js or browser
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/5.0.0/opencv.js
TypeScript is supported (thanks to mirada).
import cvModule from "@techstark/opencv-js";
async function getOpenCv() {
let cv;
if (cvModule instanceof Promise) {
cv = await cvModule;
} else {
if (cvModule.Mat) {
cv = cvModule;
} else {
await new Promise((resolve) => {
cvModule.onRuntimeInitialized = () => resolve();
});
cv = cvModule;
}
}
return { cv };
}
async function main() {
const { cv } = await getOpenCv();
console.log("OpenCV.js is ready!");
// You can now use OpenCV functions here
console.log(cv.getBuildInformation());
}
main();Get the test image from here Lenna.png
npm install @techstark/opencv-jsyarn add @techstark/opencv-jsimport cv from "@techstark/opencv-js""esModuleInterop": true in tsconfig.jsonimport * 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.
No open issues yet, or sync has not completed.