zhiqingstudy

Be a young person with knowledge and content

Opencv helps us to provide a very useful video capture api. We only need to call a few simple apis to collect video data. Let's see what apis are available.
  1. VideoCapture (): It is a virtual video collector. When we call VideoCapture, we tell it a device number to open the camera.
  2. Cap. read (): After opening the camera, you can use this api to read the video content frame by frame. There are two return values, the first is the status value, the read value is TRUE, and the second is the number of video frames.
  3. Cap. release(): release resources.

import cv2
from cv2 import waitKey

cv2.namedWindow('video',cv2.WINDOW_NORMAL)
# 获取视频设备,获取索引为0的摄像头设备,设备至少有一个摄像头
cap=cv2.VideoCapture(0)
while 1:
    # 从摄像头读视频帧
    ret,frame=cap.read()
    cv2.imshow('video',frame)
    # 等待键盘事件,如果按q键就退出
    key=cv2.waitKey(5)
    if key==ord('q'):
        break
# 释放VideoCaptrue
cap.release()

cv2.destroyAllWindows()
comment
head sculpture
Code:
Related

Why you shouldn't stay at a job for more than 2 years?

3 harsh facts long-distance relationships

how to keep your girlfriend interested in a long-distance relationship




Unless otherwise specified, all content on this website is original. If the reprinted content infringes on your rights, please contact the administrator to delete it
Contact Email:2380712278@qq.com

Filing number:皖ICP备19012824号