ezamorag commited on
Commit
f5eb105
·
1 Parent(s): 8c65f97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py CHANGED
@@ -1,6 +1,7 @@
1
  from PIL import Image, ImageDraw, ImageFont
2
  from dotenv import load_dotenv
3
  import matplotlib.pyplot as plt
 
4
  from io import BytesIO
5
  from glob import glob
6
  import gradio as gr
@@ -144,8 +145,30 @@ def testing_directcounter(input_img):
144
  img, text = display_detectionsandcountings_directcounter(input_img, countings, prob_th=0, cth = 0)
145
  return img, text
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  def video_identity(video):
148
  vidupload2aws(video)
 
149
  return video
150
 
151
  with gr.Blocks() as demo:
 
1
  from PIL import Image, ImageDraw, ImageFont
2
  from dotenv import load_dotenv
3
  import matplotlib.pyplot as plt
4
+ from moviepy.editor import *
5
  from io import BytesIO
6
  from glob import glob
7
  import gradio as gr
 
145
  img, text = display_detectionsandcountings_directcounter(input_img, countings, prob_th=0, cth = 0)
146
  return img, text
147
 
148
+ def extractframes(vid_path):
149
+ clip = VideoFileClip(vid_path)
150
+ clip = clip.subclip(0, 10)
151
+ stride = int(round(clip.fps,0))/2
152
+ frames = []
153
+ for i,frame in enumerate(clip.iter_frames()):
154
+ if i % stride == 0:
155
+ frames.append(frame)
156
+ return frames
157
+
158
+ def processvideo(vid_path, detector):
159
+ frames = extractframes(vid_path)
160
+ img_list = []
161
+ for frame in frames:
162
+ img, text = detector(frame)
163
+ img_list.append(np.asarray(img))
164
+ clip = ImageSequenceClip(img_list, fps=2)
165
+ outvid_path = "out.mp4"
166
+ clip.write_videofile(outvid_path)
167
+ return outvid_path
168
+
169
  def video_identity(video):
170
  vidupload2aws(video)
171
+ video = processvideo(vid_path, detector = testing_yolocounter)
172
  return video
173
 
174
  with gr.Blocks() as demo: