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 -0600

Adelphina gravatar image

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

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

3 answers

Sort by ยป oldest newest most voted
0

answered 2020-04-02 03:11:06 -0600

The program doesn t have access to the camera you need to enable applications to access the pc camera from the control panel .

edit flag offensive delete link more
0

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

supra56 gravatar image

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

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 -0600

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 -0600 )edit

You will get blank screen. Unfortunately, no video.

supra56 gravatar imagesupra56 ( 2019-11-13 06:22:46 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 16,841 times

Last updated: Nov 13 '19