Ejemplo n.º 1
0
    def setUpMultiView(self, N_lines, K_imgs, sigma_R_image = 0.001, sigma_T_image = 0.001):
        
        #Define random rotations for our cameras
        R_list = [ga_exp(createRandomBivector()) for _ in range(K_imgs)]            

        #Create N lines
        lines = createRandomLines(N_lines, scale = 2)
        for i in range(len(lines)):
            lines[i] = Sandwich(lines[i], Translator(e3*4))

        
        #Create our noise free images for comparison
        lines_img_base_d_real   =  [projectLineToPlane(line, one) for line in lines]        #Real base lines
        lines_imgs_d_real       = [[projectLineToPlane(line, R_list[i]) for line in lines] for i in range(K_imgs)]
  


        #Create noisy images
        lines_img_base_d     =  [perturbeObjectInplane(projectLineToPlane(line, one)      , sigma_R_image, sigma_T_image) for line in lines]    
        lines_imgs_d         = [[perturbeObjectInplane(projectLineToPlane(line, R_list[i]), sigma_R_image, sigma_T_image) for line in lines] for i in range(K_imgs)]  

        i = 0
        #for j in range(len(lines_imgs_d[i])):
        #    print((R_list[i]*(-no ^ lines_imgs_d_real[i][j])* ~R_list[i]).normal())
        #    print(((R_list[i]*(-no)* ~R_list[i])^lines[j]).normal())
        #    print("")


        return R_list, lines, lines_img_base_d, lines_img_base_d_real , lines_imgs_d, lines_imgs_d_real
Ejemplo n.º 2
0
 def testLineProjection(self):
     A, B = createRandomPoints(2)
     R = ga_exp(createRandomBivector())
     L = createLine(A, B)
     L_img = projectLineToPlane(L, R)
     A_img = projectPointToPlane(A, R)
     B_img = projectPointToPlane(B, R)
     L_img_actual = createLine(A_img, B_img)
     assert(MVEqual(L_img, L_img_actual))
Ejemplo n.º 3
0
 def testAssertEqual(self):
     verbose = False
     a = createRandomBivector()
     b = a + 0.01
     a2 = b - 0.01
     c = a + 1
     d = c - a
     AssertMVEqual(a, a2, verbose=verbose)
     AssertMVUnEqual(a, b, verbose=verbose)
     AssertMVEqual(d, 1, verbose=verbose)
Ejemplo n.º 4
0
def benchmarkImageCostFunction():
    np.random.seed(123)
    B = createRandomBivector()
    R_real = ga_exp(B)
    N = 10

    lines = createRandomLines(N, scale = 2)
    for i in range(len(lines)):
        lines[i] = Sandwich(lines[i], Translator(e3*3))

    sigma_R_model = 0.01
    sigma_T_model = 0.01
    lines_perturbed = [perturbeObject(line, sigma_T_model, sigma_R_model) for line in lines] #Model noise

    lines_img_d_real   = [projectLineToPlane(line, R_real) for line in lines]                     #Real lines

    sigma_R_image = 0.01
    sigma_T_image = 0.01        
    lines_img_d        = [perturbeObjectInplane(projectLineToPlane(line, R_real), sigma_R_image, sigma_T_image) for line in lines]

    traininglinesets = (lines_perturbed, lines_img_d)

    benchmarkMinimizeError(R_real, traininglinesets, traininglinesets, fileout = None, mapping = BivectorLineImageMapping)
Ejemplo n.º 5
0
    def testLogarithm(self):
        verbose = False

        if verbose:
            print("\nTest Logarithms and exponents")

        phi = 0.5  #Rotation amount
        P = (e12 + 2 * e23 + 3 * e13).normal()  #Rotation Plane
        P_n = P * I3

        t = 2.73 * e1 + 3.14 * e2  #Translation vector
        t_nor = (P_n | t) * P_n  #Decomposition into normal component
        t_par = t - t_nor  #Decomposition into paralel component
        assert (t_par + t_nor == t)

        if verbose:
            print("P     = ", P)
            print("phi   = ", phi)
            print("t     = ", t)
            print("t_nor = ", t_nor)
            print("t_par = ", t_par)
            print("")

        assert (P | t_nor == 0)  #Normal to P
        assert (P ^ t_nor != 0)  #Normal to P
        assert (P | t_par != 0)  #Parallel to P
        assert (P ^ t_par == 0)  #Parallel to P
        assert (P * t != 0)  #Non zero product

        R_expected = (np.cos(phi) +
                      (np.sin(phi) * P)) * (1 + (t_nor * ninf)) + np.sinc(
                          phi / np.pi) * t_par * ninf
        B_expected = phi * P + t * ninf

        R_exponential = np.exp(B_expected)

        R_actual = ga_exp(B_expected, verbose=verbose)
        B_new = ga_log(R_expected, verbose=verbose)
        R_ga = ga_exp(B_new)

        if verbose:
            print("R_old        ", R_expected)
            print("R_expected   ", R_actual)
            print("R_exponential", R_exponential)
            print("R_ga         ", R_ga)
            print("B_new        ", B_new)
            print("B_expected   ", B_expected)

        #Rotor properties
        AssertMVEqual(R_expected * ~R_expected, 1, verbose=verbose)
        AssertMVEqual(R_ga * ~R_ga, 1, verbose=verbose)

        #Equalities
        AssertMVEqual(R_actual, R_expected, verbose=verbose)
        AssertMVEqual(R_exponential, R_expected, verbose=verbose)
        AssertMVEqual(B_new, B_expected, verbose=verbose)
        AssertMVEqual(R_ga, R_expected, verbose=verbose)

        N = 100
        #Random bivectors to test this as well
        for i in range(N):
            B = createRandomBivector()
            AssertMVEqual(B,
                          ga_log(ga_exp(B, verbose=verbose), verbose=verbose),
                          verbose=verbose)