查找和丢弃轮廓内的轮廓

时间:2019-10-28 14:59:35

标签: python opencv image-processing

我需要在图像中找到多个面板的轮廓,但是在这些面板中还有更多的矩形,这些矩形也可以通过findcontours函数检测到,但是我需要将其删除,以便仅获得最外面的轮廓,

enter image description here

这是一个存在此问题的图像的示例,我需要两个矩形来构成L形对象,但我不希望该矩形位于矩形内。

现在我可以使用此代码找到轮廓,但是无法移除轮廓内的轮廓。

_, contours,h = cv2.findContours(image,cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
        areasCheck = []

        for cnt in contours:
            [x,y,w,h] = cv2.boundingRect(cnt)
            area = cv2.contourArea(cnt)
            if (w >= (width / 100 * 90)) and (h >= (height / 100 * 90)):
                continue
            elif w <= (width / 100 * 10) or h <= (height / 100 * 10):
                continue

0 个答案:

没有答案
相关问题