Ask Your Question
0

How to fix error error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow' when trying to capture a video stream?

asked 2019-11-12 14:33:42 -0500

updated 2019-11-12 14:48:56 -0500

I use the simplest code:

import cv2
import time
import numpy as np

cv2.namedWindow("video")

cap = cv2.VideoCapture(1)
time.sleep(3)

while cv2.waitKey(1)!= 30:
    flag, frame = cap.read()
    cv2.imshow("video", frame)

cap.release()
cv2.destroyAllWindows()

and I have an error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

How can I fix that? Thanks

edit retag flag offensive close merge delete

Comments

your input is invalid

apart from that, please do us a favour and replace the (useless) screenshot of your code with a TEXT version, thank you.

berak gravatar imageberak ( 2019-11-12 14:38:34 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2019-11-13 06:18:55 -0500

supra56 gravatar image

updated 2019-11-13 06:25:47 -0500

I got same as your error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'. Unfortunately, you can't get debug to fix it.

  • VIDEOIO ERROR: V4L2: Could not obtain specifics of capture window.
  • VIDEOIO ERROR: V4L: can't open camera by index 1
  • /dev/video1 does not support memory mapping

To get it working. Change this:

cap = cv2.VideoCapture(1)

to:

cap = cv2.VideoCapture(0)
edit flag offensive delete link more
-1

answered 2019-11-12 20:28:41 -0500

Gourav gravatar image

You can add an exception handling block
try:
cv2.imshow("video",frame)
except
pass

edit flag offensive delete link more

Comments

does never solve the actual problem

berak gravatar imageberak ( 2019-11-13 01:05:49 -0500 )edit

You will get blank screen. Unfortunately, no video.

supra56 gravatar imagesupra56 ( 2019-11-13 06:22:46 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-11-12 14:33:42 -0500

Seen: 107 times

Last updated: Nov 13