Skip to content

Commit

Permalink
Redefine bounding boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
sthanhng committed Feb 12, 2019
1 parent 026930a commit 922b1b4
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

0 comments on commit 922b1b4

Please sign in to comment.