amosfang commited on
Commit
0abbec6
1 Parent(s): 52418c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -9
app.py CHANGED
@@ -11,7 +11,6 @@ import gradio as gr
11
  # from huggingface_hub import snapshot_download
12
  import os
13
  import cv2
14
- import time
15
 
16
 
17
  PATH_TO_LABELS = 'data/label_map.pbtxt'
@@ -41,7 +40,7 @@ def predict(image_np):
41
  category_index,
42
  use_normalized_coordinates=True,
43
  max_boxes_to_draw=200,
44
- min_score_thresh=.60,
45
  agnostic_mode=False,
46
  line_thickness=2
47
  )
@@ -53,6 +52,7 @@ def predict_on_video(video_in_filepath, video_out_filepath, detection_model, cat
53
  frame_h = int(video_reader.get(cv2.CAP_PROP_FRAME_HEIGHT))
54
  frame_w = int(video_reader.get(cv2.CAP_PROP_FRAME_WIDTH))
55
  fps = video_reader.get(cv2.CAP_PROP_FPS)
 
56
  video_writer = cv2.VideoWriter(
57
  video_out_filepath,
58
  cv2.VideoWriter_fourcc(*'mp4v'),
@@ -64,20 +64,14 @@ def predict_on_video(video_in_filepath, video_out_filepath, detection_model, cat
64
  if not ret:
65
  break # Break the loop if the video is finished
66
 
67
- start_time = time.time()
68
  processed_frame = predict(frame)
69
- end_time = time.time()
70
- processing_time = end_time - start_time
71
  processed_frame_np = np.array(processed_frame)
72
  video_writer.write(processed_frame_np)
73
 
74
- # Adjust the delay based on processing time
75
- delay_time = max(1, int((1 / fps - processing_time) * 1000))
76
- cv2.waitKey(delay_time)
77
  video_reader.release()
78
  video_writer.release()
79
  cv2.destroyAllWindows()
80
- cv2.waitKey(5)
81
 
82
  # Function to process a video
83
  def process_video(video_path):
 
11
  # from huggingface_hub import snapshot_download
12
  import os
13
  import cv2
 
14
 
15
 
16
  PATH_TO_LABELS = 'data/label_map.pbtxt'
 
40
  category_index,
41
  use_normalized_coordinates=True,
42
  max_boxes_to_draw=200,
43
+ min_score_thresh=.7,
44
  agnostic_mode=False,
45
  line_thickness=2
46
  )
 
52
  frame_h = int(video_reader.get(cv2.CAP_PROP_FRAME_HEIGHT))
53
  frame_w = int(video_reader.get(cv2.CAP_PROP_FRAME_WIDTH))
54
  fps = video_reader.get(cv2.CAP_PROP_FPS)
55
+
56
  video_writer = cv2.VideoWriter(
57
  video_out_filepath,
58
  cv2.VideoWriter_fourcc(*'mp4v'),
 
64
  if not ret:
65
  break # Break the loop if the video is finished
66
 
 
67
  processed_frame = predict(frame)
 
 
68
  processed_frame_np = np.array(processed_frame)
69
  video_writer.write(processed_frame_np)
70
 
 
 
 
71
  video_reader.release()
72
  video_writer.release()
73
  cv2.destroyAllWindows()
74
+ cv2.waitKey(1)
75
 
76
  # Function to process a video
77
  def process_video(video_path):