Last active
October 10, 2022 14:03
-
-
Save sukhitashvili/79d02a039c170f0bc623a6009e2a9ca0 to your computer and use it in GitHub Desktop.
Revisions
-
sukhitashvili revised this gist
Oct 10, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -19,5 +19,6 @@ def rescale_bounding_boxes(original_shape: tuple, new_shape: tuple, bounding_boxes[:, 1] *= scale_h bounding_boxes[:, 2] *= scale_w bounding_boxes[:, 3] *= scale_h bounding_boxes = np.clip(bounding_boxes, a_min=0, a_max=None) bounding_boxes = bounding_boxes.astype(np.uint32).tolist() return bounding_boxes -
sukhitashvili created this gist
Jun 13, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ import numpy as np def rescale_bounding_boxes(original_shape: tuple, new_shape: tuple, bounding_boxes: list) -> list: """ Rescales bounding box coords according to new image size :param original_shape: (W, H) :param new_shape: (W, H) :param bounding_boxes: [[x1, y1, x2, y2], ...] :return: scaled bbox coords """ original_w, original_h = original_shape new_w, new_h = new_shape bounding_boxes = np.array(bounding_boxes, dtype=np.float64) scale_h, scale_w = new_h / original_h, new_w / original_w bounding_boxes[:, 0] *= scale_w bounding_boxes[:, 1] *= scale_h bounding_boxes[:, 2] *= scale_w bounding_boxes[:, 3] *= scale_h bounding_boxes = bounding_boxes.astype(np.uint32).tolist() return bounding_boxes