python opencv CV_8UC1与CV_32SC1类型相关错误

问题描述:在使用Scipy.signal的手动Prewitt边缘检测算子后,因为自定义卷积的元素值没有进行归一化,图像像素超过255,而且变为浮点型。 在做后续基础操作时出现如下错误:


error: (-210) [start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function cvStartFindContours_Impl


error: (-215) src.depth() == 0 && (cn == 1 || cn == 3 || cn == 4) in function medianBlur

产生的原因参考了链接。因为opencv读取文件默认CV_8U类型,在做完卷积后会转化为CV_32FC1类型的矩阵来提高精度或者避免舍入误差。需要clip之后转换为np.uint8。

image = np.clip(image, 0, 255)# 归一化也行

image = np.array(image,np.uint8)

猜你喜欢

转载自blog.csdn.net/u010030977/article/details/81214145