How do I use the "detectMarkers" function in the "aruco" module of "opencv.js"?

69 Views Asked by At

I set up my aruco detector as follows:

let detectionParams = new cv.aruco_DetectorParameters();
let refineParams = new cv.aruco_RefineParameters(10,3,true);
let dictionary = cv.getPredefinedDictionary(cv.DICT_ARUCO_ORIGINAL);
let detector = new cv.aruco_ArucoDetector(dictionary,detectionParams,refineParams)

The parameters of refineParams are the defaults ones I found on the opencv website. When I log the dictionary and the detector they are both there. The decector has the detectMarkers function.

Then I try to run the detectMarkers function as follows:

let src_image= cv.imread("canvas");
let corners_matvec = new cv.MatVector()
let id_mat = new cv.Mat()
detector.detectMarkers(src_image,corners_matvec,id_mat);

This gives me an "Uncaught" error with "___cxa_throw" at the top of the stack.

Since it is my first time using this library I think that I am maybe missing something basic. Is there anybody who has worked with this technology before that could help me by pointing out where I am going wrong?

I am using version 4.9.0 of opencv.js.

Currently my hunch is that I am doing something wrong with the "output variables".

When looking at the aruco detection tutorial for c++ on the opencv docs website I saw that these "output variables" are only declared and not assigned anything. When not initializing the variables I get a type error and when I try assigning null to them I get a binding error. Since I had previously stumbled upon the following error "Expected null or instance of MatVector.." I thought assigning null would be the solution here, but it was not since I then get this error: "null is not a valid MatVector".

I have also tried using the 3.4.20 version of opencv.js

1

There are 1 best solutions below

0
Steffen On

I stumbled upon the same problem. I tried lots of different things, but in the end, it seems 'detectMarkers' is simply broken in version 4.9.0 of opencv.js.

I 'updated' to the latest by downloading opencv.js from https://docs.opencv.org/**4.x**/opencv.js. That is on 2024/03/26, I don't know how reproducbile that is.

Now, running 'detectMarkers' and accessing the detected marker IDs and their coordinates does work. I still get a similar error for 'drawDetectedMarkers', which would be very conveniant to have running. Still, the core functionality is available that way.