def test_point3D(): assert np.all(Point3D(1,2,3) == np.array([[1],[2],[3]])) assert np.all(Point3D(np.array([[1],[2],[3]])) == np.array([[1],[2],[3]])) assert np.all(Point3D(np.array([[1,2],[2,0],[3,5]])) == np.array([[1,2],[2,0],[3,5]])) assert np.all(Point3D([1,2],[2,0],[3,5]) == np.array([[1,2],[2,0],[3,5]])) assert np.all(Point3D([1,2,4,9,1],[2,0,0,0,3],[3,5,1,2,3]) == np.array([[1,2,4,9,1],[2,0,0,0,3],[3,5,1,2,3]])) assert np.all(Point3D([Point3D(1,2,3), Point3D(5,6,6)]) == Point3D([1,5], [2,6], [3,6]))
def test_tolist(): p = Point3D(1400.2, 750.3, 0.1) assert np.all(p.to_list() == [1400.2, 750.3, 0.1]) assert np.all(p.to_int_tuple() == (1400, 750, 0)) points3D = Point3D([1400, 2800],[750, 1500],[0,0]) try: points3D.to_int_tuple() except BaseException as e: assert isinstance(e, AssertionError) else: assert False
def test_projection(): calib = Calib(K=K, R=R, kc=kc, T=T, width=width, height=height) # Single point point3D = Point3D(1400,750,0) point2D = calib.project_3D_to_2D(point3D) assert np.all(point2D - np.array([[128.950], [782.928]]) < 1.0e-2) # 0.01 pixel error projection assert np.all(calib.project_2D_to_3D(point2D, Z=0) - point3D < 1.0e-2) # 0.01 cm error reprojection on image border # Multiple points points3D = Point3D([1400, 2800],[750, 1500],[0, 0]) points2D = calib.project_3D_to_2D(points3D) assert np.all(points2D - np.array([[128.950, 1895.195], [782.928, 968.128]]) < 1.0e-2) # 0.01 pixel error projection assert np.all(calib.project_2D_to_3D(points2D, Z=0) - points3D < 1.0e-2) # 0.01 cm error reprojection on image border
def test_constructorlist(): p1 = Point3D(1,2,3) p2 = Point3D(5,6,7) points = Point3D(np.linspace(p1, p2, 5)) assert np.all(points == Point3D([1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7]))
def test_linspace(): p1 = Point3D(1,2,3) p2 = Point3D(5,6,7) points = np.linspace(p1, p2, 5) assert np.all(points == np.array([Point3D(1,2,3), Point3D(2,3,4), Point3D(3,4,5), Point3D(4,5,6), Point3D(5,6,7)]))
def test_flatten(): p = Point3D(1400, 750, 0) assert np.all(p.flatten() == [1400, 750, 0]) points3D = Point3D([1400, 2800],[750, 1500],[0,0]) assert np.all(points3D.flatten() == [1400, 2800, 750, 1500, 0, 0]) assert not isinstance(p.flatten(), Point3D)
def test_iterator(): points3D = Point3D([1400, 2800],[750, 1500],[0,0]) points3D_list = [Point3D(1400, 750, 0), Point3D(2800, 1500, 0)] for point3D, expected_point3D in zip(points3D, points3D_list): assert np.all(point3D - expected_point3D == 0)
def test_getitem(): return point3D = Point3D([1400, 2800],[750, 1500],[0,0]) assert np.all(point3D.x == [1400, 2800]) assert np.all(point3D[0] - Point3D(1400, 750, 0) == 0)