Check if the (y,x) point is contained in each bounding box. Args: yx: The (y, x) coordinate in pixels of the point. bounding_boxes: A 2D int array of shape (num_bboxes, 4), where each row represents a bounding box: (y_top_left, x_top_left, box_height, box
(
yx, bounding_boxes
)
| 109 | |
| 110 | |
| 111 | def _yx_in_bounding_boxes( |
| 112 | yx, bounding_boxes |
| 113 | ): |
| 114 | """Check if the (y,x) point is contained in each bounding box. |
| 115 | |
| 116 | Args: |
| 117 | yx: The (y, x) coordinate in pixels of the point. |
| 118 | bounding_boxes: A 2D int array of shape (num_bboxes, 4), where each row |
| 119 | represents a bounding box: (y_top_left, x_top_left, box_height, |
| 120 | box_width). Note: containment is inclusive of the bounding box edges. |
| 121 | |
| 122 | Returns: |
| 123 | is_inside: A 1D bool array where each element specifies if the point is |
| 124 | contained within the respective box. |
| 125 | """ |
| 126 | y, x = yx |
| 127 | |
| 128 | # `bounding_boxes` has shape (n_elements, 4); we extract each array along the |
| 129 | # last axis into shape (n_elements, 1), then squeeze unneeded dimension. |
| 130 | top, left, height, width = [ |
| 131 | jnp.squeeze(v, axis=-1) for v in jnp.split(bounding_boxes, 4, axis=-1) |
| 132 | ] |
| 133 | |
| 134 | # The y-axis is inverted for AndroidEnv, so bottom = top + height. |
| 135 | bottom, right = top + height, left + width |
| 136 | |
| 137 | return jnp.logical_and(y >= top, y <= bottom) & jnp.logical_and(x >= left, x <= right) |
| 138 | |
| 139 | |
| 140 | def _resize_annotation_bounding_boxes( |
no outgoing calls
no test coverage detected