Created
April 10, 2019 02:08
-
-
Save tatesuke/25a8005566e2a37b9fe09acd3ea4455c to your computer and use it in GitHub Desktop.
pythonで動画撮影(音声なし)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
import datetime | |
cap = cv2.VideoCapture(0) | |
ret, frame = cap.read() | |
if ret==True: | |
frame = cv2.flip(frame,0) | |
print(frame.shape) | |
# Define the codec and create VideoWriter object | |
fourcc = cv2.VideoWriter_fourcc(*'XVID') | |
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (frame.shape[1],frame.shape[0])) | |
startTime = int(datetime.datetime.now().timestamp()) | |
while(cap.isOpened()): | |
ret, frame = cap.read() | |
if ret==True: | |
frame = cv2.flip(frame,0) | |
# write the flipped frame | |
out.write(frame) | |
now = int(datetime.datetime.now().timestamp()) | |
if (now - startTime) >= 5: | |
break | |
else: | |
break | |
# Release everything if job is finished | |
cap.release() | |
out.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment