ax.plot(Xtrue[0],Xtrue[1],Xtrue[2],'r.') plt.axis('equal') #5.2.2 3Dの点群からカメラ行列を計算する corr = corr[:,0] # ndx3D = np.where(corr>=0)[0] ndx2D = corr[ndx3D] #見える点を選び同次座標に変換 x = points2D[0][:,ndx2D] # x = np.vstack( (x,np.ones(x.shape[1])) ) X = points3D[:,ndx3D] X = np.vstack( (X,np.ones(X.shape[1])) ) #Pを指定する Pest = camera.Camera(sfm.compute_P(x,X)) #比較する print Pest.P / Pest.P[2,3] print P[0].P / P[0].P[2,3] xest = Pest.project(X) #描画する plt.figure() plt.imshow(im1) plt.plot(x[0],x[1],'bo') plt.plot(xest[0],xest[1],'r.') plt.axis('off')
plt.show # + # %matplotlib inline corr1 = corr[:, 0] #第一視点のインデックスを取り出す。 ndx3D = np.where(corr1 >= 0)[0] ndx2D = corr1[ndx3D] #見える点を選び、同次座標に変換 x = points2D[0][:, ndx2D] x = homography.make_homog(x) X = points3D[:, ndx3D] X = homography.make_homog(X) # Pを推定する Pest = camera.Camera(sfm.compute_P(x, X)) #比較する print(Pest.P / Pest.P[2, 3]) print(P[0].P / P[0].P[2, 3]) xest = Pest.project(X) #描写する。 ip.show_img(im1) plt.plot(x[0], x[1], 'bo') plt.plot(xest[0], xest[1], 'r.') plt.axis('off') plt.show() # -
import pandas as pd import numpy as np points2D = [np.loadtxt('2D/00' + str(i + 1) + '.corners').T for i in range(3)] points3D = np.loadtxt('3D/p3d').T corr = np.genfromtxt('2D/nview-corners', dtype='int', missing_values='*') corr = corr[:, 0] ndx3D = np.where(corr >= 0)[0] # missing values are -1 ndx2D = corr[ndx3D] x = points2D[0][:, ndx2D] # view 1 x = np.vstack((x, np.ones(x.shape[1]))) X = points3D[:, ndx3D] X = np.vstack((X, np.ones(X.shape[1]))) # estimate P print sfm.compute_P(x, X) corr = np.genfromtxt('2D/nview-corners', dtype='int', missing_values='*') # index for points in first two views ndx = (corr[:, 0] >= 0) & (corr[:, 1] >= 0) # get coordinates and make homogeneous x1 = points2D[0][:, corr[ndx, 0]] x1 = np.vstack((x1, np.ones(x1.shape[1]))) x2 = points2D[1][:, corr[ndx, 1]] x2 = np.vstack((x2, np.ones(x2.shape[1]))) # compute F print x1 print x2 F = sfm.compute_fundamental(x1, x2) print 'F', F