Alexander Fengler commited on
Commit
dd3b198
·
1 Parent(s): b3cb6e3

some simplifications;

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -69,27 +69,24 @@ def draw_cockpit(frame, top_pred,cnt):
69
  # Bullet points:
70
  high_danger_color = (255,0,0)
71
  low_danger_color = yellowgreen = (154,205,50)
 
72
  shark_sighted = 'Shark Detected: ' + str(top_pred['shark_sighted'])
73
  human_sighted = 'Number of Humans: ' + str(top_pred['human_n'])
74
  shark_size_estimate = 'Biggest shark size: ' + str(top_pred['biggest_shark_size'])
75
  shark_weight_estimate = 'Biggest shark weight: ' + str(top_pred['biggest_shark_weight'])
76
  danger_level = 'Danger Level: '
77
  danger_level += 'High' if top_pred['dangerous_dist'] else 'Low'
78
- danger_color = 'orangered' if top_pred['dangerous_dist'] else 'yellowgreen'
79
- # Create a list of strings to plot
 
80
  strings = [shark_sighted, human_sighted, shark_size_estimate, shark_weight_estimate, danger_level]
81
  relative = max(frame.shape[0],frame.shape[1])
82
- if top_pred['shark_sighted'] and top_pred['dangerous_dist'] and cnt%2 == 0:
83
  relative = max(frame.shape[0],frame.shape[1])
84
- frame = add_border(frame, color=high_danger_color, thickness=int(relative*0.025))
85
- elif top_pred['shark_sighted'] and not top_pred['dangerous_dist'] and cnt%2 == 0:
86
- relative = max(frame.shape[0],frame.shape[1])
87
- frame = add_border(frame, color=low_danger_color, thickness=int(relative*0.025))
88
- overlay_text_on_image(frame, strings, font=cv2.FONT_HERSHEY_SIMPLEX, font_size=1.5, font_thickness=3, margin=int(relative*0.05), color=(255, 255, 255))
89
  return frame
90
 
91
-
92
-
93
  def process_video(input_video, out_fps = 'auto', skip_frames = 7):
94
  cap = cv2.VideoCapture(input_video)
95
 
@@ -110,6 +107,7 @@ def process_video(input_video, out_fps = 'auto', skip_frames = 7):
110
  cnt = 0
111
 
112
  while iterating:
 
113
  if (cnt % skip_frames) == 0:
114
  # flip frame vertically
115
  display_frame, result = inference_frame_serial(frame)
@@ -121,12 +119,11 @@ def process_video(input_video, out_fps = 'auto', skip_frames = 7):
121
  frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
122
  prediction_frame = cv2.cvtColor(display_frame, cv2.COLOR_BGR2RGB)
123
 
124
-
125
  frame = cv2.resize(frame, (int(width*4), int(height*4)))
126
 
127
- if cnt*skip_frames %2==0 and top_pred['shark_sighted']:
128
  prediction_frame = cv2.resize(prediction_frame, (int(width*4), int(height*4)))
129
- frame =prediction_frame
130
 
131
  if top_pred['shark_sighted']:
132
  frame = draw_cockpit(frame, top_pred,cnt*skip_frames)
@@ -137,6 +134,7 @@ def process_video(input_video, out_fps = 'auto', skip_frames = 7):
137
  yield prediction_frame,frame , None, pred_dashbord
138
  cnt += 1
139
  iterating, frame = cap.read()
 
140
 
141
  video.release()
142
  yield None, None, output_path, None
 
69
  # Bullet points:
70
  high_danger_color = (255,0,0)
71
  low_danger_color = yellowgreen = (154,205,50)
72
+
73
  shark_sighted = 'Shark Detected: ' + str(top_pred['shark_sighted'])
74
  human_sighted = 'Number of Humans: ' + str(top_pred['human_n'])
75
  shark_size_estimate = 'Biggest shark size: ' + str(top_pred['biggest_shark_size'])
76
  shark_weight_estimate = 'Biggest shark weight: ' + str(top_pred['biggest_shark_weight'])
77
  danger_level = 'Danger Level: '
78
  danger_level += 'High' if top_pred['dangerous_dist'] else 'Low'
79
+ danger_color = high_danger_color if top_pred['dangerous_dist'] else low_danger_color # 'orangered' for high danger , 'yellowgreen' for low danger'
80
+
81
+ # Create a list of strings to plot
82
  strings = [shark_sighted, human_sighted, shark_size_estimate, shark_weight_estimate, danger_level]
83
  relative = max(frame.shape[0],frame.shape[1])
84
+ if top_pred['shark_sighted'] and (cnt % 2) == 0:
85
  relative = max(frame.shape[0],frame.shape[1])
86
+ frame = add_border(frame, color=danger_color, thickness=int(relative*0.025))
87
+ frame = overlay_text_on_image(frame, strings, font=cv2.FONT_HERSHEY_SIMPLEX, font_size=1.5, font_thickness=3, margin=int(relative*0.05), color=(255, 255, 255))
 
 
 
88
  return frame
89
 
 
 
90
  def process_video(input_video, out_fps = 'auto', skip_frames = 7):
91
  cap = cv2.VideoCapture(input_video)
92
 
 
107
  cnt = 0
108
 
109
  while iterating:
110
+ print(cnt)
111
  if (cnt % skip_frames) == 0:
112
  # flip frame vertically
113
  display_frame, result = inference_frame_serial(frame)
 
119
  frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
120
  prediction_frame = cv2.cvtColor(display_frame, cv2.COLOR_BGR2RGB)
121
 
 
122
  frame = cv2.resize(frame, (int(width*4), int(height*4)))
123
 
124
+ if ((cnt*skip_frames) % 2==0): # and top_pred['shark_sighted']:
125
  prediction_frame = cv2.resize(prediction_frame, (int(width*4), int(height*4)))
126
+ frame = prediction_frame
127
 
128
  if top_pred['shark_sighted']:
129
  frame = draw_cockpit(frame, top_pred,cnt*skip_frames)
 
134
  yield prediction_frame,frame , None, pred_dashbord
135
  cnt += 1
136
  iterating, frame = cap.read()
137
+ print('interating: ', iterating)
138
 
139
  video.release()
140
  yield None, None, output_path, None