我正在尝试在 Ubuntu 16.4 上使用 Python 中的 OpenCV 录制视频。我正在使用 Logitec 920 相机。我的问题是,当我改变房间照明(从白光到红光)或改变帧速率时,录制视频的持续时间会根据情况而变快或变慢。这是我正在使用的代码:
import numpy as np
import cv2
import time
cam = cv2.VideoCapture(0) # select the camera
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID') # (*'XVID')
out = cv2.VideoWriter('teste6.avi',fourcc, 30.0, (640,480))
# Start time in seconds
t0 = time.time()
while (cam.isOpened()):
ret, frame=cam.read() # read frames
if ret == True:
out.write(frame)
cv2.imshow('video',frame) # plot frames
t1 = time.time() # Current time
dur = t1-t0; # diff time
if dur > 60:
out.release() # Stop video recording
print('end')
if cv2.waitKey(1) & 0xFF== ord('q'): # close window pressing 'q' key
break
cam.release()
cv2.destroyAllWindows()
有什么帮助吗?