Created
January 15, 2021 11:08
-
-
Save susantabiswas/d45785874cb3e7d4e470125c4952a8a5 to your computer and use it in GitHub Desktop.
Dlib rectangle conversion code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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