由于 cv.findContours,我想从轮廓中获取图像蒙版(它只存在 1 个轮廓)。
但是,虽然我的轮廓变量不为空,但我无法使用 cv.drawContours 检索图像蒙版,我的目标图像始终为空。
这是我的代码:
img = mosaicImage[:,:,0].astype('uint8')
contours, _ = cv.findContours(img.copy(), cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
mask = np.zeros(img.shape, np.uint8)
cv.drawContours(mask, contours, -1, (0,255,0),1)
Run Code Online (Sandbox Code Playgroud)
我希望你能帮忙!
谢谢