5

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.

Simplicity
  • 47,404
  • 98
  • 256
  • 385

1 Answers1

2

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')
cs95
  • 379,657
  • 97
  • 704
  • 746
  • Thanks for your kind reply. Yes, my destination is a directory. I used "copy". Does that differ from using "copy2"? – Simplicity Jun 21 '17 at 14:08
  • The only difference is that the `atime` and `mtime` of a file are not changed (with copy2). Besides that, there is no difference. – cs95 Jun 21 '17 at 14:09
  • When I use "copy2" I get "NameError: name 'copy2' is not defined", provided that I'm doing "import shutil" – Simplicity Jun 21 '17 at 14:10
  • 1
    @Simplicity Here's the docs for copy2: https://docs.python.org/2/library/shutil.html#shutil.copy2 – cs95 Jun 21 '17 at 14:11
  • For "copy2" I had to do the following: "from shutil import copy2" :-) – Simplicity Jun 21 '17 at 14:13
  • Thanks for your kind support, appreciate it! – Simplicity Jun 21 '17 at 14:13
  • 1
    @Simplicity Ah, yep. Won't work unless you either do that, or `import shutil; shutil.copy2(.., ..)`. No problem, cheers. – cs95 Jun 21 '17 at 14:14