我试图从嘈杂的图像中检测出线条,结果得到的线条太多。我需要多次遍历行,这对于太多行来说太慢了,我只对足够长的行感兴趣。
我的检测行的代码如下:
// Edge detection
int lowThreshold = 35;
Canny(greyMat, dst, lowThreshold, lowThreshold * 3, 3);
cv::blur(dst, dst, cv::Size(2,2));
// Standard Hough Line Transform
std::vector<cv::Vec2f> lines; // will hold the results of the detection
HoughLines(dst, lines, 1, rho_resolution, 150, 0, 0 ); // runs the actual detection
我的原始图片是
从Canny得到的图像是
HoughLines将检测100条线,我只对中间形成矩形的长条感兴趣。如何删除短线?如果我增加Canny阈值,则不会检测到我需要的某些行。
最佳答案
对图像进行模糊处理以减少噪点或帧中的小细节,它对我有用。
kernel = np.ones((5, 5), np.float32) / 25
smoothed = cv2.filter2D(frame, -1, kernel)
gray=cv2.cvtColor(smoothed, cv2.COLOR_BGR2GRAY)
edge=cv2.Canny(gray, 100, 150)
lines = cv2.HoughLines(edge, 1, np.pi / 180, 200)
print(lines)
关于opencv - 删除由OpenCV HoughLines检测到的细线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47594016/