I am using OpenCV to detect Aruco markers in a frame captured by a webcam. The problem arose from the following piece of code:
public class Detector {
private final ArucoDetector detector;
public Detector() {
DetectorParameters param = new DetectorParameters();
Dictionary dict = new Dictionary();
detector = new ArucoDetector(dict, param);
}
public void detect(Mat mat) throws CvException {
ArrayList<Mat> corners = new ArrayList<>();
Mat ids = new Mat();
detector.detectMarkers(mat, corners, ids); // Causes exception
System.out.println(ids.size());
}
}
The parameter mat
is the frame supplied by the calling method, which appears correctly when displayed with AWT and Swing. Also, ids.size()
is printed correctly, and no exception is thrown when the webcam is recording a dark or black scene, which is quite peculiar. The full stack trace and the error message follows:
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.9.0) /home/runner/work/opencv/opencv/opencv-4.9.0/modules/objdetect/src/aruco/aruco_detector.cpp:399: error: (-215:Assertion failed) markerSize > 0 && bits.cols == sizeWithBorders && bits.rows == sizeWithBorders in function '_getBorderErrors']
at org.opencv.objdetect.ArucoDetector.detectMarkers_1(Native Method)
at org.opencv.objdetect.ArucoDetector.detectMarkers(ArucoDetector.java:132)
at org.dcs.aruco.Detector.detect(Detector.java:28)
at org.dcs.main.DetectArucoMarkers.action(Main.java:37)
at org.dcs.camera.Camera.cameraLoop(Camera.java:65)
at org.dcs.main.Main.main(Main.java:58)
I tried assigning Imgcodecs.imread("/some/path/to/image.png")
to mat
, but it did not solve the issue and threw the same exception.
Thank you in advance, and if more information is needed, I’ll edit the question appropriately.
Nascity is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.