I need to solve a problem when I am detecting rectangles with rounded corners using opencv. Basically I'm using the same code sample squares.c:
cvFindContours( gray, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE );
while( contours )
{
double area=fabs(cvContourArea(contours, CV_WHOLE_SEQ));
if(area < minimum_area || area > maximum_area) {
contours = contours->h_next;
continue;
}
result = cvApproxPoly( contours, sizeof(CvContour), storage,
CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.05, 0 );
if( result->total == 4 &&
fabs(cvContourArea(result,CV_WHOLE_SEQ)) > 1000 &&
cvCheckContourConvexity(result) )
{
With this code I can usually detect the image, but I need to adjust the image's perspective and for that I need to detect the corners of the image, how to do this and the image has rounded corners? The problem happens because the point I need not detected between points, as an example, I created the following image, where the black lines represent the points detected by the existing code and the blue dots are the ones I need?
Thank's for any help.
In OpenCV terms, first find the black rectangle by using FindContours
with RETR_EXTERNAL
and CHAIN_APPROX_SIMPLE
. Now you find the minimal bounding box of this round rectangle by using minAreaRect
on the points found by FindContours
. To get the corners of this bounding box, use the function BoxPoints
on the return (center, (width, height), rotation angle) of minAreaRect
. Now you have the four corners of the red line you are after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With