我正在学习 OpenCV 和 Python。我从我的网络摄像头捕获了一些图像并保存了它们。但它们默认保存在本地文件夹中。我想将它们从直接路径保存到另一个文件夹。我该怎么做?
我试过这段代码
import cv2
import os
img = cv2.imread('image.jpg', 1)
path = 'C:\\Users\MJ-INFO\Desktop\amaster\test'
cv2.imwrite('test.jpg', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
最佳答案
请查看以下代码并查看注释掉的更改:
import cv2
import os
img = cv2.imread('image.jpg', 1)
path = r'C:\\Users\MJ-INFO\Desktop\amaster\test' #use r here as in windows sometimes there is a Unicode problem
cv2.imwrite(path, img) #use path here
cv2.waitKey(0)
cv2.destroyAllWindows()
关于python - 如何使用openCV将图像保存在文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57233138/