Spaces:
Runtime error
Runtime error
Alexander Fengler
commited on
Commit
·
037f9a9
1
Parent(s):
dd3b198
still debuggine, commented a couple of things out but still runnning slow and failing
Browse files
app.py
CHANGED
@@ -65,26 +65,26 @@ def overlay_text_on_image(image, text_list, font=cv2.FONT_HERSHEY_SIMPLEX, font_
|
|
65 |
cv2.putText(image, line, (image.shape[1] - text_width - margin, y), font, font_size, color, font_thickness, lineType=cv2.LINE_AA)
|
66 |
return image
|
67 |
|
68 |
-
def draw_cockpit(frame, top_pred,cnt):
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
return frame
|
89 |
|
90 |
def process_video(input_video, out_fps = 'auto', skip_frames = 7):
|
@@ -109,29 +109,41 @@ def process_video(input_video, out_fps = 'auto', skip_frames = 7):
|
|
109 |
while iterating:
|
110 |
print(cnt)
|
111 |
if (cnt % skip_frames) == 0:
|
112 |
-
#
|
113 |
display_frame, result = inference_frame_serial(frame)
|
114 |
video.write(cv2.cvtColor(display_frame, cv2.COLOR_BGR2RGB))
|
|
|
115 |
#print(result)
|
|
|
116 |
top_pred = process_results_for_plot(predictions = result.numpy(),
|
117 |
classes = classes,
|
118 |
class_sizes = class_sizes_lower)
|
|
|
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 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
127 |
|
128 |
-
|
129 |
-
|
|
|
|
|
130 |
|
|
|
131 |
pred_dashbord = prediction_dashboard(top_pred = top_pred)
|
132 |
#print('sending frame')
|
|
|
133 |
print(cnt)
|
134 |
-
|
|
|
|
|
|
|
135 |
cnt += 1
|
136 |
iterating, frame = cap.read()
|
137 |
print('interating: ', iterating)
|
@@ -146,8 +158,8 @@ with gr.Blocks(theme=theme) as demo:
|
|
146 |
output_video = gr.Video(label="Output Video")
|
147 |
dashboard = gr.Image(label="Dashboard")
|
148 |
|
149 |
-
with gr.Row(height='
|
150 |
-
original_frames = gr.Image(label="Original Frame", width='
|
151 |
|
152 |
with gr.Row():
|
153 |
paths = sorted(pathlib.Path('videos_example/').rglob('*.mp4'))
|
|
|
65 |
cv2.putText(image, line, (image.shape[1] - text_width - margin, y), font, font_size, color, font_thickness, lineType=cv2.LINE_AA)
|
66 |
return image
|
67 |
|
68 |
+
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 |
+
|
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):
|
|
|
109 |
while iterating:
|
110 |
print(cnt)
|
111 |
if (cnt % skip_frames) == 0:
|
112 |
+
# Get inference results and output masks
|
113 |
display_frame, result = inference_frame_serial(frame)
|
114 |
video.write(cv2.cvtColor(display_frame, cv2.COLOR_BGR2RGB))
|
115 |
+
|
116 |
#print(result)
|
117 |
+
print('start top_pred')
|
118 |
top_pred = process_results_for_plot(predictions = result.numpy(),
|
119 |
classes = classes,
|
120 |
class_sizes = class_sizes_lower)
|
121 |
+
|
122 |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
123 |
prediction_frame = cv2.cvtColor(display_frame, cv2.COLOR_BGR2RGB)
|
124 |
|
125 |
frame = cv2.resize(frame, (int(width*4), int(height*4)))
|
126 |
|
127 |
+
# Only show the prediction frame every other frame
|
128 |
+
# print('first if')
|
129 |
+
# if ((cnt*skip_frames) % 2 == 0): # and top_pred['shark_sighted']:
|
130 |
+
# prediction_frame = cv2.resize(prediction_frame, (int(width*4), int(height*4)))
|
131 |
+
# frame = prediction_frame
|
132 |
|
133 |
+
# # Add cockpit to frame
|
134 |
+
# print('cockput if')
|
135 |
+
# if top_pred['shark_sighted']:
|
136 |
+
# frame = draw_cockpit(frame, top_pred, cnt*skip_frames)
|
137 |
|
138 |
+
print('dashboard')
|
139 |
pred_dashbord = prediction_dashboard(top_pred = top_pred)
|
140 |
#print('sending frame')
|
141 |
+
print('finished dashboard')
|
142 |
print(cnt)
|
143 |
+
# if cnt == 119:
|
144 |
+
# import ipdb; ipdb.set_trace()
|
145 |
+
|
146 |
+
yield prediction_frame, frame , None, pred_dashbord
|
147 |
cnt += 1
|
148 |
iterating, frame = cap.read()
|
149 |
print('interating: ', iterating)
|
|
|
158 |
output_video = gr.Video(label="Output Video")
|
159 |
dashboard = gr.Image(label="Dashboard")
|
160 |
|
161 |
+
with gr.Row(height='100%',width='100%'):
|
162 |
+
original_frames = gr.Image(label="Original Frame", width='100%', height='100%')
|
163 |
|
164 |
with gr.Row():
|
165 |
paths = sorted(pathlib.Path('videos_example/').rglob('*.mp4'))
|