我正试着画出这张图的最大轮廓.但我的代码总是返回一个空白图像.因此,我非常感谢您帮助解决这个问题.
以下是我的代码
import cv2
import numpy as np
img_1 = cv2.imread('img.png')
img_gray = cv2.cvtColor(img_1, cv2.COLOR_BGR2GRAY)
# get external contour
cnts = cv2.findContours(img_gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
maxcontour = max(cnts, key=cv2.contourArea, default=0)
# draw white filled contour on black background
contour = np.zeros(img_1.shape, dtype=np.uint8)
contour.fill(0)
mask1 = cv2.drawContours(contour, [maxcontour], 0, 255, -1)
cv2.imshow('mask1.png', mask1)
提前谢谢你