Skip to content

Commit 19ddbe6

Browse files
Add backward compatibility for older opencv versions
1 parent 2833ce3 commit 19ddbe6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Diff for: yolo_opencv.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
def get_output_layers(net):
2525

2626
layer_names = net.getLayerNames()
27-
28-
output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]
27+
try:
28+
output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]
29+
except:
30+
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
2931

3032
return output_layers
3133

@@ -89,7 +91,12 @@ def draw_prediction(img, class_id, confidence, x, y, x_plus_w, y_plus_h):
8991
indices = cv2.dnn.NMSBoxes(boxes, confidences, conf_threshold, nms_threshold)
9092

9193
for i in indices:
92-
box = boxes[i]
94+
try:
95+
box = boxes[i]
96+
except:
97+
i = i[0]
98+
box = boxes[i]
99+
93100
x = box[0]
94101
y = box[1]
95102
w = box[2]

0 commit comments

Comments
 (0)