简体   繁体   English

OpenCV Hough行不显示

[英]OpenCV Hough Lines Not Showing

I am trying to get the lines from the following image: original 我正在尝试从下图获得线条: 原始

My code uses the following function: 我的代码使用以下功能:

import cv2
lines = cv2.HoughLinesP(image, .1, np.pi/360, 10,
                        minLineLength, maxLineGap)

Where minLineLength = 20, and maxLineGap = 10. I am obtaining the following: after hough lines 其中minLineLength = 20,和maxLineGap = 10。我获得以下: 后霍夫线

Why are the horizontal lines not showing up in this case, despite being clearly visible to the naked eye? 尽管用肉眼可以清楚地看到水平线,为什么在这种情况下不显示水平线?

The problem is the resolution that you use for rho. 问题是您用于rho的分辨率。

A resolution of 0.1 is extremely small. 0.1的分辨率非常小。 Indeed for an image of size (N, N) pixels, the number of possible values for rho is N * N * sqrt(2) / rho_resolution (sometimes the double of this depending of how the angle is defined). 实际上,对于大小为(N, N)像素的图像,rho的可能值的数量为N * N * sqrt(2) / rho_resolution (有时是角度的定义方式的两倍)。

The number of possible values is materialized as bins in the Hough accumulator. 可能值的数量在霍夫累加器中具体化为箱。 The larger this number, the less the different pixels of the image will accumulate is the same bins. 该数字越大,相同的像素元将在图像中累积的不同像素越少。 With a very small value for the resolution of rho, you will end up with a sparse accumulator, with a few low values here and there. 如果Rho的分辨率值很小,那么最终将得到一个稀疏的累加器,在此各处都有一些较低的值。

Bring this value up to 1 or 2 pixels of resolution and you should see more significant lines appear. 将此值提高到1或2像素的分辨率,您应该会看到更明显的线条出现。

If HoughLinesP() is not detecting some line, even though it is clearly visible, it is because that line surely does not meet some of your criteria. 如果HoughLinesP()即使清晰可见也检测到某些线,那是因为该线肯定不满足您的某些条件。 Most probably your minLineLength or maxLineGap . 最有可能是您的minLineLengthmaxLineGap If you reduce those criteria you will start detecting more lines. 如果减少这些条件,则将开始检测更多行。

Also, as some comments indicate, your rho parameter may be too small (0.1). 另外,正如一些评论所指出的那样,您的rho参数可能太小(0.1)。 As that parameter is measured in pixels , giving it a non-integer value may produce unexpected results, try giving it a value of 1. 由于该参数以像素单位 ,将其赋予非整数值可能会产生意外的结果,请尝试将其赋予1的值。

If you want you can take a look at this example from the docs where they explain and show how to use both HoughLines() and HoughLinesP() . 如果您愿意,可以从文档HoughLines()一下这个示例 ,他们在其中解释并显示如何同时使用HoughLines()HoughLinesP()

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

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