简体   繁体   English

如何检测二值图像中的多边形

[英]How to detect polygon in binary image

I want to detect existence of continuous or closed polygon in binary image. 我想检测二进制图像中连续或闭合多边形的存在。 The image may contain polygon of variable number of edges and also there may be no polygon at all. 图像可以包含可变数量的边的多边形,并且根本不存在多边形。

Here is the positive case: 这是积极的情况:

在此输入图像描述

And, 和,

this one is negative case: 这个是否定的情况:

在此输入图像描述

Is there any method in image processing or some algorithm to detect continuous polygon ? 图像处理中是否有任何方法或某些算法来检测连续多边形?

Any kind of help is appreciated. 任何形式的帮助表示赞赏。

I hope you know how to find contours. 我希望你知道如何找到轮廓。

Using cv2.isContourConvex(contour) you can identify whether the detected contour is convex or not. 使用cv2.isContourConvex(contour)可以识别检测到的轮廓是否凸起。 By convex, I mean whether the convex is closed or not. 凸起是指凸起是否闭合。 You will be able to separate closed and open contours using this function, which return a boolean value True or False . 您将能够使用此函数分离闭合和开放轮廓,该函数返回布尔值TrueFalse

After separating out the contours you go on to perform further analysis deciding whether the contour has edges or not. 分离出轮廓后,继续进行进一步分析,确定轮廓是否有边缘。

您可能需要查看shapely.geometry.Polygon ,特别是is_valid方法。

If you need to detect both concave and convex polygons, then I can suggest you another way to do it, one has already have been told by @mdh 如果你需要检测凹面和凸面多边形,那么我可以建议你采用另一种方法来实现它,一个已经被@mdh告知过

  1. first, you need to find the contour ( cv2.findContours ) 首先,你需要找到轮廓( cv2.findContours
  2. then compute the area of the contour ( cv2.contourArea ) 然后计算轮廓的面积( cv2.contourArea
  3. compute the area of the black area in the binary image (compute the number of black pixels in the binary image, openCv has a countNonZero function, that does it for you) 计算二进制图像中黑色区域的面积(计算二进制图像中的黑色像素数,openCv有一个countNonZero函数,可以为你做到)
  4. compare the 2 values, if they are close (eg their ratio is close to 1, or greater than a value, you should chose it by testing on more images), then the contour you found is closed, so it may be a polygon 比较2个值,如果它们接近(例如它们的比率接近1,或者大于一个值,你应该通过测试更多图像来选择它),然后你找到的轮廓是闭合的,所以它可能是一个多边形

Of course there may be some errors in self-intersecting polygons, and/or if there are more than one contour in an image, but this may be fixed by a segmentation picking just the bounding box of the contour and apply the algo on each one. 当然,在自相交多边形中可能存在一些误差,和/或如果图像中存在多个轮廓,但这可以通过仅选取轮廓的边界框的分割来修复,并在每个轮廓上应用算法。

I had a tool to detect region in image and some properties belonging to that region. 我有一个工具来检测图像中的区域和属于该区域的一些属性。 https://github.com/mribrahim/Blob-Detection https://github.com/mribrahim/Blob-Detection

Think that, if it is a polygon , it will be a closed region (positive case). 认为,如果它是一个多边形,它将是一个封闭的区域(正面情况)。

If it is not closed,it will be a line (negative case). 如果它没有关闭,它将是一条线(负面情况)。

You can find regions properties with the blob detection tool, I mentioned. 我提到,您可以使用blob检测工具找到区域属性。 And you can use some properties like eccentricity, solidity to distinguish positive and negative cases. 你可以使用一些属性,如偏心,坚固来区分正面和负面的情况。

For example; 例如; negative case eccentiricity will be closed to 0, because of it is a line 负面情况eccentiricity将被关闭为0,因为它是一条线

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM