higashi
Hi, I’m higashi.
This time, I introduce how to make images of movie’s all frame.
Specifically, by using below movie,
I make these images that is composed in above movie.
Supported formats is gif and mp4.
I think it will be useful when we make teacher data for AI from movie.
So, let’s get started!!
Make Image from “gif” Format Movie
At first, I make images from gif format movie.
The program is shown below.
It assume that there is a base movie in same folder with this program.
#import library
import cv2
os
#make folder for images
folder_name='gif_pic'
os.makedirs(folder_name, exist_ok=True)
#load base movie
movie = cv2.VideoCapture('01_gif_test.gif')
#get frame number
nframe = int(movie.get(cv2.CAP_PROP_FRAME_COUNT))
#making images
for i in range(nframe):
ret, frame = movie.read()
cv2.imwrite(folder_name+'/pic_'+str(i).zfill(3)+'.jpg', frame)
The result is below.
It is likely no problem.
Make Image from “mp4” Format Movie
Next is mp4 format.
It also assume that there is a base movie in same folder with this program.
#import library
import cv2
os
#make folder for images
folder_name='mp4_pic'
os.makedirs(folder_name, exist_ok=True)
#load base movie
movie = cv2.VideoCapture('02_mp4_test.mp4')
#get frame number
nframe = int(movie.get(cv2.CAP_PROP_FRAME_COUNT))
#making images
for i in range(nframe):
ret, frame = movie.read()
cv2.imwrite(folder_name+'/pic_'+str(i).zfill(3)+'.jpg', frame)
The result is below.
It is likely no problem too.
That’s all. Thank you!!
コメント