-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
minAreaRect fails with a particular contour (and probably others) #11915
Copy link
Copy link
Open
Labels
Description
System information (version)
- OpenCV => 3.4.1 (I found the same behavior with 3.3.0 though)
- Operating System / Platform => OSX / WIN10
- Compiler => apple clang / Visual c++ 2017
Detailed description
minAreaRect is supposed to provide a rotated bounding box of a set of points (contour), it works fine in probably most of the cases but I encountered one case in which the rotated rectangle is not enclosing the contour.
Steps to reproduce
cpp code:
std::vector<Point> hull;
hull.push_back(Point(7826,5663));
hull.push_back(Point(4190,5685));
hull.push_back(Point(882,5699));
hull.push_back(Point(879,5390));
hull.push_back(Point(871,2696));
hull.push_back(Point(865,558));
hull.push_back(Point(870,140));
hull.push_back(Point(7369,119));
hull.push_back(Point(7797,119));
hull.push_back(Point(7825,5314));
hull.push_back(Point(7826,5598));
RotatedRect rbb = minAreaRect(hull);
Point2f vertices[4];
rbb.points(vertices);
Mat image = Mat::zeros(6000, 8000, CV_8UC3);
std::vector<std::vector<Point> > contours(1);
contours[0] = hull;
drawContours(image, contours, 0, Scalar(0, 0, 255));
for (int i = 0; i < 4; ++i) {
line(image, vertices[i], vertices[(i+1)%4], Scalar(0, 255, 0));
}
imwrite("./view.png", image);
The resulting image (rotated rect is drawn in green and original contour in red):
Zoom on bottom left corner:
Zoom on bottom right corner:
Reactions are currently unavailable


