From 922b1b416297c69007fed5298d8030833666223d Mon Sep 17 00:00:00 2001 From: ThanhNS Date: Tue, 12 Feb 2019 13:28:41 +0700 Subject: [PATCH] Redefine bounding boxes --- utils.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index 2895d72..2f99b06 100644 --- a/utils.py +++ b/utils.py @@ -101,8 +101,10 @@ def post_process(frame, outs, conf_threshold, nms_threshold): width = box[2] height = box[3] final_boxes.append(box) - draw_predict(frame, confidences[i], left, top, left + width, - top + height) + left, top, right, bottom = refined_box(left, top, width, height) + # draw_predict(frame, confidences[i], left, top, left + width, + # top + height) + draw_predict(frame, confidences[i], left, top, right, bottom) return final_boxes @@ -134,3 +136,18 @@ def elapsed(self): def fps(self): # compute the (approximate) frames per second return self._num_frames / self.elapsed() + +def refined_box(left, top, width, height): + right = left + width + bottom = top + height + + original_vert_height = bottom - top + top = int(top + original_vert_height * 0.15) + bottom = int(bottom - original_vert_height * 0.05) + + margin = ((bottom - top) - (right - left)) // 2 + left = left - margin if (bottom - top - right + left) % 2 == 0 else left - margin - 1 + + right = right + margin + + return left, top, right, bottom