cap_bounding_box_coordinates#
- Dataset.cap_bounding_box_coordinates() Self[source]#
Method to ensure the bounding box coordinates are inside the picture frame. Indeed, some dataset (like crowdhuman) do use outside of picture bounding box
- Returns:
New Dataset with bounding box capped so that X and Y coordinates are inside corresponding picture dimensions
Example
>>> from lours.utils.doc_utils import dummy_dataset >>> from lours.utils.testing import assert_bounding_boxes_well_formed >>> example = dummy_dataset(1, 1) >>> example.annotations.loc[0, "box_y_min"] = -0.5 >>> example.annotations.loc[0, "box_height"] = ( ... example.images["height"][0] + 1 ... ) >>> example Dataset object containing 1 image and 1 object Name : inside_else_memory Images root : such/serious Images : width height relative_path type split id 0 342 377 help/me.jpeg .jpeg train Annotations : image_id category_str category_id ... box_y_min box_width box_height id ... 0 0 interview 25 ... -0.5 306.509956 378.0 [1 rows x 8 columns] Label map : {15: 'step', 19: 'why', 25: 'interview'}
>>> assert_bounding_boxes_well_formed(example) Traceback (most recent call last): ... AssertionError: Assertion failed. Bounding boxes must have positive Y values. First occurrence at row 0 : image_id 0 category_str interview category_id 25 split train box_x_min 5.652451 box_y_min -0.5 box_width 306.509956 box_height 378.0 Name: 0, dtype: object
>>> example.cap_bounding_box_coordinates() Dataset object containing 1 image and 1 object Name : inside_else_memory Images root : such/serious Images : width height relative_path type split id 0 342 377 help/me.jpeg .jpeg train Annotations : image_id category_str category_id ... box_y_min box_width box_height id ... 0 0 interview 25 ... 0.0 306.509956 377.0 [1 rows x 8 columns] Label map : {15: 'step', 19: 'why', 25: 'interview'}