gpt4 book ai didi

c++ - 检测嘈杂图像中的细线切割

转载 作者:搜寻专家 更新时间:2023-10-31 01:05:32 25 4
gpt4 key购买 nike

我有一张嘈杂的图像,我必须在其中检测特定大小的圆圈。在少数图像上,可能会有非常精细的线切割。目前我使用的算法基本上是如果在基于轮廓的圆检测中没有检测到外部(黑色)和内部中心(白色)圆,我声明有一个线切割。但这种方法并不总是奏效。细线的检测也很困难(背景表面上的线默认情况下不应该被检测到)。 enter image description here

圆检测和线切割的伪代码

1. convert image to grey scale
2. find hough circles
3. from the circles found, store the ones with expected radii.
4. apply canny to the grey scale image and dilate.
5. find contours on the canny image.
6. check if contour is circle :

if(contour.size() > lineThresh) {
cv::RotatedRect rect = cv::fitEllipse(contour);
float width = rect.size.width * 0.5;
float height = rect.size.height * 0.5;

float shortAxis = 0.0;
float longAxis = 0.0;

if (width < height) {
shortAxis = width;
longAxis = height;
} else {
shortAxis = height;
longAxis = width;
}

if (longAxis == 0.0) {
longAxis = 1.0;
}

float circleMeasure = ((longAxis - shortAxis) / longAxis);
float radius = (longAxis + shortAxis) / 2;

float perimeter = cv::arcLength(contour, false);
float area = abs(cv::contourArea(contour));

if (area <= 0) {
area = 1;
}
float area_diff = std::abs(area - ((radius * perimeter) / 2));
float area_delta = area_diff / area;

if(circleMeasure < this->circleError &&
area_delta < this->areaDelta) {
return true;
}else
return false;

7. if both (exterior and interior central) circles are found, circles are good
else if, found in hough and not in contours, there's a line cut.

这是我放大后得到的图像。有什么好的检测线的方法吗? enter image description here

最佳答案

好吧,大家终于找到了解决方案!

- Use tophat morphology on the gray image. This enhances the line cuts along with noise
- Use line filter and rotate it by 10 degrees.
e.g. Mat kernel = (cv::Mat_<float>(3, 3) << -1, 4, -1,
-1, 4, -1,
-1, 4, -1;
(Now only the straight contours remain)
- Check the aspect ratio of the contours and store if it exceeds a threshold.
- Check for collinearity of the contours. If the length of collinear segment is more than a threshold, declare it as a line cut.

这个算法很适合我

关于c++ - 检测嘈杂图像中的细线切割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22448738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com