Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Inference on a video? #152

Open
aditjha opened this issue May 18, 2020 · 1 comment
Open

Inference on a video? #152

aditjha opened this issue May 18, 2020 · 1 comment

Comments

@aditjha
Copy link

aditjha commented May 18, 2020

Hello, is it possible to run an inference of the trained model on a .mp4 video??? Has anyone implemented this yet? Also, can the pre-trained model be used to just run a simple inference on an image that can be seen as an output image?

@ajithvcoder
Copy link

@aditjha convert you video to frames and place it in folder use below code for inference.

#200 (comment)

code to split video to frames

import cv2
vidcap = cv2.VideoCapture('sample2.mp4')
success,image = vidcap.read()
count = 0
while success:
  cv2.imwrite("newvideo/frame%d.jpg" % count, image)     # save frame as JPEG file      
  success,image = vidcap.read()
  #print('Read a new frame: ', success)
  count += 1

code to combine frames to video

import cv2
import numpy as np
import glob
 
img_array = []
count = 0
for filename in glob.glob('results/*.jpg'):
    filename = "results/frame"+str(count)+".jpg"
    img = cv2.imread(filename)
    height, width, layers = img.shape
    size = (width,height)
    img_array.append(img)
    count+=1
 
 
out = cv2.VideoWriter('project.avi',cv2.VideoWriter_fourcc(*'DIVX'), 15, size)
 
for i in range(len(img_array)):
    out.write(img_array[i])
out.release()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants