Not getting a continuous video output from webcam in openCV

ⅰ亾dé卋堺 提交于 2020-08-10 20:27:51

问题


I am new to OpenCV and I am trying to render video from my webcam but instead of getting a continuous live video, I get a single frame as a picture. When I tap on close button it shows me the next frame as a picture.

import cv2
vid=cv2.VideoCapture(0)
while(vid.isOpened()):
    ret,frame=vid.read()
    cv2.imshow('Video',frame)
    if cv2.waitKey(0) & 0xFF ==ord('e'):
        break
vid.release()
cv2.destroyAllWindows()

I am using Asus X507uf laptop. Maybe it is my webcam's fault.


回答1:


Try this code -

import cv2
vid=cv2.VideoCapture(0)
while(vid.isOpened()):
    ret,frame=vid.read()
    cv2.imshow('Video',frame)
    if cv2.waitKey(1) & 0xFF ==ord('e'):
        break
   
vid.release()
cv2.destroyAllWindows()


来源:https://stackoverflow.com/questions/62638030/not-getting-a-continuous-video-output-from-webcam-in-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!