OpenCV でキャプチャーしたビデオをファイルに出力
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import cv2 cap = cv2.VideoCapture(0) w = cap.get(cv2.CAP_PROP_FRAME_WIDTH) h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) fps = cap.get(cv2.CAP_PROP_FPS) fourcc = cv2.VideoWriter_fourcc(*'MP4V') out = cv2.VideoWriter('out.mp4',fourcc, 30.0, (int(w),int(h))) while(True): ret, frame = cap.read() if ret==True: out.write(frame) cv2.imshow('frame',frame) keyboard = cv2.waitKey(30) if keyboard == 27: break else: break cap.release() out.release() cv2.destroyAllWindows() |