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()
Python视频操作
最新推荐文章于 2023-05-25 16:03:01 发布