I’m trying to get min area rectangle from list of Points, but the rectangle I’m getting is not what I’m expecting. I’m using JavaCV 0.11.
Here is my java code:
ArrayList < Point > points = new ArrayList <> ();
points.add(...)
CvMat cvMat = CvMat.create(imageWithPoints.width() * imageWithPoints.height() * 2, 1, CV_32FC2);
for (Point point: points) {
int index = point.x() * imageWithPoints.width() + imageWithPoints.y();
int offset = index * 2;
cvMat.put(offset, point.x());
cvMat.put(offset + 1, point.y());
}
CvBox2D minAreaRectanle = cvMinAreaRect2(cvMat);
CvPoint2D32f rectanglePoints= new CvPoint2D32f(4);
cvBoxPoints(minAreaRectanle, rectanglePoints);
drawing lines between rectanglePoints...
In images below white dots are points in List and min area rectangle is yellow.

minAreaRectanle (center,size,angle)= ((199.9758, 297.95895), (387.48523, 604.0982), -1.1903903)

minAreaRectanle (center,size,angle) = ((113.72618, 322.62048), (554.406, 400.87958), -73.54802)
For some reason top left corner of the rectangle is in the point 0,0 but in the list(points) is no Point 0,0 (all points are drawn in the images, I checked many times ). I think there is something wrong with my algorithm for creating cvMat... Can anyone give me suggestion to what am I doing wrong?
↧