A
A
Adelphina2019-11-12 22:42:02
Python
Adelphina, 2019-11-12 22:42:02

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

To capture the video stream, I use the simplest code:
import cv2
import time
import numpy as np
cap = cv2.VideoCapture(0)
time.sleep(3)
while cv2.waitKey(1)!= 32:
flag, frame = cap.read()
cv2.imshow("video", frame)
cap.release()
cv2.destroyAllWindows()
Error: cv2.error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\highgui\src\ window.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Dugin, 2019-11-13
@adugin

Read documentation. Understand the purpose of the flag variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question