def loop_zhang(F, w, h): """ Computes rectifying homographies from a fundamental matrix, with Loop-Zhang. Args: F: 3x3 numpy array containing the fundamental matrix w, h: images size. The two images are supposed to have same size Returns: The two rectifying homographies. The rectifying homographies are computed using the Pascal Monasse binary named rectify_mindistortion. It uses the Loop-Zhang algorithm. """ Ffile = common.tmpfile('.txt') Haf = common.tmpfile('.txt') Hbf = common.tmpfile('.txt') common.matrix_write(Ffile, F) common.run('rectify_mindistortion %s %d %d %s %s > /dev/null' % (Ffile, w, h, Haf, Hbf)) Ha = common.matrix_read(Haf, size=(3, 3)) Hb = common.matrix_read(Hbf, size=(3, 3)) # check if both the images are rotated a = does_this_homography_change_the_vertical_direction(Ha) b = does_this_homography_change_the_vertical_direction(Hb) if a and b: R = np.array([[-1, 0, 0], [0, -1, 0], [0, 0, 1]]) Ha = np.dot(R, Ha) Hb = np.dot(R, Hb) return Ha, Hb
def compute_height_map(P1, P2, H1, H2, f_disp, f_mask, fout_height, fout_proj_err): import piio import common P1 = common.matrix_read(P1,3,4) P2 = common.matrix_read(P2,3,4) H1 = common.matrix_read(H1,3,3) H2 = common.matrix_read(H2,3,3) disp = piio.read(f_disp)[:,:,0] mask = piio.read(f_mask)[:,:,0] height,proj_err = disp_to_h_projective(P1,P2,H1,H2,disp,mask) piio.write(fout_height ,height) piio.write(fout_proj_err,proj_err)