效果图如下所示:
我希望背景是黑色
代码如下:
(三通道)
# 将img变为同样大小的黑色img
img = np.zeros((image.shape[0], image.shape[1], 3), dtype = "uint8")
re = cv2.drawContours(img, [box], 0, (0, 255, 0), -1)
img = 255 * np.ones((image.shape[0] ,image.shape[1], 3), dtype=np.uint8)
#生成一张白图
创建其他颜色:
#亮绿色
to_save = (0,255,0) * np.ones((self.image.shape[0] ,self.image.shape[1], 1), dtype=np.uint8)
#浅红色
red_img = (252,157,154) * np.ones((self.image.shape[0] ,self.image.shape[1], 1), dtype=np.uint8)