指定坐标为python cv2的图像的遮光部分

2024-09-28 19:33:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我的问题与以下问题相反: Blackout image except for polygons provided as coordinates in OpenCV (Python)

我只希望我的图像的某一部分被遮住


Tags: in图像imageforasopencvprovidedexcept
1条回答
网友
1楼 · 发布于 2024-09-28 19:33:39

感谢@stateMachine提到了掩码的反转

除此之外,cv2.fillPoly函数应将颜色设置为[0,0,0]

这些是我换的部分

mask = np.zeros(image.shape, dtype=np.uint8)
mask = 255 - mask

cv2.fillPoly(mask, pts=[contours], color=(0,0,0))

相关问题 更多 >