Ask Your Question

How to pass points to minAreaRect using Java Bindings

asked 2013-03-30 22:33:15 -0600

birdy gravatar image

updated 2013-03-30 22:51:38 -0600

I'm looking for a way to use minAreaRect with certain points I've collected. I'm converting this C++ code to Java using the OpenCV Java Bindings


std::vector<cv::Point> box_points;
box_points.push_back(cv::Point(left, top));
box_points.push_back(cv::Point(left, bottom));
box_points.push_back(cv::Point(right, bottom));
box_points.push_back(cv::Point(right, top));

// Compute minimal bounding box for the ROI
// Note: for some unknown reason, width/height of the box are switched.
cv::RotatedRect box = cv::minAreaRect(cv::Mat(box_points));


List <Point> boxPoints = new ArrayList<Point>();
boxPoints.add(new Point(left, top));
boxPoints.add(new Point(left, bottom));
boxPoints.add(new Point(right, bottom));
boxPoints.add(new Point(right, top));

RotatedRect box = Imgproc.minAreaRect(new Mat(boxPoints));

However, the last line of my java code is giving me an error.

What is the best way to pass boxPoints to minAreaRect ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-04-10 07:54:24 -0600

Andrey Pavlenko gravatar image

Sample code:

 MatOfPoint2f points = new MatOfPoint2f(new Point(1, 1), new Point(5, 1), new Point(4, 3), new Point(6, 2));
 RotatedRect rrect = Imgproc.minAreaRect(points);
edit flag offensive delete link more

Question Tools


Asked: 2013-03-30 22:33:15 -0600

Seen: 3,224 times

Last updated: Apr 10 '13