Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV - Saving images to a particular folder of choice

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?

like image 284
Hieu Tran Trung Avatar asked Jan 11 '17 08:01

Hieu Tran Trung


People also ask

How do I save multiple images in OpenCV?

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.


1 Answers

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

like image 111
Jeru Luke Avatar answered Sep 22 '22 15:09

Jeru Luke