Last active
June 2, 2017 22:51
-
-
Save isnullnull/17c049af74931ae410a244e384f1dc3e to your computer and use it in GitHub Desktop.
動画を早送りして任意フレームから開始し任意間隔で画面キャプチャを保存するOpenCV ref: http://qiita.com/n_ueh/items/8b458a3c24f27afe81a8
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
# -*- coding: utf-8 -*- | |
import cv2 | |
import numpy as np | |
print ("start.") | |
img1= cv2.imread("30000.jpg") | |
img2= cv2.imread("30666.jpg") | |
img3= cv2.imread("32544.jpg") | |
vis = np.concatenate((img1, img2, img3), axis=1) | |
cv2.imwrite('out.jpg', vis) | |
print ("done.") |
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
# -*- coding: utf-8 -*- | |
import cv2 | |
cap = cv2.VideoCapture('Video_001.avi') | |
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) | |
fps = int(cap.get(cv2.CAP_PROP_FPS)) | |
# 総フレーム数とFPSを確認 | |
print("FRAME_COUNT: ", frame_count) | |
print("FPS: ", fps ) | |
# 20分ぐらいのところまで早送り | |
start_pos = fps * (60 * 20) | |
# フレームポジションをファイル名にして、1秒4枚ぐらいの気持ちで画像保存 | |
print("-- start") | |
for idx in range(start_pos, frame_count, round(fps/4)): | |
cap.set(cv2.CAP_PROP_POS_FRAMES, idx) | |
current_pos = str(int(cap.get(cv2.CAP_PROP_POS_FRAMES))) | |
cv2.imwrite("pict/" + current_pos +".jpg", cap.read()[1]) | |
print("-- done.") | |
cap.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment