From 2c20b6479f3e8c05d14915dfec2169244143e4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Enbishdev?= Date: Sat, 6 Nov 2021 04:21:42 +0200 Subject: [PATCH 1/3] Fix "IndexError: invalid index to scalar variable" --- utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils.py b/utils.py index 2f99b06..3e0cb53 100644 --- a/utils.py +++ b/utils.py @@ -45,7 +45,7 @@ def get_outputs_names(net): # Get the names of the output layers, i.e. the layers with unconnected # outputs - return [layers_names[i[0] - 1] for i in net.getUnconnectedOutLayers()] + return [layers_names[i - 1] for i in net.getUnconnectedOutLayers()] # Draw the predicted bounding box @@ -94,7 +94,6 @@ def post_process(frame, outs, conf_threshold, nms_threshold): nms_threshold) for i in indices: - i = i[0] box = boxes[i] left = box[0] top = box[1] From f4328616c414de00d13897f3b42a26286852bfcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Enbishdev?= Date: Mon, 8 Nov 2021 03:47:53 +0200 Subject: [PATCH 2/3] Fix bounding box coordinates residing outside image --- utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index 3e0cb53..d8b52a4 100644 --- a/utils.py +++ b/utils.py @@ -83,8 +83,10 @@ def post_process(frame, outs, conf_threshold, nms_threshold): center_y = int(detection[1] * frame_height) width = int(detection[2] * frame_width) height = int(detection[3] * frame_height) - left = int(center_x - width / 2) - top = int(center_y - height / 2) + left = max(int(center_x - width / 2), 0) + top = max(int(center_y - height / 2), 0) + width = min(width, frame_width - left) + height = min(height, frame_height - top) confidences.append(float(confidence)) boxes.append([left, top, width, height]) From a61c0f201c088a3d53c62ba6350f7bcaea2bd89f Mon Sep 17 00:00:00 2001 From: nbishdev Date: Mon, 8 Nov 2021 14:27:27 +0200 Subject: [PATCH 3/3] Use a distinct color for every distinct face detected in a frame --- utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils.py b/utils.py index d8b52a4..63cee5b 100644 --- a/utils.py +++ b/utils.py @@ -51,7 +51,8 @@ def get_outputs_names(net): # Draw the predicted bounding box def draw_predict(frame, conf, left, top, right, bottom): # Draw a bounding box. - cv2.rectangle(frame, (left, top), (right, bottom), COLOR_YELLOW, 2) + colors = tuple(np.random.randint(1, 255, 3).tolist()) + cv2.rectangle(frame, (left, top), (right, bottom), colors, 2) text = '{:.2f}'.format(conf)