I'm learning OpenCV and Python. I captured some images from my webcam and saved them. But they are saved by default into the local folder. I want to save them to another folder from direct path. How can I do that?
I tried this code
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()
Kindly look at the following code and see the commented out changes:
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()
如以上注释中所述,更改此行cv2.imwrite(path +'\\ test.jpg',img)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.