|
|
@ -218,6 +218,11 @@ int main( int argc, char** argv ) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline static bool isGoodBox(const RotatedRect& box) { |
|
|
|
|
|
|
|
//size.height >= size.width awalys,only if the pts are on a line or at the same point,size.width=0
|
|
|
|
|
|
|
|
return (box.size.height <= box.size.width * 30) && (box.size.width > 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Define trackbar callback function. This function finds contours,
|
|
|
|
// Define trackbar callback function. This function finds contours,
|
|
|
|
// draws them, and approximates by ellipses.
|
|
|
|
// draws them, and approximates by ellipses.
|
|
|
|
void processImage(int /*h*/, void*) |
|
|
|
void processImage(int /*h*/, void*) |
|
|
@ -276,39 +281,30 @@ void processImage(int /*h*/, void*) |
|
|
|
{ |
|
|
|
{ |
|
|
|
vector<Point2f> pts = points[i]; |
|
|
|
vector<Point2f> pts = points[i]; |
|
|
|
|
|
|
|
|
|
|
|
if (pts.size()<=5) { |
|
|
|
//At least 5 points can fit an ellipse
|
|
|
|
|
|
|
|
if (pts.size()<5) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (fitEllipseQ) { |
|
|
|
if (fitEllipseQ) { |
|
|
|
box = fitEllipse(pts); |
|
|
|
box = fitEllipse(pts); |
|
|
|
if( MAX(box.size.width, box.size.height) > MIN(box.size.width, box.size.height)*30 || |
|
|
|
if (isGoodBox(box)) { |
|
|
|
MAX(box.size.width, box.size.height) <= 0 || |
|
|
|
paper.drawEllipseWithBox(box, fitEllipseColor, 3); |
|
|
|
MIN(box.size.width, box.size.height) <= 0){continue;}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (fitEllipseAMSQ) { |
|
|
|
if (fitEllipseAMSQ) { |
|
|
|
boxAMS = fitEllipseAMS(pts); |
|
|
|
boxAMS = fitEllipseAMS(pts); |
|
|
|
if( MAX(boxAMS.size.width, boxAMS.size.height) > MIN(boxAMS.size.width, boxAMS.size.height)*30 || |
|
|
|
if (isGoodBox(boxAMS)) { |
|
|
|
MAX(box.size.width, box.size.height) <= 0 || |
|
|
|
paper.drawEllipseWithBox(boxAMS, fitEllipseAMSColor, 2); |
|
|
|
MIN(box.size.width, box.size.height) <= 0){continue;}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (fitEllipseDirectQ) { |
|
|
|
if (fitEllipseDirectQ) { |
|
|
|
boxDirect = fitEllipseDirect(pts); |
|
|
|
boxDirect = fitEllipseDirect(pts); |
|
|
|
if( MAX(boxDirect.size.width, boxDirect.size.height) > MIN(boxDirect.size.width, boxDirect.size.height)*30 || |
|
|
|
if (isGoodBox(boxDirect)){ |
|
|
|
MAX(box.size.width, box.size.height) <= 0 || |
|
|
|
paper.drawEllipseWithBox(boxDirect, fitEllipseDirectColor, 1); |
|
|
|
MIN(box.size.width, box.size.height) <= 0 ){continue;}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fitEllipseQ) { |
|
|
|
|
|
|
|
paper.drawEllipseWithBox(box, fitEllipseColor, 3); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (fitEllipseAMSQ) { |
|
|
|
|
|
|
|
paper.drawEllipseWithBox(boxAMS, fitEllipseAMSColor, 2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (fitEllipseDirectQ) { |
|
|
|
|
|
|
|
paper.drawEllipseWithBox(boxDirect, fitEllipseDirectColor, 1); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
paper.drawPoints(pts, cv::Scalar(255,255,255)); |
|
|
|
paper.drawPoints(pts, fitEllipseTrueColor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
imshow("result", paper.img); |
|
|
|
imshow("result", paper.img); |
|
|
|