Monday 30 January 2017

Python + OpenCV - Copying an image to some directory




I would like to copy some images to some directory, rather than cv2.imwrite the images. The reason is that when I use cv2.imwrite in OpenCV, I get images that are larger than the original ones, apart from that I can see that some images are being rotated.



Would that be possible in Python + OpenCV, since I don't want any operation to be made on the original image, which cv2.imwrite seems to be doing?



Thanks.


Answer



You don't need opencv to do this. You can use the shutil library.




import shutil
shutil.copyfile('path/to/1.jpg', 'new/path/to/1.jpg')


Note that the destination path must specify the filename too. If you don't want this, you can use shutil.copy2 which lets you specify a directory as the destination.



shutil.copy2('path/to/1.jpg', 'new/path/to/dir')

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...