Dennis Stritzke
Dennis Stritzke

Reputation: 5558

IOError with Python and OpenCV

I want to do some OpenCV Basic Operations using Python. My Problem is that the Pythoninterpreter says that the file I want to open with cv.LoadImage() dont exists. But as you can see in my code and the and the Interpreter Output this file exists and the Program should be able to read it.

Likly the answer is simple (I am new at Python Programming!). Thanks for answers!

Here my Code:

import cv, sys, os

print sys.argv[1]
print os.getcwd()
print os.access(sys.argv[1], os.F_OK)

img = cv.LoadImage(sys.argv[1], 1)

cv.NamedWindow("orginal", CV_WINDOW_AUTOSIZE)
cv.ShowImage("orginal", img)

cv.waitKey(0)

here is the Pythoninterpreter Output:

dennis@Powertux:~/opencv/showPicture$ python2.5 showPicture.py google-de02.jpg google-de02.jpg
/home/steffke/opencv/showPicture
True
Traceback (most recent call last):
  File "showPicture.py", line 7, in <module>
    img = cv.LoadImage(sys.argv[1], 1)
IOError: [Errno 2] No such file or directory: 'google-de02.jpg'

Upvotes: 3

Views: 1108

Answers (3)

kettlepot
kettlepot

Reputation: 11011

Try using the repr function when the exception happens.

Upvotes: 0

Dennis Stritzke
Dennis Stritzke

Reputation: 5558

I've tried both suggestions, but its the same like before. the os.access returns a TRUE but the function cv.LoadImage produce the same error.

Any other solutions?

anyhow thanks fpr answer...

Upvotes: 2

kettlepot
kettlepot

Reputation: 11011

Try giving it the whole path instead of the name only, or maybe using .\google-de02.jpg.

Upvotes: 1

Related Questions