I'm learning OpenCV and Python. I captured some images from my webcam and saved them. But they are being saved by default into the local folder. I want to save them to another folder from direct path. How do I fix it?
Show activity on this post. change the name of the image to be saved to " [image name] [a number which increase after every loop] " By doing this your image will be stored with a new name after every loop.. otherwise all the images will overwrite the same name ! now your images will be saved as pic0. jpg, pic1.
The solution provided by ebeneditos works perfectly.
But if you have cv2.imwrite()
in several sections of a large code snippet and you want to change the path where the images get saved, you will have to change the path at every occurrence of cv2.imwrite()
individually.
As Soltius stated, here is a better way. Declare a path and pass it as a string into cv2.imwrite()
import cv2 import os img = cv2.imread('1.jpg', 1) path = 'D:/OpenCV/Scripts/Images' cv2.imwrite(os.path.join(path , 'waka.jpg'), img) cv2.waitKey(0)
Now if you want to modify the path, you just have to change the path
variable.
Edited based on solution provided by Kallz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With