如何计算 OpenCV 中的行数(Hough Transform)
我成功地将图像中的发丝检测为线条。我看到输出图像将每根头发检测为线条。我使用 cvHoughLines2()
,方法参数为 CV_HOUGH_PROBABILISTIC
。
现在我想数一下这些行。输出图像在每根头发上显示 1 或 2 条线。我看到每条线都是由小线段组成的。因此很难直接得到他们的总数。 对此有何建议?
谢谢, 普拉迪普
I am successfully able to detect hair strands in an image as lines. I see that the output image detects each hair as line. I use cvHoughLines2()
with method parameter as CV_HOUGH_PROBABILISTIC
.
Now I want to count these lines. The output image shows 1 or 2 line over each hair. I see that each line is composed of small line segments. And so it is difficult to directly get their total number.
Any suggestions on this?
Thanks,
Pradeep
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,使用 Canny 边缘检测器可能会更好。从您的描述来看,它似乎比霍夫变换有一些关键优势:
给定正确的参数,它也许能够用一条连续的线唯一地检测每根头发。
这是在 OpenCV 中的
cvCanny()
函数中实现的。使用threshold1
和threshold2
参数(第三个和第四个参数)的值来试验检测和跟踪。至于实际计算线数,我不确定如何最好地解决这个问题(Canny 输出与 Hough 变换输出的形式有些不同),但您可能会发现使用独特的实心边缘比使用碎片线集更容易参数。
You may actually be better off using the Canny edge detector. From your description, it seems to have a few key advantages over the Hough transform:
Given the right parameters, it may be able to uniquely detect each hair with a single, continuous line.
This is implemented in OpenCV in the
cvCanny()
function. Play around with the value of thethreshold1
andthreshold2
parameters (3rd and 4th arguments) to experiment with detection and tracing.As for actually counting the lines, I'm not sure how best to approach this (Canny output is a somewhat different form from Hough transform output), but you might find it easier to work with unique, solid edges than with fragmented sets of line parameters.
霍夫函数应返回 OpenCV2 中的向量或 OpenCV1 中的 CvSeq。您可以轻松获取它们的长度并迭代它们。有关更多详细信息,请参阅 OpenCV 文档中的示例代码。
The hough function should return a vector in OpenCV2 or a CvSeq in OpenCV1. You can easily get their length and iterate through them. See the sample code in the OpenCV documentation for more details.