model = homography.RansacModel() H, inliers = homography.H_from_ransac(fp, tp, model) # camera calibration K = my_calibration((747, 1000)) # 3D points at plane z=0 with sides of length 0.2 box = cube_points([0, 0, 0.1], 0.1) # project bottom square in first image cam1 = camera.Camera(hstack((K, dot(K, array([[0], [0], [-1]]))))) # first points are the bottom square box_cam1 = cam1.project(homography.make_homog(box[:, :5])) # use H to transfer points to the second image box_trans = homography.normalize(dot(H, box_cam1)) # compute second camera matrix from cam1 and H cam2 = camera.Camera(dot(H, cam1.P)) A = dot(linalg.inv(K), cam2.P[:, :3]) A = array([A[:, 0], A[:, 1], cross(A[:, 0], A[:, 1])]).T cam2.P[:, :3] = dot(K, A) # project with the second camera box_cam2 = cam2.project(homography.make_homog(box)) # plotting im0 = array(Image.open('book_frontal.JPG')) im1 = array(Image.open('book_perspective.JPG')) figure()
H, inliers = homography.H_from_ransac(fp, tp, model) # camera calibration K = my_calibration((747, 1000)) # 3D points at plane z=0 with sides of length 0.2 box = cube_points([0, 0, 0.1], 0.1) # project bottom square in first image cam1 = camera.Camera(hstack((K, dot(K, array([[0], [0], [-1]]))))) # first points are the bottom square box_cam1 = cam1.project(homography.make_homog(box[:, :5])) # use H to transfer points to the second image box_trans = homography.normalize(dot(H,box_cam1)) # compute second camera matrix from cam1 and H cam2 = camera.Camera(dot(H, cam1.P)) A = dot(linalg.inv(K), cam2.P[:, :3]) A = array([A[:, 0], A[:, 1], cross(A[:, 0], A[:, 1])]).T cam2.P[:, :3] = dot(K, A) # project with the second camera box_cam2 = cam2.project(homography.make_homog(box)) # plotting im0 = array(Image.open('book_frontal.JPG')) im1 = array(Image.open('book_perspective.JPG'))
K = my_calibration((747,1000)) print K # 3D points at plane z=0 with sides of length 0.2 # box = cube_points([0.15,-0.15,0.1],0.1) box = cube_points([0,0,0.1],0.09) # project bottom square in first image cam1 = camera.Camera( hstack((K,dot(K,array([[0],[0],[-1]])) )) ) # first points are the bottom square box_cam1 = cam1.project(homography.make_homog(box[:,:5])) # use H to transfer points to the second image box_trans = homography.normalize(dot(H,box_cam1)) # compute second camera matrix from cam1 and H cam2 = camera.Camera(dot(H,cam1.P)) A = dot(linalg.inv(K),cam2.P[:,:3]) A = array([A[:,0],A[:,1],cross(A[:,0],A[:,1])]).T cam2.P[:,:3] = dot(K,A) # print cam2.P Rt = dot(linalg.inv(K),cam2.P) print Rt # project with the second camera box_cam2 = cam2.project(homography.make_homog(box)) point = array([1,1,0,1]).T