随手记,在win10下用摄像头录制视频没问题,把代码直接复制带ubutnu下,一直花屏,试了很多,最后发现是少了一句
cap.set(6,cv2.VideoWriter_fourcc('M', 'J', 'P', 'G') )
下面贴全部代码
import cv2
import time
timenow = time.strftime('%Y%m%d_%H%M%S')
def get_time_stamp():
ct = time.time()
local_time = time.localtime(ct)
data_head = time.strftime("%H:%M:%S", local_time)
data_secs = (ct - int(ct)) * 1000
time_stamp = "%s.%03d" % (data_head, data_secs)
return time_stamp
def videowork():
videoname = 'data_0527/' + time.strftime('%Y%m%d_%H%M%S') + '.avi'
fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
cap = cv2.VideoCapture(0)
cap.set(3,1920)
cap.set(4,960)
cap.set(5,25)
cap.set(6,cv2.VideoWriter_fourcc('M', 'J', '