当前位置: 首页>>代码示例>>Python>>正文


Python Translation.apply方法代码示例

本文整理汇总了Python中menpo.transform.Translation.apply方法的典型用法代码示例。如果您正苦于以下问题:Python Translation.apply方法的具体用法?Python Translation.apply怎么用?Python Translation.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在menpo.transform.Translation的用法示例。


在下文中一共展示了Translation.apply方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_align_2d_translation_set_h_matrix_raises_notimplemented_error

# 需要导入模块: from menpo.transform import Translation [as 别名]
# 或者: from menpo.transform.Translation import apply [as 别名]
def test_align_2d_translation_set_h_matrix_raises_notimplemented_error():
    t_vec = np.array([1, 2])
    translation = Translation(t_vec)
    source = PointCloud(np.array([[0, 1], [1, 1], [-1, -5], [3, -5]]))
    target = translation.apply(source)
    # estimate the transform from source to source..
    estimate = AlignmentTranslation(source, source)
    # and change the target.
    estimate.set_h_matrix(translation.h_matrix)
开发者ID:kritsong,项目名称:menpo,代码行数:11,代码来源:h_align_test.py

示例2: test_align_2d_translation

# 需要导入模块: from menpo.transform import Translation [as 别名]
# 或者: from menpo.transform.Translation import apply [as 别名]
def test_align_2d_translation():
    t_vec = np.array([1, 2])
    translation = Translation(t_vec)
    source = PointCloud(np.array([[0, 1], [1, 1], [-1, -5], [3, -5]]))
    target = translation.apply(source)
    # estimate the transform from source and target
    estimate = AlignmentTranslation(source, target)
    # check the estimates is correct
    assert_allclose(translation.h_matrix, estimate.h_matrix)
开发者ID:kritsong,项目名称:menpo,代码行数:11,代码来源:h_align_test.py

示例3: test_align_2d_translation_from_vector_inplace

# 需要导入模块: from menpo.transform import Translation [as 别名]
# 或者: from menpo.transform.Translation import apply [as 别名]
def test_align_2d_translation_from_vector_inplace():
    t_vec = np.array([1, 2])
    translation = Translation(t_vec)
    source = PointCloud(np.array([[0, 1], [1, 1], [-1, -5], [3, -5]]))
    target = translation.apply(source)
    # estimate the transform from source to source..
    estimate = AlignmentTranslation(source, source)
    # and update from_vector
    estimate.from_vector_inplace(t_vec)
    # check the estimates is correct
    assert_allclose(target.points, estimate.target.points)
开发者ID:kritsong,项目名称:menpo,代码行数:13,代码来源:h_align_test.py

示例4: chain_compose_before_tps_test

# 需要导入模块: from menpo.transform import Translation [as 别名]
# 或者: from menpo.transform.Translation import apply [as 别名]
def chain_compose_before_tps_test():
    a = PointCloud(np.random.random([10, 2]))
    b = PointCloud(np.random.random([10, 2]))
    tps = ThinPlateSplines(a, b)

    t = Translation([3, 4])
    s = Scale([4, 2])
    chain = TransformChain([t, s])
    chain_mod = chain.compose_before(tps)

    points = PointCloud(np.random.random([10, 2]))

    manual_res = tps.apply(s.apply(t.apply(points)))
    chain_res = chain_mod.apply(points)
    assert(np.all(manual_res.points == chain_res.points))
开发者ID:HaoyangWang,项目名称:menpo,代码行数:17,代码来源:compose_chain_test.py

示例5: test_align_2d_translation_from_vector

# 需要导入模块: from menpo.transform import Translation [as 别名]
# 或者: from menpo.transform.Translation import apply [as 别名]
def test_align_2d_translation_from_vector():
    t_vec = np.array([1, 2])
    translation = Translation(t_vec)
    source = PointCloud(np.array([[0, 1], [1, 1], [-1, -5], [3, -5]]))
    target = translation.apply(source)
    # estimate the transform from source to source..
    estimate = AlignmentTranslation(source, source)
    # and update from_vector
    new_est = estimate.from_vector(t_vec)
    # check the original is unchanged
    assert_allclose(estimate.source.points, source.points)
    assert_allclose(estimate.target.points, source.points)
    # check the new estimate has the source and target correct
    assert_allclose(new_est.source.points, source.points)
    assert_allclose(new_est.target.points, target.points)
开发者ID:kritsong,项目名称:menpo,代码行数:17,代码来源:h_align_test.py

示例6: test_translation

# 需要导入模块: from menpo.transform import Translation [as 别名]
# 或者: from menpo.transform.Translation import apply [as 别名]
def test_translation():
    t_vec = np.array([1, 2, 3])
    starting_vector = np.random.rand(10, 3)
    transform = Translation(t_vec)
    transformed = transform.apply(starting_vector)
    assert_allclose(starting_vector + t_vec, transformed)
开发者ID:AshwinRajendraprasad,项目名称:menpo,代码行数:8,代码来源:test_homogeneous.py

示例7: test_init_from_pointcloud_return_transform

# 需要导入模块: from menpo.transform import Translation [as 别名]
# 或者: from menpo.transform.Translation import apply [as 别名]
def test_init_from_pointcloud_return_transform():
    correct_tr = Translation([5, 5])
    pc = correct_tr.apply(PointCloud.init_2d_grid((10, 10)))
    im, tr = Image.init_from_pointcloud(pc, return_transform=True)
    assert im.shape == (9, 9)
    assert_allclose(tr.as_vector(), -correct_tr.as_vector())
开发者ID:JeanKossaifi,项目名称:menpo,代码行数:8,代码来源:image_basics_test.py

示例8: non_rigid_icp_generator

# 需要导入模块: from menpo.transform import Translation [as 别名]
# 或者: from menpo.transform.Translation import apply [as 别名]
def non_rigid_icp_generator(source, target, eps=1e-3,
                            stiffness_weights=None, data_weights=None,
                            landmark_group=None, landmark_weights=None,
                            v_i_update_func=None, verbose=False):
    r"""
    Deforms the source trimesh to align with to optimally the target.
    """
    # If landmarks are provided, we should always start with a simple
    # AlignmentSimilarity between the landmarks to initialize optimally.

    if landmark_group is not None:
        if verbose:
            print("'{}' landmarks will be used as "
                  "a landmark constraint.".format(landmark_group))
            print("performing similarity alignment using landmarks")
        lm_align = AlignmentSimilarity(source.landmarks[landmark_group],
                                       target.landmarks[landmark_group]).as_non_alignment()
        source = lm_align.apply(source)

    # Scale factors completely change the behavior of the algorithm - always
    # rescale the source down to a sensible size (so it fits inside box of
    # diagonal 1) and is centred on the origin. We'll undo this after the fit
    # so the user can use whatever scale they prefer.
    
    #tr = Translation(-1 * source.centre())
    #sc = UniformScale(1.0 / np.sqrt(np.sum(source.range() ** 2)), 3)
    
    #tr_t = Translation(-1 * target.centre())
    #sc_t = UniformScale(1.0 / np.sqrt(np.sum(target.range() ** 2)), 3) 
    
    #tr = Translation([0, 0, 0])
    #sc = UniformScale(1.0, 3)

    #prepare = tr.compose_before(sc)
    #prepare_t = tr_t.compose_before(sc_t)

    #source = prepare.apply(source)
    #target = prepare_t.apply(target)
    
    #m3io.export_mesh(source, '/data/tmp/source.obj', overwrite = True)
    #m3io.export_mesh(target, '/data/tmp/target.obj', overwrite = True)
    
    #t = AlignmentSimilarity(source.landmarks['LJSON'], target.landmarks['LJSON'])

    #source = t.apply(source)
    

    # store how to undo the similarity transform
    # restore = prepare.pseudoinverse()
    
    # restore source to target scale
    #restore = prepare_t.pseudoinverse()
    restore = Translation([0, 0, 0])

    n_dims = source.n_dims
    # Homogeneous dimension (1 extra for translation effects)
    h_dims = n_dims + 1
    points, trilist = source.points, source.trilist
    n = points.shape[0]  # record number of points

    # ========================================================================
    edge_tris = target.boundary_tri_index() # SOURCE???
    # ========================================================================

    M_s, unique_edge_pairs = node_arc_incidence_matrix(source)
    #print('M_s {}'.format(M_s.shape))

    # weight matrix
    G = np.identity(n_dims + 1)

    M_kron_G_s = sp.kron(M_s, G)
    #print('M_kron_G_s {}'.format(M_kron_G_s.shape))

    # build octree for finding closest points on target.
    target_vtk = trimesh_to_vtk(target)
    closest_points_on_target = VTKClosestPointLocator(target_vtk)

    # save out the target normals. We need them for the weight matrix.
    target_tri_normals = target.tri_normals()

    # init transformation
    X_prev = np.tile(np.zeros((n_dims, h_dims)), n).T
    v_i = points

    if stiffness_weights is not None:
        if verbose:
            print('using user-defined stiffness_weights')
        validate_weights('stiffness_weights', stiffness_weights,
                         source.n_points, verbose=verbose)
    else:
        # these values have been empirically found to perform well for well
        # rigidly aligned facial meshes
        stiffness_weights = [50, 20, 5, 2, 0.8, 0.5, 0.35, 0.2]
        if verbose:
            print('using default '
                  'stiffness_weights: {}'.format(stiffness_weights))

    n_iterations = len(stiffness_weights)

    if landmark_weights is not None:
#.........这里部分代码省略.........
开发者ID:HaoyangWang,项目名称:menpo3d,代码行数:103,代码来源:nicp.py


注:本文中的menpo.transform.Translation.apply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。