本文整理汇总了Python中menpo.shape.PointCloud类的典型用法代码示例。如果您正苦于以下问题:Python PointCloud类的具体用法?Python PointCloud怎么用?Python PointCloud使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PointCloud类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _recursive_procrustes
def _recursive_procrustes(self):
r"""
Recursively calculates a procrustes alignment.
"""
from menpo.shape import PointCloud
if self.n_iterations > self.max_iterations:
return False
av_aligned_source = sum(t.aligned_source.points for t in self.transforms) / self.n_sources
new_target = PointCloud(av_aligned_source)
# rescale the new_target to be the same size as the original about
# it's centre
rescale = UniformScale(self.initial_target_scale / new_target.norm(), self.n_dims)
centre = Translation(-new_target.centre)
rescale_about_centre = centre.compose_before(rescale).compose_before(centre.pseudoinverse)
rescale_about_centre.apply_inplace(new_target)
# check to see if we have converged yet
delta_target = np.linalg.norm(self.target.points - new_target.points)
if delta_target < 1e-6:
return True
else:
self.n_iterations += 1
for t in self.transforms:
t.set_target(new_target)
self.target = new_target
return self._recursive_procrustes()
示例2: test_pointcloud_bounding_box_3d
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])
示例3: test_pointcloud_centre
def test_pointcloud_centre():
points = np.array([[0, 0],
[1., 1],
[0, 2]])
pc = PointCloud(points)
c = pc.centre()
assert_allclose(c, [1. / 3., 1.])
示例4: sparse_target
def sparse_target(self):
r"""
The current sparse `menpo.shape.PointCloud` that this object produces.
:type: `menpo.shape.PointCloud`
"""
sparse_target = PointCloud(self.target.points[:self.n_landmarks])
return self._sparse_instance.from_vector(sparse_target.as_vector())
示例5: test_pointcloud_flatten_rebuild
def test_pointcloud_flatten_rebuild():
points = np.array([[1, 2, 3], [1, 1, 1]])
pc = PointCloud(points)
flattened = pc.as_vector()
new_pc = pc.from_vector(flattened)
assert np.all(new_pc.n_dims == pc.n_dims)
assert np.all(new_pc.n_points == pc.n_points)
assert np.all(pc.points == new_pc.points)
示例6: test_pointcloud_centre_of_bounds
def test_pointcloud_centre_of_bounds():
points = np.array([[0, 0],
[1., 1],
[0, 2]])
pc = PointCloud(points)
cb = pc.centre_of_bounds()
assert_allclose(cb, [0.5, 1.])
assert 1
示例7: test_pointcloud_bounding_box
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.])
示例8: test_pointcloud_copy_method
def test_pointcloud_copy_method():
points = np.array([[1, 2, 3], [1, 1, 1]])
landmarks = PointCloud(np.ones([3, 3]), copy=False)
p = PointCloud(points, copy=False)
p.landmarks["test"] = landmarks
p_copy = p.copy()
assert not is_same_array(p_copy.points, p.points)
assert not is_same_array(p_copy.landmarks["test"].lms.points, p.landmarks["test"].lms.points)
示例9: _parse_marker_size
def _parse_marker_size(marker_size, points):
if marker_size is None:
from menpo.shape import PointCloud
from scipy.spatial.distance import squareform
pc = PointCloud(points, copy=False)
if 1 < pc.n_points < 1000:
d = squareform(pc.distance_to(pc))
d.sort()
min_10pc = d[int(d.shape[0] / 10)]
marker_size = min_10pc / 5
else:
marker_size = 0.1
return marker_size
示例10: _align_mean_shape_with_bbox
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)
示例11: test_pointcloud_init_from_depth_image
def test_pointcloud_init_from_depth_image():
fake_z = np.random.uniform(size=(10, 10))
pc = PointCloud.init_from_depth_image(Image(fake_z))
assert pc.n_points == 100
assert pc.n_dims == 3
assert_allclose(pc.range()[:2], [9, 9])
assert pc.points[:, -1].max() <= 1.0
assert pc.points[:, -1].min() >= 0.0
示例12: test_constrain_landmarks_to_bounds
def test_constrain_landmarks_to_bounds():
im = Image.init_blank((10, 10))
im.landmarks['test'] = PointCloud.init_2d_grid((20, 20))
with warnings.catch_warnings():
warnings.simplefilter('ignore')
im.constrain_landmarks_to_bounds()
assert not im.has_landmarks_outside_bounds()
assert_allclose(im.landmarks['test'].lms.bounds(), im.bounds())
示例13: __init__
def __init__(self, points, tcoords, texture, trilist=None, copy=True):
super(TexturedTriMesh, self).__init__(points, trilist=trilist,
copy=copy)
self.tcoords = PointCloud(tcoords, copy=copy)
if not copy:
self.texture = texture
else:
self.texture = texture.copy()
示例14: _parse_marker_size
def _parse_marker_size(marker_size, points):
if marker_size is None:
from menpo.shape import PointCloud
pc = PointCloud(points, copy=False)
# This is the way that mayavi automatically computes the scale factor in
# case the user passes scale_factor = 'auto'. We use it for both the
# marker_size as well as the numbers_size.
xyz_min, xyz_max = pc.bounds()
x_min, y_min, z_min = xyz_min
x_max, y_max, z_max = xyz_max
distance = np.sqrt(((x_max - x_min) ** 2 +
(y_max - y_min) ** 2 +
(z_max - z_min) ** 2) /
(4 * pc.n_points ** 0.33))
if distance == 0:
marker_size = 1
else:
marker_size = 0.1 * distance
return marker_size
示例15: test_pointcloud_init_from_depth_image_masked
def test_pointcloud_init_from_depth_image_masked():
fake_z = np.random.uniform(size=(10, 10))
mask = np.zeros(fake_z.shape, dtype=np.bool)
mask[2:6, 2:6] = True
im = MaskedImage(fake_z, mask=mask)
pc = PointCloud.init_from_depth_image(im)
assert pc.n_points == 16
assert pc.n_dims == 3
assert_allclose(pc.range()[:2], [3, 3])
assert pc.points[:, -1].max() <= 1.0
assert pc.points[:, -1].min() >= 0.0