I want to use opencv in node. Found @techstark/opencv-js and looks promising, but I cannot run even a simple example. I've installed the examples from https://github.com/TechStark/opencv-js-examples. I'm using Node v22.18.0
My simple program:
const { getOpenCv } = require("./opencv.js");
async function main() {
const { cv } = await getOpenCv();
console.log("OpenCV.js is ready!");
console.log(cv.getBuildInformation());
const inputImage = cv.imread("Lenna.png");
console.log("Done");
}
main();
Run with:
> npm run commonjs
Throws this error:
(build info, as expected) (a very long block of obfuscated code)
abort(ReferenceError: document is not defined). Build with -s ASSERTIONS=1 for more info. (Use node --trace-uncaught ... to show where the exception was thrown)
Node.js v22.18.0
I tried an earlier version with similar outcome. I don't know where the problem is: in techstark's package, the opencv js port (the author says it's downloaded directly from its source), an incompatibility with node.js, my own setup, or what.
@techstarkprovides the package. please direct your support request to@techstark.