• 摄像头脸部识别 (1)opencv 抓取视频数据并保存


    摄像头脸部识别 (1)opencv 抓取视频数据并保存

    基于python 和 opencv 3.4.0 (兼容 opencv 2.X 参考注释),详细如代码

    
    import numpy as np
    import cv2
    
    # 从文件打开视频
    #videoFile = "test.mp4"
    #capture = cv2.VideoCapture(videoFile)
    #从摄像头获取视频
    capture = cv2.VideoCapture(0)
    
    # Define the codec and create VideoWriter object
    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    #opcv3.x
    #从视频文件打开可以获取fps
    #fps = capture.get(cv2.CAP_PROP_FPS)
    fps =  30
    size = (int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)),
            int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
    #opencv2.x
    #fps = capture.get(cv2.cv.CV_CAP_PROP_FPS)
    #size = (int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)),
    #        int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)))
    
    
    out = cv2.VideoWriter('output.avi',fourcc, fps, size)
    
    print("Video size:",size)
    imageindex = 0;
    while(capture.isOpened()):
        ret, frame = capture.read()
        if ret==True:
            out.write(frame)
            cv2.imshow('frame',frame)
            cv2.imwrite('image%s.jpg'%(str(imageindex)),frame)
            imageindex +=1
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
        else:
            print("Read video frame failed!")
            break
    
    # Release everything if job is finished
    capture.release()
    out.release()
    cv2.destroyAllWindows()
    
    
  • 相关阅读:
    模拟测试20190815(已更新)
    [JLOI2015]管道连接
    [BJWC2018]最长上升子序列
    [CQOI2012]局部极小值
    [HNOI2010]Bus 公交线路
    [BZOJ4903/CTSC2017]吉夫特
    [BZOJ3717/PA2014]Pakowanie
    [NOI2015]寿司晚宴
    [BZOJ4145/AMPPZ2014]The Prices
    [Usaco2013 Nov]No Change
  • 原文地址:https://www.cnblogs.com/dyufei/p/8194888.html
Copyright © 2020-2023  润新知