Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
809 views
in Technique[技术] by (71.8m points)

opencv - why cv2.imshow() results in error in my python compiler?

Hi friends i just now installed opencv and checking the basic code but it results in error. The code is

import numpy as np
import cv2
img=cv2.imread('C:UsersPravinDesktopa.jpeg',1)
cv2.namedWindow('img',cv2.WINDOW_NORMAL)
cv2.Waitkey(10000)
cv2.imshow('cv2.WINDOW_NORMAL',img)
cv2.destoryAllWindows()

The error for cv2.imshow() is

Traceback (most recent call last):
 File "<pyshell#3>", line 1, in <module>
cv2.imshow('image',img)
error: ......srcopencvmoduleshighguisrcwindow.cpp:261: error: (-215)
size.width>0 && size.height>0

It was very helpful to me with your answer. Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Most likely, the imread call didn't succeed. Make sure the image "C:UsersPravinDesktopa.jpeg" exists. (The extension .jpeg seems unusual, maybe it has to be .jpg?)

Also, as Hyperboreus suggests, please, try using forward slashes in the filename "C:/Users/Pravin/Desktop/a.jpg", or escape backslashes

"C:\Users\Pravin\Desktop\a.jpg"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...