opencv-python——报错解决:error: (-210:Unsupported format or combination of formats) in ‘threshold‘

报错截图

在这里插入图片描述

报错代码

ret, res_th = cv2.threshold(res_m, 127, 255, cv2.THRESH_BINARY)
cv2.imwrite("res_th.jpg", res_th)

解决方法

图像的格式一定要是np.uint8,而不是!!!!!.astype(np.uint8)转化一下即可解决!

不能用.astype("int8")!!!

 res_m = res_m.astype(np.uint8) 

你可能感兴趣的:(opencv,opencv,python,计算机视觉)