Use the following code to read the image, [WARN:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_(' D:.jpg'): can't open/read file error message
import numpy as np
import cv2 as cv
import 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)
The reason is that "\" should be replaced with "\\" when using an absolute path
import numpy as np
import cv2 as cv
import 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)
Imported successfully