-1

I am struggling to read a picture from certain directory.

img = cv2.imread('/Users/myname/Desktop/traindog.8011.jpg', cv2.IMREAD_COLOR) 
print (img)

I just simplified my code to make sure the issue and understand above. And even when I put the full path of the picture, it always returns 'None'. Where did I get a wrong ? Thank you in advance.

TIshow
  • 918
  • 4
  • 12
  • 27

2 Answers2

2

I spend the whole night found that if your folder name has space then it can't read the file. So be careful with your folder name which you include to your path.

-4

try this:

img = cv2.imread('\Users\myname\Desktop\traindog.8011.jpg', cv2.IMREAD_COLOR) 

or

img = cv2.imread('//Users//myname//Desktop//traindog.8011.jpg', cv2.IMREAD_COLOR) 
yoram
  • 191
  • 1
  • 1
  • 13
  • are you sure the filename is correct? the path exists? is this happen with other images and folders? – yoram Feb 27 '18 at 15:37
  • 3
    This is not helpful advice. Neither is a double slash at the beginning of any meaning, nor does changing slashes around to backslashes make things better. In fact it makes them worse: \t is escape code for tabular, which you introduced. – deets Feb 27 '18 at 15:37
  • but with single slash it won't work no matter what, only with one of these options @deets – yoram Feb 27 '18 at 15:42
  • 2
    @yoram that is nonsense. There is no meaning defined for double forward slashes as you show. And the backslash string is still broken, and can't possibly work as path because the user is clearly on a mac, and the mac doesn't use backward slashes as path separaters. Look at `os.sep`. Just because a path is not working does not mean you get it to work by randomly doing things to it. – deets Feb 27 '18 at 15:49
  • can you share what was the problem? @user7421972 – yoram Mar 04 '18 at 09:22