I was able to successfully split a video into it's constituent image frames and analysed them using keras RESNet50 model. I was also able to add the overlays of predictions into these individual images. Now I want to recreate the original video by putting these processed images with overlays back together into an mp4 file.
How can I create a video from individual jpg image frames in sequence?
I am trying to use cv2.VideoWriter to write these images back into a separate video file.
uname -a
gives me the following output
Linux myhost 4.15.0-1023-azure #24~16.04.1-Ubuntu SMP Wed Aug 29 12:54:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
My first 11 frames are named frame-0000.jpg through frame-0011.jpg
How can I create a video from individual jpg image frames in sequence?
You can use this code for creating video frame by frame from jpg images. These images will be read from folder where this script is.
import cv2 #Import of openCV library
import os
#Create video, with name 'video.mp4', MP4 codec, 60 fps, width 1280 and height of 1024
video = cv2.VideoWriter('video.mp4',cv2.VideoWriter_fourcc(*'MP4V'),60,(1280,1024))
for file in os.listdir('./'): #List every file in this folder
if ".jpg" in file: #Filter only jpg files
image = cv2.imread(file) #Load image from disk
video.write(image) #Put image into video.
video.release() #Save video to disk.
You can modify this code for loading images from your application or some array.
Edit: added commentary
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments