Detecting a corner point from a rounded rectangle

I need to solve the problem when I detect rounded rectangles using opencv. I mainly use the same squares.c code example:

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 determine the image, but I need to adjust the perspective of the image, and for this I need to determine the angles of the image, how to do it, and the image has rounded corners? The problem arises due to the fact that a point that I did not find between the points, as an example, I created the following image, where the black lines represent the points detected by the existing code, and the blue points are the ones I need?

enter image description here

Thanks for any help.

+7
source share
3 answers

In terms of OpenCV, first find the black rectangle using FindContours with RETR_EXTERNAL and CHAIN_APPROX_SIMPLE . You will now find the minimum bounding box of this round rectangle using minAreaRect at the points found in FindContours . To get the corners of this bounding box, use the BoxPoints function to return (in the center, (width, height), rotation angle) minAreaRect . Now you have the four corners of the red line that you are after.

+2
source

Try scaling the image to a smaller size with the cvResize command and apply this code to it. Theoretically, reducing the size of the image should sharpen the corners of the image and reduce your problem by losing accuracy.

0
source

I had a problem and none of the other answers helped. In my case, I had to consider the correct datatrix, which has a missing corner in the upper right corner that looks rounded when the harris is detected.

To fix this, define the shape in any way, and then get the convex hull of the outline. Once you have this, you will need to extract four long lines (there is no opencv function, you have to make your own extraction function) Then you just get the intersection of 4 lines (your own function) and convert them back to matrix for perspective correction.

If your media may be bent or your detection may have flaws, you can also remove points from the path that have large angles relative to neighboring points, which can create deviations at the end points.

0
source