reab5555 commited on
Commit
f05ca8c
·
verified ·
1 Parent(s): e2b25ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -64,15 +64,23 @@ def process_video(video_path, target, progress=gr.Progress()):
64
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
65
  out = cv2.VideoWriter(output_path, fourcc, original_fps, (int(cap.get(3)), int(cap.get(4))))
66
 
 
 
 
67
  for frame in progress.tqdm(range(frame_count)):
68
  ret, img = cap.read()
69
  if not ret:
70
  break
71
 
72
  pil_img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
73
- annotated_img = detect_objects_in_frame(pil_img, target)
74
- annotated_frame = cv2.cvtColor(np.array(annotated_img), cv2.COLOR_RGB2BGR)
75
- out.write(annotated_frame)
 
 
 
 
 
76
 
77
  cap.release()
78
  out.release()
 
64
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
65
  out = cv2.VideoWriter(output_path, fourcc, original_fps, (int(cap.get(3)), int(cap.get(4))))
66
 
67
+ batch_size = 16
68
+ frames = []
69
+
70
  for frame in progress.tqdm(range(frame_count)):
71
  ret, img = cap.read()
72
  if not ret:
73
  break
74
 
75
  pil_img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
76
+ frames.append(pil_img)
77
+
78
+ if len(frames) == batch_size or frame == frame_count - 1:
79
+ annotated_frames = [detect_objects_in_frame(frame, target) for frame in frames]
80
+ for annotated_img in annotated_frames:
81
+ annotated_frame = cv2.cvtColor(np.array(annotated_img), cv2.COLOR_RGB2BGR)
82
+ out.write(annotated_frame)
83
+ frames = []
84
 
85
  cap.release()
86
  out.release()