MCPcopy Create free account
hub / github.com/InternRobotics/EmbodiedScan / corners_nd

Function corners_nd

embodiedscan/structures/ops/box_np_ops.py:63–93  ·  view source on GitHub ↗

Generate relative box corners based on length per dim and origin point. Args: dims (np.ndarray, shape=[N, ndim]): Array of length per dim origin (list or array or float, optional): origin point relate to smallest point. Defaults to 0.5 Returns: np.ndarra

(dims, origin=0.5)

Source from the content-addressed store, hash-verified

61
62
63def corners_nd(dims, origin=0.5):
64 """Generate relative box corners based on length per dim and origin point.
65
66 Args:
67 dims (np.ndarray, shape=[N, ndim]): Array of length per dim
68 origin (list or array or float, optional): origin point relate to
69 smallest point. Defaults to 0.5
70
71 Returns:
72 np.ndarray, shape=[N, 2 ** ndim, ndim]: Returned corners.
73 point layout example: (2d) x0y0, x0y1, x1y0, x1y1;
74 (3d) x0y0z0, x0y0z1, x0y1z0, x0y1z1, x1y0z0, x1y0z1, x1y1z0, x1y1z1
75 where x0 < x1, y0 < y1, z0 < z1.
76 """
77 ndim = int(dims.shape[1])
78 corners_norm = np.stack(np.unravel_index(np.arange(2**ndim), [2] * ndim),
79 axis=1).astype(dims.dtype)
80 # now corners_norm has format: (2d) x0y0, x0y1, x1y0, x1y1
81 # (3d) x0y0z0, x0y0z1, x0y1z0, x0y1z1, x1y0z0, x1y0z1, x1y1z0, x1y1z1
82 # so need to convert to a format which is convenient to do other computing.
83 # for 2d boxes, format is clockwise start with minimum point
84 # for 3d boxes, please draw lines by your hand.
85 if ndim == 2:
86 # generate clockwise box corners
87 corners_norm = corners_norm[[0, 1, 3, 2]]
88 elif ndim == 3:
89 corners_norm = corners_norm[[0, 1, 3, 2, 4, 5, 7, 6]]
90 corners_norm = corners_norm - np.array(origin, dtype=dims.dtype)
91 corners = dims.reshape([-1, 1, ndim]) * corners_norm.reshape(
92 [1, 2**ndim, ndim])
93 return corners
94
95
96def center_to_corner_box2d(centers, dims, angles=None, origin=0.5):

Callers 2

center_to_corner_box2dFunction · 0.85
center_to_corner_box3dFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected