Удаление внешних контуров с изображения с помощью Python и OpenCV - PullRequest
0 голосов
/ 17 апреля 2020

Я использовал этот код, но он внутри. Я хочу удалить вне контуров

def is_contour_bad(c):
    # approximate the contour
    peri = cv2.arcLength(c, True)
    approx = cv2.approxPolyDP(c, 0.02 * peri, True)
    # the contour is 'bad' if it is not a rectangle
    return not len(approx) == 4

mask = np.ones(image.shape[:2], dtype="uint8") * 255
# loop over the contours
for n in cnts:
    # if the contour is bad, draw it on the mask
    if is_contour_bad(n):
        cv2.drawContours(mask, [n], -1, 0, -1)
# remove the contours from the image and show the resulting images
image = cv2.bitwise_and(image, image, mask=mask)
imshow(mask)
imshow(image)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...