Python视频操作

import cv2 as cv
import time
import logging
import logging.handlers
import datetime

display_flag = False
#init videowriter
save_dir = './savevideo/'
fps = 15.0
frame_width = 960.0
frame_height = 540.0
size = (int(frame_width), int(frame_height))
vw0 = cv.VideoWriter(save_dir+'camera0.mp4', cv.VideoWriter_fourcc('H', 'E', 'V', 'C'), int(fps), size, True)
vw1 = cv.VideoWriter(save_dir+'camera1.mp4', cv.VideoWriter_fourcc('H', 'E', 'V', 'C'), int(fps), size, True)
vw2 = cv.VideoWriter(save_dir+'camera2.mp4', cv.VideoWriter_fourcc('H', 'E', 'V', 'C'), int(fps), size, True)
#init capture
capture0 = cv.VideoCapture(0, cv.CAP_DSHOW)
capture1 = cv.VideoCapture(1, cv.CAP_DSHOW)
capture2 = cv.VideoCapture(2, cv.CAP_DSHOW)

#fps infor
capture0.set(cv.CAP_PROP_FPS, fps)
capture1.set(cv.CAP_PROP_FPS, fps)
capture2.set(cv.CAP_PROP_FPS, fps)
fps0 = capture0.get(cv.CAP_PROP_FPS)
fps1 = capture1.get(cv.CAP_PROP_FPS)
fps2 = capture2.get(cv.CAP_PROP_FPS)

# if(display_flag):
print('fps0: ', fps0)
print('fps1: ', fps1)
print('fps2: ', fps2)

#frame size
capture0.set(cv.CAP_PROP_FRAME_WIDTH, frame_width)
capture0.set(cv.CAP_PROP_FRAME_HEIGHT, frame_height)
capture1.set(cv.CAP_PROP_FRAME_WIDTH, frame_width)
capture1.set(cv.CAP_PROP_FRAME_HEIGHT, frame_height)
capture2.set(cv.CAP_PROP_FRAME_WIDTH, frame_width)
capture2.set(cv.CAP_PROP_FRAME_HEIGHT, frame_height)

size0 = (int(capture0.get(cv.CAP_PROP_FRAME_WIDTH)), int(capture0.get(cv.CAP_PROP_FRAME_HEIGHT)))
size1 = (int(capture1.get(cv.CAP_PROP_FRAME_WIDTH)), int(capture1.get(cv.CAP_PROP_FRAME_HEIGHT)))
size2 = (int(capture2.get(cv.CAP_PROP_FRAME_WIDTH)), int(capture2.get(cv.CAP_PROP_FRAME_HEIGHT)))

if(display_flag):
    print('size0:', size0)
    print('size1:', size1)
    print('size2:', size2)

#capture
for ind_frame in range(0, 600):
    print("ind_frame: ", ind_frame)
    success0 = capture0.grab()
    success1 = capture1.grab()
    success2 = capture2.grab()
    if (display_flag):
        print('success0:', success0)
        print('success1:', success1)
        print('success2:', success2)

    if (success0 and success1 and success2):
        ret0, frame0 = capture0.retrieve()
        ret1, frame1 = capture1.retrieve()
        ret2, frame2 = capture2.retrieve()
        if(ret0 and ret1 and ret1):
            #video writer\
            cv.imshow('frame0', frame0)
            vw0.write(frame0)
            cv.imshow('frame1', frame1)
            vw1.write(frame1)
            cv.imshow('frame2', frame2)
            vw2.write(frame2)
            if cv.waitKey(1) & 0xFF == ord('q'):
                break


#release
vw0.release()
vw1.release()
vw2.release()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值