生成掩码过程中报错如标题,代码如下
total_target_mask= np.zeros(label.shape)
counter=cv2.findContours(total_target_mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
因为findContours只能处理灰度图,审查了一下shape,(2048,2448)貌似也没问题,打印数值,发现是float型,忘了指定numpy的类型,图像需要int8
应该是
total_target_mask= np.zeros(label.shape,dtype=np.int8)
紧接着又报错error: (-210:Unsupported format or combination of formats) in function ‘cv::threshold’
其实图像需要的是uint8,uint8和int8的区别:
“ uint”中的“ u”是“ unsigned”的缩写,表示整数没有符号(不能为负)。有符号的8位整数值从-128到+127,而无符号的值从0到255:经典的“字节”
所以最终应该如下:
total_target_mask= np.zeros(label.shape,dtype=np.uint8)