报错:OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor’

因为路径中有中文!!!
或者该路径不存在该图像

图像相加操作

加法: 使用cv2.add()将两个图像相加,可以使用numpy中的矩阵加法来实现。但是在opencv中加法是饱和操作,也就是有上限值,numpy会对结果取模。 综上,使用opencv的效果更好

进行图片相加操作需要注意的点

1.图像的大小要相同 例如分辨率都是256*256
否则报错

OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\core\src\arithm.cpp:650: error: (-209:Sizes of input arguments do not match) The operation is neither ‘array op array’ (where arrays have the same size and the same number of channels), nor ‘array op scalar’, nor ‘scalar op array’ in function ‘cv::arithm_op’

2.路径中不能有中文

img1=cv2.imread('data/i1.png')
img2=cv2.imread('data/i2.png')

res = cv2.add(img1,img2)
plt.imshow(res)

原图:
i1.png
i2.png
生成的图像
结果

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐