简体   繁体   中英

black screen no output error in displaying video/webcam feed in OpenCV

I am new to OpenCV. I want to display video/webcam feed in OpenCV.I have written the following code

import cv2
cap = cv2.VideoCapture(0)
while True:
    ret,img  = cap.read()
    cv2.imshow("Frame",img)

在此处输入图像描述

Instead of getting webcam feed or video, I get a black screen with no output as shown in the picture

You need to add cv.waitKey(1) or some other ms number as you wish. This will display a frame for 1 ms. Check the example here :

 if cv2.waitKey(1) & 0xFF == ord('q'):
        break

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM