opencv - 删除由OpenCV HoughLines检测到的细线

标签 opencv hough-transform canny-operator

我试图从嘈杂的图像中检测出线条,结果得到的线条太多。我需要多次遍历行,这对于太多行来说太慢了,我只对足够长的行感兴趣。

我的检测行的代码如下:

// 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

我的原始图片是source image

从Canny得到的图像是result image from 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/

相关文章:

LAB和灰度之间的Python OpenCV色彩空间差异

python - PyQt/PySide : How do I convert QImage into OpenCV's MAT format

opencv - 了解霍夫变换

python - 霍夫线变换以在图像中查找多边形

python - OpenCV 中的 Canny 可以同时处理灰度和彩色图像吗?

objective-c - iOS 中的 CVSurf (OpenCV) 功能

python - 圆形霍夫变换遗漏圆圈

Opencv-cvHoughLines2

android - 精明边缘检测器后的opencv洪水填充

c++ - Qt Creator,Mac OS X : Error: "Symbol(s) not found" when calling function from included header