tools/smpl_utils.py
def iterative_optimize_on_vertices(model,
                                   vertices,
                                   joints3D,
                                   vertices_prob=np.zeros(1),
                                   opt_cross=True,
                                   opt_trans=False,
                                   itr=5,
                                   viz=True):
    """Fit the model (iteratively) to the given set of 3D vertices + 3D joints
    :param model: initial SMPL model ===> is modified after optimization
    :param vertices: 3D vertex locations to fit [num_vertices x 3]
    :param joints3D: 3D joint locations to fit [16 x 3]
    :param vertices_prob: an optional confidence/probability score for each point
    :param opt_trans: boolean, if True optimizes only translation
    :param itr: how many iterations of correspondence computation/fitting
    """
    t0 = time()
    # kdtree for vertices to make closest point queries
    pt_tree = scipy.spatial.cKDTree(vertices, leafsize=15)
    print('==> Will run for %d iterations to fit to %d vertices:' % (itr, vertices.shape[0]))
    for i in range(itr):
        print('\n===> Iteration %d' % i)
        smpl_tree = scipy.spatial.cKDTree(model.r, leafsize=15)

        vertices_corr = np.zeros((model.r.shape[0], 3))
        weights_corr = np.zeros((model.r.shape[0]))
        count = 0
        for v in model.r:
            dd, ii = pt_tree.query(v, k=1)
            vertices_corr[count, :] = vertices[ii, :]
            if(vertices_prob.shape[0] == 1):
                weights_corr[count] = 1.0
            else:
                weights_corr[count] = vertices_prob[ii]
            count = count + 1

        if opt_cross:
            print('====> Correspondence from both directions.')
            weights_cross_corr = np.zeros(vertices.shape[0])
            indices_cross_corr = np.zeros(vertices.shape[0])
            count = 0
            for j in range(vertices.shape[0]):
                pt = [vertices[j][0], vertices[j][1], vertices[j][2]]
                dd, ii = smpl_tree.query(pt, k=1)
                indices_cross_corr[count] = ii
                if(vertices_prob.shape[0] == 1):
                    weights_cross_corr[count] = 1.0
                else:
                    weights_cross_corr[count] = vertices_prob[j]
                count = count + 1
            optimize_on_vertices(
                model=model,
                vertices=vertices_corr,
                joints3D=joints3D,
                weights_corr=weights_corr,
                vertices_cross_corr=vertices,
                indices_cross_corr=indices_cross_corr,
                weights_cross_corr=weights_cross_corr,
                opt_trans=opt_trans,
                viz=viz)
        else:
            print('====> Correspondence from one direction.')
            optimize_on_vertices(
                model=model,
                vertices=vertices_corr,
                joints3D=joints3D,
                weights_corr=weights_corr,
                opt_trans=opt_trans,
                viz=viz)

    print('\nElapsed beta & theta fitting (%d vertices)(%d joints): %.2f sec.'
          % (vertices.shape[0], joints3D.shape[0], (time() - t0)))
Fit the model (iteratively) to the given set of 3D vertices + 3D joints
    :param model: initial SMPL model ===> is modified after optimization
    :param vertices: 3D vertex locations to fit [num_vertices x 3]
    :param joints3D: 3D joint locations to fit [16 x 3]
    :param vertices_prob: an optional confidence/probability score for each point
    :param opt_trans: boolean, if True optimizes only translation
    :param itr: how many iterations of correspondence computation/fitting
    
Fit the model (iteratively) to the given set of 3D vertices + 3D joints
Fit the model ( iteratively ) to the given set of 3D vertices + 3D joints
def iterative_optimize_on_vertices(model,
                                   vertices,
                                   joints3D,
                                   vertices_prob=np.zeros(1),
                                   opt_cross=True,
                                   opt_trans=False,
                                   itr=5,
                                   viz=True):
    t0 = time()
    pt_tree = scipy.spatial.cKDTree(vertices, leafsize=15)
    print('==> Will run for %d iterations to fit to %d vertices:' % (itr, vertices.shape[0]))
    for i in range(itr):
        print('\n===> Iteration %d' % i)
        smpl_tree = scipy.spatial.cKDTree(model.r, leafsize=15)
        vertices_corr = np.zeros((model.r.shape[0], 3))
        weights_corr = np.zeros((model.r.shape[0]))
        count = 0
        for v in model.r:
            dd, ii = pt_tree.query(v, k=1)
            vertices_corr[count, :] = vertices[ii, :]
            if(vertices_prob.shape[0] == 1):
                weights_corr[count] = 1.0
            else:
                weights_corr[count] = vertices_prob[ii]
            count = count + 1
        if opt_cross:
            print('====> Correspondence from both directions.')
            weights_cross_corr = np.zeros(vertices.shape[0])
            indices_cross_corr = np.zeros(vertices.shape[0])
            count = 0
            for j in range(vertices.shape[0]):
                pt = [vertices[j][0], vertices[j][1], vertices[j][2]]
                dd, ii = smpl_tree.query(pt, k=1)
                indices_cross_corr[count] = ii
                if(vertices_prob.shape[0] == 1):
                    weights_cross_corr[count] = 1.0
                else:
                    weights_cross_corr[count] = vertices_prob[j]
                count = count + 1
            optimize_on_vertices(
                model=model,
                vertices=vertices_corr,
                joints3D=joints3D,
                weights_corr=weights_corr,
                vertices_cross_corr=vertices,
                indices_cross_corr=indices_cross_corr,
                weights_cross_corr=weights_cross_corr,
                opt_trans=opt_trans,
                viz=viz)
        else:
            print('====> Correspondence from one direction.')
            optimize_on_vertices(
                model=model,
                vertices=vertices_corr,
                joints3D=joints3D,
                weights_corr=weights_corr,
                opt_trans=opt_trans,
                viz=viz)
    print('\nElapsed beta & theta fitting (%d vertices)(%d joints): %.2f sec.'
          % (vertices.shape[0], joints3D.shape[0], (time() - t0)))
def iterative_optimize_on_vertices ( model , vertices , joints3D , vertices_prob = np . zeros ( 1 ) , opt_cross = True , opt_trans = False , itr = 5 , viz = True ) : t0 = time ( ) pt_tree = scipy . spatial . cKDTree ( vertices , leafsize = 15 ) print ( '==> Will run for %d iterations to fit to %d vertices:' % ( itr , vertices . shape [ 0 ] ) ) for i in range ( itr ) : print ( '\n===> Iteration %d' % i ) smpl_tree = scipy . spatial . cKDTree ( model . r , leafsize = 15 ) vertices_corr = np . zeros ( ( model . r . shape [ 0 ] , 3 ) ) weights_corr = np . zeros ( ( model . r . shape [ 0 ] ) ) count = 0 for v in model . r : dd , ii = pt_tree . query ( v , k = 1 ) vertices_corr [ count , : ] = vertices [ ii , : ] if ( vertices_prob . shape [ 0 ] == 1 ) : weights_corr [ count ] = 1.0 else : weights_corr [ count ] = vertices_prob [ ii ] count = count + 1 if opt_cross : print ( '====> Correspondence from both directions.' ) weights_cross_corr = np . zeros ( vertices . shape [ 0 ] ) indices_cross_corr = np . zeros ( vertices . shape [ 0 ] ) count = 0 for j in range ( vertices . shape [ 0 ] ) : pt = [ vertices [ j ] [ 0 ] , vertices [ j ] [ 1 ] , vertices [ j ] [ 2 ] ] dd , ii = smpl_tree . query ( pt , k = 1 ) indices_cross_corr [ count ] = ii if ( vertices_prob . shape [ 0 ] == 1 ) : weights_cross_corr [ count ] = 1.0 else : weights_cross_corr [ count ] = vertices_prob [ j ] count = count + 1 optimize_on_vertices ( model = model , vertices = vertices_corr , joints3D = joints3D , weights_corr = weights_corr , vertices_cross_corr = vertices , indices_cross_corr = indices_cross_corr , weights_cross_corr = weights_cross_corr , opt_trans = opt_trans , viz = viz ) else : print ( '====> Correspondence from one direction.' ) optimize_on_vertices ( model = model , vertices = vertices_corr , joints3D = joints3D , weights_corr = weights_corr , opt_trans = opt_trans , viz = viz ) print ( '\nElapsed beta & theta fitting (%d vertices)(%d joints): %.2f sec.' % ( vertices . shape [ 0 ] , joints3D . shape [ 0 ] , ( time ( ) - t0 ) ) )
Fit the model (iteratively) to the given set of 3D vertices + 3D joints
Fit the model ( iteratively ) to the given set of 3D vertices + 3D joints
"""Fit the model (iteratively) to the given set of 3D vertices + 3D joints
    :param model: initial SMPL model ===> is modified after optimization
    :param vertices: 3D vertex locations to fit [num_vertices x 3]
    :param joints3D: 3D joint locations to fit [16 x 3]
    :param vertices_prob: an optional confidence/probability score for each point
    :param opt_trans: boolean, if True optimizes only translation
    :param itr: how many iterations of correspondence computation/fitting
    """ # kdtree for vertices to make closest point queries
model
initial SMPL model ===> is modified after optimization
initial SMPL model === > is modified after optimization
vertices
3D vertex locations to fit [num_vertices x 3]
3D vertex locations to fit [ num_vertices x 3 ]
joints3D
3D joint locations to fit [16 x 3]
3D joint locations to fit [ 16 x 3 ]
vertices_prob
an optional confidence/probability score for each point
an optional confidence / probability score for each point
opt_cross
opt_trans
boolean, if True optimizes only translation
boolean if True optimizes only translation
itr
None
viz