imshow: size.width>0 && size.height>0

  • Python
  • OpenCV

You may see

error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

Why it happens

  • The picture is empty: not found, or no camera frame.

How to fix it

  1. Check the file path, or ret from cap.read().
  2. Skip empty frames: if not ret: break.

It worked if: A window shows the picture.

Seen in a real run (some lines are close variants of it). Produced with Python 3.13 and OpenCV 5.1 on Windows.

Didn't help? Search another error or ask us.