Skip to content

Commit 7efbe45

Browse files
authored
Update videotest.py
Check if collection is empty
1 parent b0223e3 commit 7efbe45

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

testing_utils/videotest.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -124,40 +124,41 @@ def run(self, video_path = 0, start_frame = 0, conf_thresh = 0.6):
124124
# way to avoid that?
125125
results = self.bbox_util.detection_out(y)
126126

127-
# Interpret output, only one frame is used
128-
det_label = results[0][:, 0]
129-
det_conf = results[0][:, 1]
130-
det_xmin = results[0][:, 2]
131-
det_ymin = results[0][:, 3]
132-
det_xmax = results[0][:, 4]
133-
det_ymax = results[0][:, 5]
134-
135-
top_indices = [i for i, conf in enumerate(det_conf) if conf >= conf_thresh]
136-
137-
top_conf = det_conf[top_indices]
138-
top_label_indices = det_label[top_indices].tolist()
139-
top_xmin = det_xmin[top_indices]
140-
top_ymin = det_ymin[top_indices]
141-
top_xmax = det_xmax[top_indices]
142-
top_ymax = det_ymax[top_indices]
143-
144-
for i in range(top_conf.shape[0]):
145-
xmin = int(round(top_xmin[i] * to_draw.shape[1]))
146-
ymin = int(round(top_ymin[i] * to_draw.shape[0]))
147-
xmax = int(round(top_xmax[i] * to_draw.shape[1]))
148-
ymax = int(round(top_ymax[i] * to_draw.shape[0]))
149-
150-
# Draw the box on top of the to_draw image
151-
class_num = int(top_label_indices[i])
152-
cv2.rectangle(to_draw, (xmin, ymin), (xmax, ymax),
153-
self.class_colors[class_num], 2)
154-
text = self.class_names[class_num] + " " + ('%.2f' % top_conf[i])
155-
156-
text_top = (xmin, ymin-10)
157-
text_bot = (xmin + 80, ymin + 5)
158-
text_pos = (xmin + 5, ymin)
159-
cv2.rectangle(to_draw, text_top, text_bot, self.class_colors[class_num], -1)
160-
cv2.putText(to_draw, text, text_pos, cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0,0,0), 1)
127+
if len(results) > 0 and len(results[0]) > 0:
128+
# Interpret output, only one frame is used
129+
det_label = results[0][:, 0]
130+
det_conf = results[0][:, 1]
131+
det_xmin = results[0][:, 2]
132+
det_ymin = results[0][:, 3]
133+
det_xmax = results[0][:, 4]
134+
det_ymax = results[0][:, 5]
135+
136+
top_indices = [i for i, conf in enumerate(det_conf) if conf >= conf_thresh]
137+
138+
top_conf = det_conf[top_indices]
139+
top_label_indices = det_label[top_indices].tolist()
140+
top_xmin = det_xmin[top_indices]
141+
top_ymin = det_ymin[top_indices]
142+
top_xmax = det_xmax[top_indices]
143+
top_ymax = det_ymax[top_indices]
144+
145+
for i in range(top_conf.shape[0]):
146+
xmin = int(round(top_xmin[i] * to_draw.shape[1]))
147+
ymin = int(round(top_ymin[i] * to_draw.shape[0]))
148+
xmax = int(round(top_xmax[i] * to_draw.shape[1]))
149+
ymax = int(round(top_ymax[i] * to_draw.shape[0]))
150+
151+
# Draw the box on top of the to_draw image
152+
class_num = int(top_label_indices[i])
153+
cv2.rectangle(to_draw, (xmin, ymin), (xmax, ymax),
154+
self.class_colors[class_num], 2)
155+
text = self.class_names[class_num] + " " + ('%.2f' % top_conf[i])
156+
157+
text_top = (xmin, ymin-10)
158+
text_bot = (xmin + 80, ymin + 5)
159+
text_pos = (xmin + 5, ymin)
160+
cv2.rectangle(to_draw, text_top, text_bot, self.class_colors[class_num], -1)
161+
cv2.putText(to_draw, text, text_pos, cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0,0,0), 1)
161162

162163
# Calculate FPS
163164
# This computes FPS for everything, not just the model's execution

0 commit comments

Comments
 (0)