OpenCV.js issues - many functions not working with pre-build

Hi people!

I am new here and after fruitless searching extensively here and on the web, I hope to find help here now :slight_smile:

I just started working on my first PWA using OpenCV.js for image processing. I tried building a custom OpenCV.js file, but after no progress decided to go with the stock versions, e.g. from here.

While some functions work fine, others throw errors. Sometimes these are essential ones, like the cv.Scalar one.
Here’s a code snippet:


    cv.threshold(outImg1, threshold_img, 252, 255, cv.THRESH_BINARY);
    let m = cv.moments(threshold_img, true) // m = moments(threshold_img, true);

    let sunPos = new cv.Point(m.m10 / m.m00, m.m01 / m.m00);
    console.log(sunPos)

    const circleColor = cv.Scalar(0, 0, 130);
    cv.circle(imgWithSunDetected, sunPos, 5, circleColor, 10);
    

It works all fine up to the cv.Scalar line.
If that is included I get the following error:

this.push is not a function
TypeError: this.push is not a function
at Object.Scalar (http://localhost:3000/static/js/bundle.js:9206:14)
at detectSun

Am I doing something wrong? Other functions like cv.blur do not work either. I also get the same result whatever version I use (tried 4.8.0, 4.7.0, 3.4.16…). What works, seems to be very limited to me.

Any help apprechiated :slight_smile: :pray:

Moritz

PS: I am using wsl on windows and inside react.

Scalar is ordinarily an object, not a function,

to create one, use:

 const circleColor = new cv.Scalar(0, 0, 130);

that sounds desperately overcomplicated already
you’re trying to learn a new library. keep it as simple & stupid as possible

Hey berak,

thanks a lot for your quick answer! That solved the problem, also with the other functions!
Now I feel stupid, but happy that I can make progress!
Maybe you are right, that I should keep my projects stupid as well in the beginning :smiley:

don’t. debugging this IS painful, it’s still some experimental API,
added as an afterthought

Thanks for the understanding! I will come back when I have to build my opencv.js file again manually to include the stitching functions.