简体   繁体   English

如何使用 opencv-python 使用霍夫线变换去除噪声

[英]How can I remove noise with Hough Line Transform with opencv-python

The purpose of this program is to map out the corners and edges of a room, here is where I'm at right now:该程序的目的是将 map 移出房间的角落和边缘,这就是我现在所处的位置:image_current The image on the top right is my result, and the image on the top left is my input.右上角的图像是我的结果,左上角的图像是我的输入。 Currently, I am using canny edge detection with a gaussian filter.目前,我正在使用带有高斯滤波器的精明边缘检测。 But as you can see, there are a lot of random lines coming from other details in the image.但正如你所看到的,图像中有很多来自其他细节的随机线条。

My goal is this:我的目标是这样的:图像结果

So far, I've tried, Only showing lines that are flat (0 or infinite slope):到目前为止,我已经尝试过,只显示平坦的线(0 或无限斜率):

if lines is not None:
    for line in lines:
        x1, y1, x2, y2 = line[0]
        if math.isclose(x1, x2, tol_abs=25) or math.isclose(y1, y2, tol_abs=10):
            cv2.line(bgrimg, (x1, y1), (x2, y2), (0, 255, 0), 1)

But this resulted in me losing some of the important lines.但这导致我失去了一些重要的台词。 Next, I tried to only show lines on the edges of the image:接下来,我尝试只在图像边缘显示线条:

if lines is not None:
    for line in lines:
        x1, y1, x2, y2 = line[0]
        if y1 > 100 and y2 > 100:
            cv2.line(bgrimg, (x1, y1), (x2, y2), (0, 255, 0), 1)

This somewhat works for the top, but since the sides could be anywhere in the picture, I can't determine exactly where they will be.这有点适用于顶部,但由于侧面可能在图片中的任何位置,我无法确定它们的确切位置。

Is there a way to solve this?有没有办法解决这个问题? If not, would it be possible with machine learning?如果没有,机器学习是否有可能?

Starting from the information obtained by Canny.从Canny得到的信息开始。 Could:可以:

1 - Determine a good reference for the horizontal line, 1 - 确定水平线的良好参考,

2 - Determine a good reference for the right diagonal line 2 - 确定右对角线的良好参考

3 - Determine a good reference for the left diagonal line 3 - 确定左对角线的良好参考

4 - From the extension of these reference lines you can find the intersections. 4 - 从这些参考线的延伸中,您可以找到交叉点。

Some intersections will be good, others bad.有些路口会很好,有些则不好。

It is a good intersection if the angle formed by the horizontal reference line and the oblique reference line are the same or similar both to the right and to the left.如果水平基准线和斜基准线形成的角度左右相同或相似,则为良好的交点。

As in the image I added here: https://i.stack.imgur.com/OYS2c.png正如我在这里添加的图片: https://i.stack.imgur.com/OYS2c.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM