def test_pointcloud_bounding_box_3d(): points = np.array([[1.0, 2.0, 3.0], [3.0, 2.0, 1.0]]) pc = PointCloud(points) bb = pc.bounding_box() bb_bounds = bb.bounds() assert_allclose(bb_bounds[0], [1.0, 2.0, 1.0]) assert_allclose(bb_bounds[1], [3.0, 2.0, 3.0])
def test_pointcloud_bounding_box(): points = np.array([[0, 0], [1., 1], [0, 2]]) pc = PointCloud(points) bb = pc.bounding_box() bb_bounds = bb.bounds() assert_allclose(bb_bounds[0], [0., 0.]) assert_allclose(bb_bounds[1], [1., 2.])
def _preprocess(self, idx): name, *lms5pt = self.detection.loc[idx] lms5pt = PointCloud(np.array(lms5pt).reshape([-1,2])[:,::-1]) img = mio.import_image((self.image_path/name).with_suffix('.jpg')) cimg, _, _ = dm.utils.crop_image_bounding_box(img, lms5pt.bounding_box(), [112, 112], base=186) return cimg.pixels_with_channels_at_back() * 2 - 1
def _align_mean_shape_with_bbox(self, bbox): # Convert 3D landmarks to 2D by removing the Z axis template_shape = PointCloud(self.mm.landmarks.points[:, [1, 0]]) # Rotation that flips over x axis rot_matrix = np.eye(template_shape.n_dims) rot_matrix[0, 0] = -1 template_shape = Rotation(rot_matrix, skip_checks=True).apply(template_shape) # Align the 2D landmarks' bbox with the provided bbox return AlignmentSimilarity(template_shape.bounding_box(), bbox).apply(template_shape)
def test_pointcloud_bounding_box_3d_fail(): points = np.array([[0, 0, 0], [1, 1, 1]]) pc = PointCloud(points) pc.bounding_box()