本文介绍了在OpenCV中检测不完整的矩形(缺少角/短角)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究opencv squares示例的一种变体,以检测矩形。对于封闭的矩形来说,它可以正常工作,但是我想知道我应该采取什么方法来检测具有开口的矩形,例如,缺少角,线条太短。



我执行了一些扩张操作,该方法可以缩小较小的间隙,但不能消除较大的间隙。



我考虑使用凸面外壳或边界矩形以生成用于比较的轮廓,但是由于矩形的边缘是断开的,因此每个边缘都将读为单独的轮廓。



我认为第一步是检测哪些线适合形成完整的矩形,然后执行某种线外推法。这

解决方案

也许对本文感兴趣?



基本上,对图像进行霍夫线变换。您将在(theta,rho)空间中与存在线条的位置有关的位置获得最大值。值越大,线越长/越直。也许做一个门槛,只得到最好的台词。然后,我们尝试寻找



1)平行的线对:最大值以相似的theta值出现



2)相似的长度:最大值的值相似



3)正交于另一对线:θ值与其他线对成90度角theta值



本文中有更多详细信息,例如在滑动窗口中进行转换,然后使用误差度量来合并多个匹配项。


I've been working off a variant of the opencv squares sample to detect rectangles. It's working fine for closed rectangles, but I was wondering what approaches I could take to detect rectangles that have openings ie missing corners, lines that are too short.

I perform some dilation, which closes small gaps but not these larger ones.

I considered using a convex hull or bounding rect to generate a contour for comparison but since the edges of the rectangle are disconnected, each would read as a separate contour.

I think the first step is to detect which lines are candidates for forming a complete rectangle, and then perform some sort of line extrapolation. This seems promising, but my rectangle edges won't lie perfectly horizontally or vertically.

I'm trying to detect the three leftmost rectangles in this image:

解决方案

Perhaps this paper is of interest? Rectangle Detection based on a Windowed Hough Transform

Basically, take the hough line transform of the image. You will get maximums at the locations in (theta, rho) space which relate to the places where there are lines. The larger the value, the longer/straighter the line. Maybe do a threshold to only get the best lines. Then, we are trying to look for pairs of lines which are

1) parallel: the maximums occur at similar theta values

2) similar length: the values of the maximums are similar

3) orthogonal to another pair of lines: theta values are 90 degrees away from other pairs' theta values

There are some more details in the paper, such as doing the transform in a sliding window, and then using an error metric to consolidate multiple matches.

这篇关于在OpenCV中检测不完整的矩形(缺少角/短角)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:36