freddyaboulton HF staff commited on
Commit
b7278d2
1 Parent(s): 61732db
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -17,7 +17,7 @@ model = RTDetrForObjectDetection.from_pretrained("PekingU/rtdetr_r50vd")
17
  def stream_object_detection(video, conf_threshold):
18
  cap = cv2.VideoCapture(video)
19
 
20
- video_codec = cv2.VideoWriter_fourcc(*"x264") # type: ignore
21
  fps = int(cap.get(cv2.CAP_PROP_FPS))
22
  desired_fps = fps // 5
23
  width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
@@ -28,11 +28,12 @@ def stream_object_detection(video, conf_threshold):
28
  n_frames = 0
29
  n_chunks = 0
30
 
31
- name = f"output_{n_chunks}.ts"
32
- segment_file = cv2.VideoWriter(name, video_codec, fps, (width, height)) # type: ignore
33
  batch = []
34
 
35
  while iterating:
 
36
  frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
37
  if n_frames % 5 == 0:
38
  batch.append(frame)
@@ -62,7 +63,7 @@ def stream_object_detection(video, conf_threshold):
62
  n_frames = 0
63
  n_chunks += 1
64
  yield name
65
- name = f"output_{n_chunks}.ts"
66
  segment_file = cv2.VideoWriter(name, video_codec, fps, (width, height)) # type: ignore
67
 
68
  iterating, frame = cap.read()
@@ -91,7 +92,7 @@ with gr.Blocks(css=css) as app:
91
  """)
92
  with gr.Column(elem_classes=["my-column"]):
93
  with gr.Group(elem_classes=["my-group"]):
94
- video = gr.Video(label="Video Source", streaming=True, autoplay=True)
95
  conf_threshold = gr.Slider(
96
  label="Confidence Threshold",
97
  minimum=0.0,
 
17
  def stream_object_detection(video, conf_threshold):
18
  cap = cv2.VideoCapture(video)
19
 
20
+ video_codec = cv2.VideoWriter_fourcc(*"mp4v") # type: ignore
21
  fps = int(cap.get(cv2.CAP_PROP_FPS))
22
  desired_fps = fps // 5
23
  width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
 
28
  n_frames = 0
29
  n_chunks = 0
30
 
31
+ name = f"output_{n_chunks}.mp4"
32
+ segment_file = cv2.VideoWriter(name, video_codec, desired_fps, (width // 2, height // 2)) # type: ignore
33
  batch = []
34
 
35
  while iterating:
36
+ frame = cv2.resize( frame, (0,0), fx=0.5, fy=0.5)
37
  frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
38
  if n_frames % 5 == 0:
39
  batch.append(frame)
 
63
  n_frames = 0
64
  n_chunks += 1
65
  yield name
66
+ name = f"output_{n_chunks}.mp4"
67
  segment_file = cv2.VideoWriter(name, video_codec, fps, (width, height)) # type: ignore
68
 
69
  iterating, frame = cap.read()
 
92
  """)
93
  with gr.Column(elem_classes=["my-column"]):
94
  with gr.Group(elem_classes=["my-group"]):
95
+ video = gr.Video(label="Video Source", streaming=True)
96
  conf_threshold = gr.Slider(
97
  label="Confidence Threshold",
98
  minimum=0.0,