CodePudding user response:
Fyi://////////////////////////////////////////////////////////////////////////
//contour is a circle, judged by the area of the contour PI * r * r difference, distinguish the circle,
//contour: input profile
//minRadius: radius length at least more than minRadius
//////////////////////////////////////////////////////////////////////////
BOOL isCircleContour (vector& Contour, double minRadius)
{
BOOL isCircle=FALSE;
//double generating=arcLength (contour, TRUE);
Double generating=arcLength (contour, FALSE);
Double perimeter2=arcLength (contour, TRUE);
The Rect the Rect=boundingRect (contour);
Double r=(. The rect. The rect width + height)/4.0;//external torque radius approximately equal to the contour length/2
Double area=contourArea (contour);
Double PI=3.1415926;
//cout<& lt;" X/y/width/height \ t "& lt;//cout<& lt;" Generating: FALSE \ t "& lt; //cout<& lt;" Perimeter2: TRUE \ t "& lt; //cout<& lt;" Area: \ t "& lt; //cout<& lt;" R: "& lt;
Double perimeterDiffRatio=fabs (2 * PI * r - generating) * 2.0/(2 * PI * r + generating) * 100;
Double areaDiffRatio=fabs (PI * r * r - area) * 2.0/(PI * r * r + area) * 100;
Double sideDiffRatio=abs (the rect. Width - the rect. Height) * 2.0/(. The rect. The rect width + height) * 100;
//cstrings CstrInfo3;
//CstrInfo3. The Format (_T (" \ n areaDiffRatio perimeterDiffRatio: % f, % f \ n sideDiffRatio: % f "), perimeterDiffRatio, areaDiffRatio, sideDiffRatio);
//AfxMessageBox (CstrInfo3);
If (r> MinRadius)
{
Cout<& lt;" Perimeter percentage difference: "& lt;Cout<& lt;" Area percentage difference: "& lt; Cout<& lt;" Side length percentage difference: "& lt; Cout }
//the original
//const double areaDiffThresh=18.0;//the current statistics, the largest area of poor 2.58%
//const double perimeterDiffThresh=15;//the current statistics, the largest circumference difference 5.65%
//const double sideDiffThresh=15;//the current statistics, the largest length difference 7.3%
//const double avgDiffThresh=15.0;//three difference ratio of weighted average of the request is less than 5.0;
Const double areaDiffThresh=5;//the current statistics, the largest area of poor 2.58%
Const double perimeterDiffThresh=7.25;//the current statistics, the largest circumference difference 5.65%
Const double sideDiffThresh=10;//the current statistics, the largest length difference 7.3%
Const double avgDiffThresh=5.0;//three difference ratio of weighted average of the request is less than 5.0;
Double avdDiffRatio=(areaDiffRatio + + sideDiffRatio perimeterDiffRatio)/3.0;
//calculate the radius of the outline of the perimeter is multiples of 2 * PI
If ((areaDiffRatio & lt; AreaDiffThresh)
& & (perimeterDiffRatio & lt; PerimeterDiffThresh)
& & (sideDiffRatio & lt; SideDiffThresh)
& & (avdDiffRatio& & (r> MinRadius))
{
IsCircle=TRUE;
}
Return isCircle;
}
CodePudding user response:
Miss zhao, I this two circles can be detected? If in the process of filming is not vertical, will get round a little oval effect how to eliminate the influence thank you teacherCodePudding user response:
Relaxation limit scope of baiCodePudding user response:
Hough transform. There are code! Don't have to use opencvCodePudding user response:
The Matlab solution is more convenient, binarization, and then use regionprops the function, find out the local area, center and other properties