MCPcopy Create free account
hub / github.com/OpenBMB/AgentCPM-GUI / _yx_in_bounding_boxes

Function _yx_in_bounding_boxes

eval/utils/action_utils.py:111–137  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

109
110
111def _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
140def _resize_annotation_bounding_boxes(

Callers 1

_check_tap_actions_matchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected