问题描述
我使用轮廓检测进行矩形检测,并在调整透视投影之前使用 OpenCv 应用多边形以获取矩形的位置.而且效果很好.但是我小组中的一些人建议改为 Hough 变换.我想知道使用霍夫变换进行矩形检测是否有任何优势.
I made rectangle detection work with contour detection and apply polygon with OpenCv to get location of the rectangle before adjusting the perspective projection. And it's working great. But some people in my group suggested Hough transformation instead. I wonder if there is any advantage of using Hough transformation for rectangle detection.
更新:这两种方法我都试过了.在我的示例中,两种方法在 Canny 边缘检测后都运行良好.但是由于霍夫变换产生线,我们必须假设一些事情,例如线的长度和线的可连接性,并且应该进行额外的计算,例如搜索连接的线并从连接的线上找到角点.就个人而言,我更喜欢轮廓方法,因为它的概念更简单.使用该方法,您只需搜索可以用具有 4 个角的闭合和凸多边形近似的轮廓,并调整多边形的透视投影.就是这样.
Update: I tried both of the methods. In my example, both methods worked fine after Canny edge detection. But since Hough transformation produces lines, we have to assume several things such as length of lines and connectability of the lines and should do additional computations such as searching connected lines and find corner points from the connected lines. Personally, I liked contour method better since its concept is simpler. With the method, you just search contours that can be approximated with closed and convex polygons with 4 corners and adjust the polygons for their perspective projections. That's about it.
推荐答案
到目前为止,您使用轮廓检测获得了什么样的结果?有例子吗?
What sort of results are you getting with contour detection so far? Got any examples?
霍夫变换应该适用于矩形检测 IFF 您可以假设矩形的边是图像中最突出的线条.然后你可以简单地检测霍夫空间中的 4 个最大峰值,你就得到了矩形.
Hough transform should work well for rectangle detection IFF you can assume that the sides of the rectangle are the most prominent lines in your image.Then you can simply detect the 4 biggest peaks in hough space and you got your rectangle.
例如,这适用于深色背景前一张白纸的照片.
This works for example with a photo of a white sheet of paper in front of a dark background.
理想情况下,您应该使用模糊、阈值、形态学运算符对图像进行预处理,以在霍夫变换之前去除任何小规模结构.
Ideally you would preprocess the image with blur, threshold, morphological operators to remove any small-scale structures before hough transform.
如果图像中有多个较小的矩形或其他类型的突出线条,轮廓检测可能是更好的选择.
If there are multiple smaller rectangles or other sorts of prominent lines in your images, contour detection might be the better choice.
hough 变换的一些普遍优势:
Some general advantages for the hough transform off the top of my head:
- 如果矩形的一部分被遮挡或超出框架,霍夫变换仍然可以工作.
- 我猜霍夫变换应该比轮廓检测更快吗?
- 霍夫变换将忽略任何不是直线的东西,因此您可能会在处理杂乱的图像时取得更大的成功.(如果矩形边是最突出的线条)
最终可能取决于输入数据.有例子吗?
In the end it probably depends on the input data. Got any examples?
也许组合方法最好?看结合霍夫变换和轮廓算法检测车辆牌照
不久前我做了一些使用霍夫变换检测矩形的实验,你可以在这里看到一些初步结果:http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=14491&start=9
I did some experiments in using hough transform to detect rectangles a while back, you can see some preliminary results here:http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=14491&start=9
不幸的是,这就是目前存在的全部,该项目目前处于暂停状态,最终我希望在我不那么忙的时候恢复它.
Unfortunately that is all that exists at the moment, the project is currently on hiatus, eventually I hope to resume it when I am less busy.
我对你的结果非常感兴趣.
I'd be very interested in your results in comparison.
(如果您要进行透视校正,还可以查看透视变形矩形的比例)
(If you are doing perspective correction, also check out proportions of a perspective-deformed rectangle )
这篇关于使用透视投影进行矩形识别的霍夫变换与轮廓检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!