如何计算 OpenCV 中的行数(Hough Transform)

发布于 2024-08-17 08:02:29 字数 215 浏览 11 评论 0原文

我成功地将图像中的发丝检测为线条。我看到输出图像将每根头发检测为线条。我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情独悲 2024-08-24 08:02:29

实际上,使用 Canny 边缘检测器可能会更好。从您的描述来看,它似乎比霍夫变换有一些关键优势:

  • 响应任意形状的轮廓,而不仅仅是直线;
  • 执行降噪和非极大值抑制以最小化响应;并
  • 使用更宽松的阈值进行第二次检测,以“跟踪”或“固化”边缘。

给定正确的参数,它也许能够用一条连续的线唯一地检测每根头发。

这是在 OpenCV 中的 cvCanny() 函数中实现的。使用 threshold1threshold2 参数(第三个和第四个参数)的值来试验检测和跟踪。

至于实际计算线数,我不确定如何最好地解决这个问题(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:

  • responds to contours of arbitrary shape, not just straight lines;
  • performs noise reduction and non-maximum suppression to minimize the response; and
  • does a second detection with looser threshold to "trace" or "solidify" edges.

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 the threshold1 and threshold2 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.

橘香 2024-08-24 08:02:29

霍夫函数应返回 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文