Opencv How to detect 4 corners of a rectangle after applied cv::findContours and cv::drawContour

2.9k views Asked by At

My problems is I want to find 4 corners of rectangles after using cvfindcontours ? Here is my result:

image:
enter image description here

How can I find 4 corners of each rectangle? I think the building function Cv find and draw contours have their information of the corners, so how can I read it?

1

There are 1 answers

1
Rosa Gronchi On

(modified from here)

// Find the rotated rectangles for each contour
vector<cv::RotatedRect> cv::minRect( contours.size() );

for( size_t = 0; i < contours.size(); i++ )
{
    minRect[i] = minAreaRect( cv::Mat(contours[i]) );
}

If you want the actual points on the contour, you can later find for each contour the points that is closest to each of the corners of the RotatedRect