0

I am a few images in the "Downloads" folder. I want to save the images to a particular folder named "unclassified" using OpenCV. I have already seen the question OpenCV - Saving images to a particular folder of choice and from that I have tried this particular code:

 import cv2
 import os
 img = cv2.imread('1.jpg', 1)
 path = '~/Downloads/unclassified'
 cv2.imwrite(os.path.join(path , 'waka.jpg'),img)
 cv2.waitKey(0)

This works on Windows but it didn't work on Ubuntu (I am working on a Ubuntu 16.04) when I wrote:

cv2.imwrite(os.path.join(path , 'waka.jpg'), img)

The code returned False on Ubuntu. What should I do to solve this error?

Berriel
  • 12,659
  • 4
  • 43
  • 67
Osama
  • 55
  • 1
  • 4

1 Answers1

0

You can use something like that:

cv2.imwrite(os.path.expanduser(os.path.join(path , 'waka.jpg')), img)

The problem is with the "~". os.path.expanduser(...) will change that with the appropriate path.

Berriel
  • 12,659
  • 4
  • 43
  • 67