Ask Your Question

Revision history [back]

Opencv.js in web worker not loading

Hello, I'm using opencv 4.4 and compiling it to javascript using following command docker

run --rm --workdir /code -v "$PWD":/code "trzeci/emscripten:latest" python ./platforms/js/ build

taken from, everythin compiles just fine, it produces opencv.js file. I'm able to load this file via <script> tag and use it.

let opencvScript = document.createElement("script");                             
opencvScript.setAttribute("src", "js/lib/opencv.js");                            
opencvScript.onload = function () {                                              
    cv["onRuntimeInitialized"] = () => {                                             
        console.log("#opencv loaded !");  // Works                                           

But I want to use opencv in java script web workers. I use following code to import opencv.js in web worker (worker.js file)

cv["onRuntimeInitialized"] = () => {                                             
    console.log("#opencv loaded !");// Doesn't work, it is never executed

and create worker like this:

w = new Worker("worker.js")

The problem is nothing happens. No error is thrown, script finishes execution but library is not loaded. I found already complied opencv.js here: Which is used in demo here:

And this file is loaded in my worker.js but unfortunately it doesn't have CascadeClassifier which I want to use in js web worker. Anyone struggled which such problem and know if it's possible to load opencv.js in web worker ?