Ask Your Question
0

Python & OpenCV

asked 2016-01-23 09:11:19 -0600

peter_cz gravatar image

Dears,

I try to use OpenCV in Python, and running example such as

import numpy as np
import cv2

img = cv2.imread('messi5.jpg',0)

cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('image',img)
cv2.waitKey(0) 
cv2.destroyAllWindows()import numpy as np
import cv2

img = cv2.imread('messi5.jpg',0)

cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('image',img)
cv2.waitKey(0) 
cv2.destroyAllWindows()

Unfortunately I'm not able to dislpay image and getting errors such as

Traceback (most recent call last):

  File "<ipython-input-1-0d251b5710ac>", line 1, in <module>
    runfile('C:/Python27/Scripts/untitled1.py', wdir='C:/Python27/Scripts')

  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
    execfile(filename, namespace)


  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)

  File "C:/Python27/Scripts/untitled1.py", line 14, in <module>
    cv2.imshow('image',img)

error: ..\..\..\modules\highgui\src\window.cpp:269: error: (-215) size.width>0 && size.height>0 in function cv::imshow

what;s the propoer way to handle images and displaying hem in python?

Thank you. Peter

edit retag flag offensive close merge delete

Comments

In your code you've copied it twice... You may want to remove the first copy. One thing to try: remove this line and run the code cv2.namedWindow('image', cv2.WINDOW_NORMAL) I've ran the code without this line fine.

luketheduke gravatar imageluketheduke ( 2016-01-23 09:52:35 -0600 )edit

file not found, your image is empty, thus imshow() complains.

learn to add checks, whenever you load resources.

berak gravatar imageberak ( 2016-01-24 00:52:26 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-01-24 03:48:10 -0600

peter_cz gravatar image

Thanks a lot! I got it. Then I check it with "whos" command in python console and img is really empty - so that's why not working - I fix it - now works. I moved img source same directory as python script. Anyway need to check first img if not empty or cv2.imshow should probably return "img empty" instead of "error" - just little comments. Thanks for your help!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-01-23 09:11:19 -0600

Seen: 406 times

Last updated: Jan 23 '16