opencv c++ 中椭圆检测的歧义
Ambiguity in Ellipse Detection in opencv c++
嘿,我在做过去两周的道路标志检测项目,我遇到了从 image.Can 检测椭圆的主要问题 谁能告诉我如何处理这个问题!!!你可以查看结果 code.Thanks
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(GreyImage, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
for (size_t i = 0; i < contours.size(); i++)
{
Mat pointsf;
Mat(contours[i]).convertTo(pointsf, CV_32F);
RotatedRect box = fitEllipse(pointsf);
ellipse(OrignalImg, box, Scalar(0, 0, 255), 1, 8);
}
The function calculates the ellipse that fits (in a least-squares sense) a set of 2D points best of all.
只要你传递一个轮廓,它就会适合一个椭圆。这是什么意思?考虑点列表。如果我传递代表矩形(角)的点,则可能的输出将是绘制的椭圆。
上面的矩形实际上会找到一个具有 'no error' 的椭圆,因为它适合使用矩形的角。在其他情况下,它会尝试找到适合减少误差的椭圆(例如在带有多边形的图像中)。没关系,只要你给它传递接近图像中椭圆的轮廓。
轮廓(由 findContours 返回)定义为分隔区域的线。这些区域可以是正方形、三角形或几乎任何形状。您将这些轮廓传递给 fitEllipse 函数;也就是说,您 制作了 一个通过这些轮廓的椭圆,无论这些轮廓实际上是否表示椭圆。
正如@Micka 所说,在尝试制作(拟合)椭圆之前,您需要检查给定的轮廓是否实际上是椭圆。可以在 Whosebug 中找到使用各种方法的示例,例如 HoughCircles、MatchShape、HuTransforms 和 RANSAC:
- Detection of coins (and fit ellipses) on an image
- Ellipse detection with OpenCV
- Detect semi-circle in opencv
嘿,我在做过去两周的道路标志检测项目,我遇到了从 image.Can 检测椭圆的主要问题 谁能告诉我如何处理这个问题!!!你可以查看结果 code.Thanks
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(GreyImage, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
for (size_t i = 0; i < contours.size(); i++)
{
Mat pointsf;
Mat(contours[i]).convertTo(pointsf, CV_32F);
RotatedRect box = fitEllipse(pointsf);
ellipse(OrignalImg, box, Scalar(0, 0, 255), 1, 8);
}
The function calculates the ellipse that fits (in a least-squares sense) a set of 2D points best of all.
只要你传递一个轮廓,它就会适合一个椭圆。这是什么意思?考虑点列表。如果我传递代表矩形(角)的点,则可能的输出将是绘制的椭圆。
上面的矩形实际上会找到一个具有 'no error' 的椭圆,因为它适合使用矩形的角。在其他情况下,它会尝试找到适合减少误差的椭圆(例如在带有多边形的图像中)。没关系,只要你给它传递接近图像中椭圆的轮廓。
轮廓(由 findContours 返回)定义为分隔区域的线。这些区域可以是正方形、三角形或几乎任何形状。您将这些轮廓传递给 fitEllipse 函数;也就是说,您 制作了 一个通过这些轮廓的椭圆,无论这些轮廓实际上是否表示椭圆。
正如@Micka 所说,在尝试制作(拟合)椭圆之前,您需要检查给定的轮廓是否实际上是椭圆。可以在 Whosebug 中找到使用各种方法的示例,例如 HoughCircles、MatchShape、HuTransforms 和 RANSAC:
- Detection of coins (and fit ellipses) on an image
- Ellipse detection with OpenCV
- Detect semi-circle in opencv