使用一下代码读取图像,出现[ WARN:0@1.635] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_(‘D:.jpg’): can’t open/read file 报错信息
import numpy as npimport cv2 as cvimport matplotlib.pyplot as plt# 读取图像img = cv.imread("D:\2.jpg")# 显示图像# 利用opencv展示图像# cv.imshow('image', img)# cv.waitKey(0)# cv.destroyAllWindows()# matplotlib# plt.imshow(img[:, :, ::-1])plt.imshow(img, cmap="gray")plt.show()# 图像保存cv.imwrite("D:\2.png", img)
原因是使用绝对路径时“\”要换成“\\”
import numpy as npimport cv2 as cvimport matplotlib.pyplot as plt# 读取图像img = cv.imread("D:\\2.jpg")# 显示图像# 利用opencv展示图像# cv.imshow('image', img)# cv.waitKey(0)# cv.destroyAllWindows()# matplotlib# plt.imshow(img[:, :, ::-1])plt.imshow(img, cmap="gray")plt.show()# 图像保存cv.imwrite("D:\\2.png", img)
导入成功
来源地址:https://blog.csdn.net/m0_60266328/article/details/127753455