def main_fit_single_projections(): # use '0b' for initial geometry V = load_projection('0b')[0] T = load_triangles() lambdas = np.array( [ 1.0, # as-rigid-as-possible 1.0 ], # projection dtype=np.float64) for index, user_constraints in INPUT_SELECTION: print 'index:', index _, C, P = load_projection(user_constraints) V1 = V.copy() X = np.zeros_like(V) status, status_string = solve_single_arap_proj(V, T, X, V1, C, P, lambdas) # visualise ? if False: vis = visualise.VisualiseMesh(V1, T) vis.execute() np.savez_compressed(os.path.join( OUTPUT_ROOT, 'chihuahua_single_projection_%s.npz' % user_constraints), V1=V1, X=X, lambdas=lambdas)
def main_test_shortest_path(): _, T, C, P = load_model_3() # requires output from `main_test_problem` under run_test_problem.py z = np.load('MAIN_TEST_PROBLEM.npz') V = z['V1'].copy() lambdas = np.array([1e-3, 1e1, 1e3], dtype=np.float64) silhouette = load_silhouette_information() path = test_shortest_path(V, T, isCircular=True, lambdas=lambdas, **silhouette) # convert ALL candidates to 3D positions SilCandAssignedFaces = silhouette['SilCandAssignedFaces'] SilCandU = silhouette['SilCandU'] S = silhouette['S'] SN = silhouette['SN'] Q = np.empty((SilCandAssignedFaces.shape[0], 3), dtype=np.float64) for i, face_index in enumerate(SilCandAssignedFaces): Q[i] = bary2pos(V[T[face_index]], make_bary(SilCandU[i])) # get assigned faces L = SilCandAssignedFaces[path] U = SilCandU[path] np.savez_compressed('MAIN_TEST_SHORTEST_PATH.npz', L=L, U=U, S=S, SN=SN) vis = visualise.VisualiseMesh(V, T, L) vis.add_image('Frames/0.png') vis.add_silhouette(Q, path, [0, S.shape[0] - 1], S) vis.execute()
def main_test_problem2(): _, T, C, P = load_model_3() z = np.load('MAIN_TEST_PROBLEM.npz') V = z['V1'].copy() lambdas = np.array([1e+0, 1e+2], dtype=np.float64) status = test_problem2(V, T, C, P, lambdas, gradientThreshold=1e-6, maxIterations=5) vis = visualise.VisualiseMesh(V, T) vis.add_projection(C, P) vis.add_image('Frames/0.png') vis.execute()
def main_test_problem(): V, T, C, P = load_model_3() V1 = V.copy() X = np.zeros_like(V) lambdas = np.array([1e+0, 1e+2], dtype=np.float64) status = test_problem(V, T, X, V1, C, P, lambdas, gradientThreshold=1e-6, maxIterations=200) print 'Status:', status vis = visualise.VisualiseMesh(V1, T) vis.add_projection(C, P) vis.add_image('Frames/0.png') vis.execute() np.savez_compressed('MAIN_TEST_PROBLEM.npz', V1=V1)
def main_test_problem3(): _, T, C, P = load_model_3() z = np.load('MAIN_TEST_PROBLEM.npz') V = z['V1'].copy() z = np.load('MAIN_TEST_SHORTEST_PATH.npz') S = z['S'] SN = z['SN'] U = z['U'] L = z['L'] lambdas = np.array([1e1, 1e1, 1e3], dtype=np.float64) preconditioners = np.array([1.0, 200.0], dtype=np.float64) narrow_band = 2 kwargs = dict(gradientThreshold=1e-6, maxIterations=30, verbosenessLevel=1) # solve t1 = clock() status, status_string = test_problem3(V, T, U, L, S, SN, lambdas, preconditioners, narrow_band, **kwargs) # restart if out of the narrow band while status == 4: status, status_string = test_problem3(V, T, U, L, S, SN, lambdas, preconditioners, narrow_band, **kwargs) t2 = clock() print 'Time taken: %.3fs' % (t2 - t1) Q = np.empty((U.shape[0], 3), dtype=np.float64) for i, face_index in enumerate(L): Q[i] = bary2pos(V[T[face_index]], make_bary(U[i])) print 'Status (%d):' % status, status_string vis = visualise.VisualiseMesh(V, T, L) vis.add_image('Frames/0.png') vis.add_silhouette(Q, np.arange(Q.shape[0]), [0, S.shape[0] - 1], S) vis.execute()
def main_fit_joint_lap_silhouette(): # use '0b' for initial core geometry V = load_projection('0b')[0] T = load_triangles() # information for silhouette specific only to the model (approx) silhouette_info = load_silhouette_info() # weighting lambdas global_solve_lambdas = np.array( [ 1e-3, # geodesic between preimage 1e0, # silhouette projection 1e3 ], # silhouette normal dtype=np.float64) lm_lambdas = np.asarray( np.r_[1.0, # as-rigid-as-possible global_solve_lambdas[1:], 1.0, # spillage 1e1], # laplacian dtype=np.float64) # preconditioning for the joint minimisation lm_preconditioners = np.array([1.0, 1.0, 100.0], dtype=np.float64) # other solver options solver_options = dict(narrowBand=2, uniformWeights=True, maxIterations=20, gradientThreshold=1e-5, updateThreshold=1e-5, improvementThreshold=1e-5, verbosenessLevel=1) # construct lists for minimisation (multiX, multiV, multiU, multiL, multiS, multiSN, multiRx, multiRy) = [list() for i in range(8)] for index, user_constraints in INPUT_SELECTION: print 'index:', index # load geometry from initial projection z = np.load( os.path.join( OUTPUT_ROOT, 'chihuahua_single_projection_%s.npz' % user_constraints)) X = z['X'] V1 = z['V1'] # get the silhouette information for the frame S, SN = load_silhouette(index) # get the spillage information for the frame Rx, Ry = load_spillage(index) # solve for the initial silhouette positions U, L = shortest_path_solve(V1, T, S, SN, lambdas=global_solve_lambdas, isCircular=False, **silhouette_info) multiX.append(X) multiV.append(V1) multiU.append(U) multiL.append(L) multiS.append(S) multiSN.append(SN) multiRx.append(Rx) multiRy.append(Ry) # solve_iteration def solve_iteration(): status = solve_multiview_lap_silhouette(T, V, multiX, multiV, multiU, multiL, multiS, multiSN, multiRx, multiRy, lm_lambdas, lm_preconditioners, **solver_options) print 'LM Status (%d): ' % status[0], status[1] return status # solve t1 = clock() count = 0 status = solve_iteration() while status[0] in (0, 4): status = solve_iteration() count += 1 t2 = clock() print 'Time taken: %.3fs' % (t2 - t1) np.savez_compressed(os.path.join(OUTPUT_ROOT, 'chihuahua_lap_silhouette.npz'), T=T, V=V, multiV=multiV, multiS=multiS, multiSN=multiSN, lm_lambdas=lm_lambdas, lm_preconditioners=lm_preconditioners, solver_options=solver_options) # visualise ? if True: vis = visualise.VisualiseMesh(V, T) vis.execute() for i in xrange(len(multiV)): V1 = multiV[i] U = multiU[i] L = multiL[i] Q = geometry.path2pos(V1, T, L, U) N = Q.shape[0] vis = visualise.VisualiseMesh(V1, T, L) vis.add_silhouette(Q, np.arange(N), [0, N - 1], multiS[i]) vis.add_image(get_frame_path(INPUT_SELECTION[i][0])) vis.execute()
def main_fit_joint_arap_silhouette(): # use '0b' for initial core geometry V = load_projection('0b')[0] T = load_triangles() # information for silhouette specific only to the model (approx) silhouette_info = load_silhouette_info() global_solve_lambdas = np.array( [ 1e-3, # geodesic between preimage 1e0, # silhouette projection 1e3 ], # silhouette normal dtype=np.float64) lm_lambdas = np.asarray( np.r_[1.0, # as-rigid-as-possible global_solve_lambdas[1:]], dtype=np.float64) lm_preconditioners = np.array([1.0, 1.0, 100.0], dtype=np.float64) # construct lists for minimisation multiX, multiV, multiU, multiL, multiS, multiSN = [ list() for i in range(6) ] for index, user_constraints in INPUT_SELECTION: print 'index:', index # load geometry from initial projection z = np.load( os.path.join( OUTPUT_ROOT, 'chihuahua_single_projection_%s.npz' % user_constraints)) X = z['X'] V1 = z['V1'] # get the silhouette information for the frame S, SN = load_silhouette(index) # solve for the initial silhouette positions U, L = shortest_path_solve(V1, T, S, SN, lambdas=global_solve_lambdas, isCircular=False, **silhouette_info) multiX.append(X) multiV.append(V1) multiU.append(U) multiL.append(L) multiS.append(S) multiSN.append(SN) # solve_iteration def solve_iteration(): status = solve_multiview_arap_silhouette(T, V, multiX, multiV, multiU, multiL, multiS, multiSN, lm_lambdas, lm_preconditioners, narrowBand=2, maxIterations=50, gradientThreshold=1e-6, updateThreshold=1e-6, improvementThreshold=1e-6) print 'LM Status (%d): ' % status[0], status[1] return status solve_iteration() # visualise ? if True: vis = visualise.VisualiseMesh(V, T) vis.execute() for i in xrange(len(multiV)): V1 = multiV[i] U = multiU[i] L = multiL[i] Q = geometry.path2pos(V1, T, L, U) N = Q.shape[0] vis = visualise.VisualiseMesh(V1, T, L) vis.add_silhouette(Q, np.arange(N), [0, N - 1], multiS[i]) vis.add_image(get_frame_path(INPUT_SELECTION[i][0])) vis.execute()
def main_fit_single_silhouette(): # use '0b' for initial core geometry V = load_projection('0b')[0] T = load_triangles() # information for silhouette specific only to the model (approx) silhouette_info = load_silhouette_info() global_solve_lambdas = np.array( [ 1e-3, # geodesic between preimage 1e0, # silhouette projection 1e3 ], # silhouette normal dtype=np.float64) lm_lambdas = np.r_[2.0, # laplacian regularisation global_solve_lambdas[1:], # silhouette 1.0] # spillage lm_lambdas = np.asarray(lm_lambdas, dtype=np.float64) lm_preconditioners = np.array([1.0, 5.0], dtype=np.float64) for i, (index, user_constraints) in enumerate(INPUT_SELECTION): if i > 0: break print 'index:', index # load geometry from initial projection z = np.load( os.path.join( OUTPUT_ROOT, 'chihuahua_single_projection_%s.npz' % user_constraints)) V = z['V1'] # get the silhouette information for the frame S, SN = load_silhouette(index) # get the spillage information for the frame Rx, Ry = load_spillage(index) # solve for the initial silhouette positions U, L = shortest_path_solve(V, T, S, SN, lambdas=global_solve_lambdas, isCircular=False, **silhouette_info) # fit under laplacian def solve_iteration(): status = solve_single_lap_silhouette( V, T, U, L, S, SN, Rx, Ry, lm_lambdas, lm_preconditioners, narrowBand=3, maxIterations=20, gradientThreshold=1e-5, updateThreshold=1e-5, improvementThreshold=1e-5, ) print 'LM Status (%d): ' % status[0], status[1] return status status = solve_iteration() while status[0] in (0, 4): status = solve_iteration() print 'Final Status (%d): ' % status[0], status[1] # visualise ? if True: Q = geometry.path2pos(V, T, L, U) N = Q.shape[0] vis = visualise.VisualiseMesh(V, T, L) vis.add_silhouette(Q, np.arange(N), [0, N - 1], S) vis.add_image(get_frame_path(index)) vis.execute()
def main(): T = wsp.load_triangles() #V, C, P = wsp.load_projection('0f') V, C, P = wsp.load_projection('0b') single_arap_lambdas = np.array( [ 1.0, # as-rigid-as-possible 1e1 ], # projection dtype=np.float64) # solve for projection X = np.zeros_like(V) V1 = V.copy() print 'solve_single_arap_proj' status = solve_single_arap_proj(V, T, X, V1, C, P, single_arap_lambdas, maxIterations=20, gradientThreshold=1e-6, updateThreshold=1e-6, improvementThreshold=1e-6) print 'Status (%d): ' % status[0], status[1] # show vis = visualise.VisualiseMesh(V1, T) vis.add_image(wsp.get_frame_path(0)) vis.add_projection(C, P) vis.execute() # solve for Laplacian global_sil_lambdas = np.array( [ 1e0, # geodesic between preimage points 1e0, # silhouette projection 1e3 ], # silhouette normal dtype=np.float64) #lm_lambdas = np.r_[1e1, 0.0, global_sil_lambdas[1:]] lm_lambdas = np.r_[1e1, global_sil_lambdas[1:]] lm_lambdas = np.asarray(lm_lambdas, dtype=np.float64) print 'lm_lambdas:', lm_lambdas lm_preconditioners = np.array([1.0, 100.0], dtype=np.float64) print 'lm_preconditioners :', lm_preconditioners # use as initialisation for next stage V = V1.copy() # solve for silhouette silhouette_info = wsp.load_silhouette_info() S, SN = wsp.get_silhouette(0) print 'shortest_path_solve' U, L = shortest_path_solve(V, T, S, SN, lambdas=global_sil_lambdas, isCircular=True, **silhouette_info) # show vis = visualise.VisualiseMesh(V, T, L) vis.add_image(wsp.get_frame_path(0)) Q = geometry.path2pos(V, T, L, U) N = Q.shape[0] vis.add_silhouette(Q, np.arange(N), [0, N - 1], S) vis.add_projection(C, P) vis.execute() # fit under laplacian def solve_iteration(): status = solve_single_lap_silhouette( V, T, U, L, S, SN, lm_lambdas, lm_preconditioners, narrowBand=3, maxIterations=50, gradientThreshold=1e-6, updateThreshold=1e-6, improvementThreshold=1e-6, verbosenessLevel=1, useAsymmetricLambda=True, ) print 'LM Status (%d): ' % status[0], status[1] #status = solve_single_lap_proj_silhouette(V, T, U, L, C, P, S, SN, # lm_lambdas, # lm_preconditioners, # narrowBand=2, # maxIterations=50, # gradientThreshold=1e-6, # updateThreshold=1e-6, # improvementThreshold=1e-6, # verbosenessLevel=1, # useAsymmetricLambda=True, # ) #print 'LM Status (%d): ' % status[0], status[1] return status #for i in xrange(10): # status = solve_iteration() count = 0 while status[0] in (0, 4) and count < 5: status = solve_iteration() count += 1 # show vis = visualise.VisualiseMesh(V, T, L) vis.add_image(wsp.get_frame_path(0)) Q = geometry.path2pos(V, T, L, U) N = Q.shape[0] vis.add_silhouette(Q, np.arange(N), [0, N - 1], S) vis.add_projection(C, P) vis.execute()