def test_point_map(self): h_f = Homography(ctypes.c_float) h_d = Homography(ctypes.c_double) p_f = EigenArray.from_iterable([2.2, 3.3], ctypes.c_float) p_d = EigenArray.from_iterable([5.5, 6.6], ctypes.c_double) # float-float numpy.testing.assert_almost_equal(h_f.map(p_f), p_f) # float-double numpy.testing.assert_almost_equal(h_f.map(p_d), p_d) # double-float numpy.testing.assert_almost_equal(h_d.map(p_f), p_f) # double-double numpy.testing.assert_almost_equal(h_d.map(p_d), p_d)
def test_point_map(self): h_f = Homography('f') h_d = Homography('d') p_af = EigenArray.from_array([[2.2, 3.3]], 'f') p_f = p_af.get_matrix()[0] p_ad = EigenArray.from_array([[5.5, 6.6]], 'd') p_d = p_ad.get_matrix()[0] # float-float numpy.testing.assert_almost_equal( h_f.map(p_f), p_f ) # float-double numpy.testing.assert_almost_equal( h_f.map(p_d), p_d ) # double-float numpy.testing.assert_almost_equal( h_d.map(p_f), p_f ) # double-double numpy.testing.assert_almost_equal( h_d.map(p_d), p_d ) # Code to generate truth h = numpy.random.rand(3,3) h = h/numpy.linalg.norm(h) p0 = numpy.random.rand(3); p0[2] = 1 p1 = numpy.dot(h, p0) p1 = p1[:2]/p1[2] h_d = Homography.from_matrix(h, 'd') # map from Numpy array. numpy.testing.assert_almost_equal( h_d.map(p0[:2]).ravel(), p1 ) # map from EigenArray p0 = EigenArray.from_array([p0[:2]]) numpy.testing.assert_almost_equal( h_d.map(p0.get_matrix()[0]).ravel(), p1 ) # Another explicit case. p0 = numpy.array([1923.47,645.676,1]) h = numpy.array([[5.491496261770000276e-01,-1.125428185150000038e-01, 1.358427031619999923e+02], [-1.429513389049999993e-02 ,6.035527375529999849e-01, 5.923971959490000216e+01], [-2.042570000000000164e-06,-2.871670000000000197e-07, 1]]) p1 = numpy.dot(h, p0); p1 = p1[:2]/p1[2] H = Homography.from_matrix(h) P = EigenArray.from_array([p0[:2]]) numpy.testing.assert_almost_equal( H.map(P.get_matrix()[0]).ravel(), p1 )
def test_point_map(self): h_f = Homography(ctypes.c_float) h_d = Homography(ctypes.c_double) p_f = EigenArray.from_iterable([2.2, 3.3], ctypes.c_float) p_d = EigenArray.from_iterable([5.5, 6.6], ctypes.c_double) # float-float numpy.testing.assert_almost_equal( h_f.map(p_f), p_f ) # float-double numpy.testing.assert_almost_equal( h_f.map(p_d), p_d ) # double-float numpy.testing.assert_almost_equal( h_d.map(p_f), p_f ) # double-double numpy.testing.assert_almost_equal( h_d.map(p_d), p_d ) # Code to generate truth h = numpy.random.rand(3,3) h = h/numpy.linalg.norm(h) p0 = numpy.random.rand(3); p0[2] = 1 p1 = numpy.dot(h, p0) p1 = p1[:2]/p1[2] h_d = Homography.from_matrix(h, ctypes.c_double) # map from Numpy array. numpy.testing.assert_almost_equal( h_d.map(p0[:2]).ravel(), p1 ) # map from EigenArray p0 = EigenArray.from_iterable(p0[:2]) numpy.testing.assert_almost_equal( h_d.map(p0).ravel(), p1 ) # Another explicit case. p0 = numpy.array([1923.47,645.676,1]) h = numpy.array([[5.491496261770000276e-01,-1.125428185150000038e-01, 1.358427031619999923e+02], [-1.429513389049999993e-02 ,6.035527375529999849e-01, 5.923971959490000216e+01], [-2.042570000000000164e-06,-2.871670000000000197e-07, 1]]) p1 = numpy.dot(h, p0); p1 = p1[:2]/p1[2] H = Homography.from_matrix(h) P = EigenArray.from_iterable(p0[:2]) numpy.testing.assert_almost_equal( H.map(P).ravel(), p1 )