Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect corner point from rectangle with rounded corners

Tags:

opencv

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?

enter image description here

Thank's for any help.

like image 677
Ricardo Avatar asked Jan 11 '13 00:01

Ricardo


1 Answers

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.

like image 117
mmgp Avatar answered Sep 28 '22 01:09

mmgp