zoukankan      html  css  js  c++  java
  • python opencv3 获取摄像头视频

     git:https://github.com/linyi0604/Computer-Vision

     1 # coding:utf8
     2 
     3 import cv2
     4 
     5 
     6 """
     7 捕获摄像头10s的视频信息 写入一个avi文件
     8 """
     9 
    10 cameraCapture = cv2.VideoCapture(0)     # 传入0代表0号摄像头
    11 fps = 30
    12 size = (
    13     int(cameraCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),
    14     int(cameraCapture.get(cv2.CAP_PROP_FRAME_HEIGHT))
    15 )
    16 
    17 videoWriter = cv2.VideoWriter(
    18     "outputVid.avi",
    19     cv2.VideoWriter_fourcc("I", "4", "2", "0"),
    20     fps,
    21     size
    22 )
    23 
    24 success, frame = cameraCapture.read()
    25 numFramesRemaining = 10 * fps - 1
    26 while success and numFramesRemaining:
    27     videoWriter.write(frame)
    28     success, frame = cameraCapture.read()
    29     numFramesRemaining -= 1
    30 
    31 cameraCapture.release()
    32 
    33 
    34 """
    35 如果使用一组摄像头或多个摄像头
    36 用grab和retrieve方法代替
    37 
    38 success0 = cameraCapture.grab()
    39 success1 = cameraCapture.grab()
    40 if success0 and success1:
    41     frame0 = cameraCapture0.retrieve()
    42     frame1 = cameraCapture1.retrieve()
    43     
    44     
    45 """
  • 相关阅读:
    js兼容性——获取当前浏览器窗口的宽高
    pip 换源
    5 二分查找 算法
    顺序查找 冒泡 快排 等
    4 顺序表和链表
    python垃圾回收机制
    3 栈 队列 双头队列
    2 数据结构的性能分析 timeit
    1 时间复杂度
    线程池 爬取一本小说
  • 原文地址:https://www.cnblogs.com/Lin-Yi/p/9392748.html
Copyright © 2011-2022 走看看