reab5555 commited on
Commit
4417183
·
verified ·
1 Parent(s): e4f7d8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -147,10 +147,18 @@ def create_heatmap(frame_scores, current_frame):
147
 
148
  return tmp_file.name
149
 
150
- def load_sample_frame(video_path):
151
  cap = cv2.VideoCapture(video_path)
152
  if not cap.isOpened():
153
  return None
 
 
 
 
 
 
 
 
154
  ret, frame = cap.read()
155
  cap.release()
156
  if not ret:
@@ -175,7 +183,7 @@ def gradio_app():
175
  heatmap_output = gr.Image(label="Detection Heatmap")
176
  output_image = gr.Image(label="Processed Frame")
177
  error_output = gr.Textbox(label="Error Messages", visible=False)
178
- sample_video_frame = gr.Image(value=load_sample_frame("Drone Video of African Wildlife Wild Botswan.mp4"), label="Drone Video of African Wildlife Wild Botswan by wildimagesonline.com - Sample Video Frame")
179
  use_sample_button = gr.Button("Use Sample Video")
180
  progress_bar = gr.Progress()
181
 
 
147
 
148
  return tmp_file.name
149
 
150
+ def load_sample_frame(video_path, frame_number=None):
151
  cap = cv2.VideoCapture(video_path)
152
  if not cap.isOpened():
153
  return None
154
+
155
+ total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
156
+
157
+ if frame_number is None or frame_number >= total_frames:
158
+ frame_number = total_frames // 2 # Default to middle frame
159
+
160
+ cap.set(cv2.CAP_PROP_POS_FRAMES, frame_number)
161
+
162
  ret, frame = cap.read()
163
  cap.release()
164
  if not ret:
 
183
  heatmap_output = gr.Image(label="Detection Heatmap")
184
  output_image = gr.Image(label="Processed Frame")
185
  error_output = gr.Textbox(label="Error Messages", visible=False)
186
+ sample_video_frame = gr.Image(value=load_sample_frame("Drone Video of African Wildlife Wild Botswan.mp4", 100), label="Drone Video of African Wildlife Wild Botswan by wildimagesonline.com - Sample Video Frame")
187
  use_sample_button = gr.Button("Use Sample Video")
188
  progress_bar = gr.Progress()
189