Why does cv2.imshow () lead to an error in my python compiler?

Hi friends, I just installed opencv and checked the base code, but this leads to an error. Code

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()

Error for cv2.imshow () -

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

This has been very helpful to me with your answer. thanks in advance

+4
source share
5 answers

Most likely, the imread call failed. Verify that the image "C: \ Users \ Pravin \ Desktop \ a.jpeg" exists. (The .jpeg extension seems unusual, maybe it should be .jpg?)

Also, as Hyperboreus suggests, try using slashes in the file name "C: /Users/Pravin/Desktop/a.jpg" or strip backslash

"C:\\Users\\Pravin\\Desktop\\a.jpg"
+4
source

, height > 0 width > 0. .

, imread.

, . , a.jpg, .

+2

...

import numpy as np
import cv2
img = cv2.imread('E:/Images/ece/1.png',1)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
0

, jpeg jpg

, ,

import numpy as np
import cv2
img=cv2.imread('C:\Users\Pravin\Desktop\a.jpg',1)    #changed image format to jpg
cv2.namedWindow('img',cv2.WINDOW_NORMAL)
cv2.Waitkey(10000)
cv2.imshow('cv2.WINDOW_NORMAL',img)
cv2.destoryAllWindows()
0

This is because the python compiler cannot find the image in place. if you copy the image to the python working directory and do it. it worked for me. # save the image in the current working directory IMG = cv2.imread ('roi.jpg', 1) cv2.imshow ('images', IMG)

-1
source

Source: https://habr.com/ru/post/1534760/


All Articles