Opencv Error: (-215)Size.Width>0 && Size.Height>0 in Function Imshow

Assertion failure : size.width0 && size.height0 in function imshow

The image fails to load (probably because you forgot the leading / in the path). imread then returns None. Passing None to imshow causes it to try to create a window of size 0x0, which fails.

The poor error handling in cv probably owes to its quite thin wrapper layer on the C++ implementation (where returning NULL on error is a common practice).

OpenCV(4.2.0) error: (-215:Assertion failed) size.width0 && size.height0 in function 'cv::imshow'

Basically, this error tells you that you are trying to show an empty / non existent image. Please do check:

  • The path: I think the problem comes from cv2.imread(). If the path is incorrect, the img variable will be empty.

The way you tried to read the image is almost right:

img = cv2.imread(C:\Users\someone\Documents\python\____The Useless Installer____\PY\colorpic)

The way it should be:

  • double backslash for escaping the "\" character which has a special meaning in programming languages
  • you do need to enter the format of the picture (jpeg, png, etc..).
  • you need to pass this argument as a 'string' or "string"

Therefore try img = cv2.imread("C:\\Users\\someone\\Documents\\python\\____The Useless Installer____\\PY\\colorpic.jpg")





Related Topics



Leave a reply



Submit