Skip to content

Instantly share code, notes, and snippets.

@susantabiswas
Created January 15, 2021 11:08
Show Gist options
  • Select an option

  • Save susantabiswas/d45785874cb3e7d4e470125c4952a8a5 to your computer and use it in GitHub Desktop.

Select an option

Save susantabiswas/d45785874cb3e7d4e470125c4952a8a5 to your computer and use it in GitHub Desktop.
Dlib rectangle conversion code
def dlib_rectangle_to_list(self, dlib_bbox):
"""Converts a dlib rectangle to
List(top left x, top left y, bottom right x, bottom right y)
Args:
dlib_bbox (dlib.rectangle):
Returns:
List[int]: Bounding box coordinates
"""
# Top left corner
x1, y1 = dlib_bbox.tl_corner().x, dlib_bbox.tl_corner().y
width, height = dlib_bbox.width(), dlib_bbox.height()
# Bottom right point
x2, y2 = x1 + width, y1 + height
return [x1, y1, x2, y2]
def convert_to_dlib_rectangle(bbox):
"""Converts a bounding box coordinate list
to dlib rectangle.
Args:
bbox (List[int]): Bounding box coordinates
Returns:
dlib.rectangle: Dlib rectangle
"""
return dlib.rectangle(bbox[0], bbox[1],
bbox[2], bbox[3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment