cvMinAreaRect2 for a list of Points: (-5:Bad argument) Exception

72 views
Skip to first unread message

Oleksandr

unread,
Feb 7, 2021, 7:24:25 PM2/7/21
to javacv

Hello,

while been able to estimate the rectangle for an array (or a list) or points by using opencv-java as:
MatOfPoint2f mat = new MatOfPoint2f(pointList.toArray(new Point[] {}));
org.opencv.core.RotatedRect rrect = Imgproc.minAreaRect(mat);

I have problems to implement the same with javacv and getting
(-5:Bad argument) Unknown array type in function 'cvarrToMat'
E.g.

CvSeq seq = new CvSeq(cvPointsList.size());
for (int i = 0; i < cvPointsList.size(); i++) {
      seq.position(i).put(cvPointsList.get(i));
}
RotatedRect box = cvMinAreaRect2(seq).asRotatedRect(); <--- throws (-5:Bad argument) Unknown array type in function 'cvarrToMat'

Can you provide an example how to do that with javacv?

Many thanks in advance
Oleksandr



Samuel Audet

unread,
Feb 7, 2021, 8:11:04 PM2/7/21
to jav...@googlegroups.com, Oleksandr
The C API of OpenCV is deprecated. If you don't have any legacy code to maintain,
I would recommend using the C++ API, probably something this (although I didn't test it):
    RotatedRect rr = minAreaRect(new Mat(pointList))
Samuel

Oleksandr

unread,
Feb 8, 2021, 2:57:57 AM2/8/21
to javacv
Thank you Samuel.

My problem is the mix of javacv and opencv-java code. If I understood it correctly ImgProc.minAreaRect is the Java port of C++ OpenCV = opencv-java (from comments in the source code). And I was wondering if I can get rid of opencv-java minAreaRect (as its result is also a opencv-java object), by evoking cvMinAreaRect2 or something else with the same functionality which returns a min area for 2D points.

Oleksandr

Samuel Audet

unread,
Feb 8, 2021, 3:05:12 AM2/8/21
to jav...@googlegroups.com, Oleksandr
You can keep using the official Java API of OpenCV with JavaCV as well, there's no issues with that:

Oleksandr

unread,
Feb 8, 2021, 3:12:14 AM2/8/21
to javacv
Ok, thank you, Samuel.
Reply all
Reply to author
Forward
0 new messages