Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

opencv

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:\Users\Pravin\Desktop\a.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: ..\..\..\src\opencv\modules\highgui\src\window.cpp:261: error: (-215)
size.width>0 && size.height>0

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

like image 702
praveen Avatar asked Jan 10 '23 21:01

praveen


1 Answers

Most likely, the imread call didn't succeed. Make sure the image "C:\Users\Pravin\Desktop\a.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"
like image 142
Sergei Nosov Avatar answered Feb 04 '23 01:02

Sergei Nosov