矩形(四边形)通过ConvexHull进行检测 [英] Rectangle(quadrilateral) Detection by ConvexHull

查看:419
本文介绍了矩形(四边形)通过ConvexHull进行检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从图片中检测矩形



我用 cv2.findContours() cv2.convexHull()过滤掉不规则的多边形。



之后,我将使用船体长度来确定轮廓是否为矩形或不。

  hull = cv2.convexHull(contour,returnPoints = True)
如果len(hull)== 4:
return True

然而,有时, convexHull() code>将返回一个长度为5的数组。
如果我使用上面的标准,我会错过这个矩形。



例如,






这里是我的问题:给定一个长度为5的数组(凸壳) ,我该如何确定它是否实际上是指四边形?谢谢。



================================ =====================================
已更新:



在使用Sobel X和Y方向后,

  sobelxy = cv2.Sobel(img_inversion,cv2。我得到:

解决方案

好吧,
这不是提取矩形的正确方法。由于我们在此讨论基础知识,因此我建议您采用图像的反转并在X和Y方向上应用Sobel,然后运行findcontours函数。然后用这个,你将能够获得很多矩形,你可以过滤掉。您将必须应用大量检查来识别其中包含文本的矩形。另外我不明白你为什么要强制选择长度为5的矩形。你限制了比例。其次,另一种方法是使用Sobel X和Y图像,然后应用OpenCV的LineSegmentDetector。一旦你得到所有的线段,你必须将RANSAC应用于(四边形拟合),所以这里的条件应该是一组随机选择的相交线上的所有角度应该是锐角(粗略),最后用文本滤掉四边形(对于这种使用SWT或其他可靠的技术)。

至于你的查询,你应该选择理想长度为4(点)的四元组。



Ref:



同样在反转之前,它更好地抑制了光照伪像。这可以使用同态滤波来完成。或拍摄图像日志。

I want to detect the rectangle from an image.

I used cv2.findContours() with cv2.convexHull() to filter out the irregular polygon.

Afterwards, I will use the length of hull to determine whether the contour is a rectangle or not.

hull = cv2.convexHull(contour,returnPoints = True)
if len(hull) ==4:
    return True

However, sometimes, the convexHull() will return an array with length 5. If I am using the criterion above, I will miss this rectangle.

For example,

After using cv2.canny()

By using the methods above, I will get the hull :

 [[[819 184]]

 [[744 183]]

 [[745 145]]

 [[787 145]]

 [[819 146]]]


Here is my question: Given an array (Convex Hull) with length 5, how can I determine whether it is actually referring to a quadrilateral? Thank you.

===================================================================== updated:

After using Sobel X and Y direction,

sobelxy = cv2.Sobel(img_inversion, cv2.CV_8U, 1, 1, ksize=3)

I got:

解决方案

Well, This is not the right way to extract rectangles. Since we are talking basics here, I would suggest you to take the inversion of the image and apply Sobel in X and Y direction and then run the findcontours function. Then with this you will be able to get lot of rectangles that you can filter out. You will have to apply lot of checks to identify the rectangle having text in it. Also I dont understand why do you want to force select rectangle with length 5. You are limiting the scale.

Secondly, another way is to use the Sobel X and Y image and then apply OpenCVs LineSegmentDetector. Once you get all the line segments you have to apply RANSAC for (Quad fit) so the condition here should be all the angles on a set of randomly chosen intersecting lines should be acute(roughly) and finally filter out the quad roi with text( for this use SWT or other reliable techniques).

As for your query you should select quad with ideally length 4 (points).

Ref: Crop the largest rectangle using OpenCV

This link will give you the jist of detecting the rectangle in a very simple way.

The images below give you a sort of walkthrough for inversion and sobel of image. Inversion of image eliminates the double boundaries you get from sobel.

For Inversion you use tilde operator.

Also before taking inversion also, its better you suppress the illumination artifacts. This can be done using homomorphic filtering. or taking log of an image.

这篇关于矩形(四边形)通过ConvexHull进行检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆