前回の内容を動画に応用するには
動画を静止画に変換する作業が必要になります
下がそのコードになります(OpenCVを使用)
拡張子は
変換前:MOV、GIF・・・
変換後:PNG、JPG・・・
が可能です
import os
import cv2
import numpy as np
import cv2
import numpy as np
#入力映像ファイルの指定
inname = './images/input.mov'
inname = './images/input.mov'
#画像生成時にファイル名する名前の頭の部分
outname = 'frame'
outname = 'frame'
#画像の読み込み
captureimg = cv2.VideoCapture(inname)
captureimg = cv2.VideoCapture(inname)
#1フレームずつ書く
cnt = 0
cnt = 0
while True:
ret, frame = captureimg.read()
if ret == True:
ret, frame = captureimg.read()
if ret == True:
# ./data/still_images/フォルダーの中に保存される
# 3桁のフレーム番号を入れて,JPG形式で保存
cv2.imwrite('./data/still_images/'+outname+str("{0:03d}".format(cnt)) +'.jpg', frame)
cnt += 1
else:
break
# 3桁のフレーム番号を入れて,JPG形式で保存
cv2.imwrite('./data/still_images/'+outname+str("{0:03d}".format(cnt)) +'.jpg', frame)
cnt += 1
else:
break