def test_equal(self): ci1 = CameraIntrinsics() ci2 = CameraIntrinsics() ntools.assert_true(ci1 == ci2) ntools.assert_false(ci1 != ci2) ci1 = CameraIntrinsics(2, (10, 10), 3, 1) ci2 = CameraIntrinsics(2, (11, 10), 3, 0.1) ntools.assert_false(ci1 == ci2) ntools.assert_true(ci1 != ci2)
def test_members(self): ci = CameraIntrinsics() assert (ci.is_map_valid(np.array([2, 1, 1]))) np.testing.assert_array_almost_equal(np.array([3, 2]), ci.distort(np.array([3, 2]))) np.testing.assert_array_almost_equal(np.array([3, 2]), ci.undistort(np.array([3, 2])))
def test_new(self): # just seeing that basic construction doesn't blow up cam = Camera() c = EigenArray(3) r = Rotation() ci = CameraIntrinsics() cam = Camera(c, r, ci)
def test_virt_methods(self): ci = CameraIntrinsics() no_call_pure_virtual_method(ci.focal_length) no_call_pure_virtual_method(ci.principal_point) no_call_pure_virtual_method(ci.aspect_ratio) no_call_pure_virtual_method(ci.skew) no_call_pure_virtual_method(ci.image_width) no_call_pure_virtual_method(ci.image_height) no_call_pure_virtual_method(ci.map, np.array([0, 1])) no_call_pure_virtual_method(ci.unmap, np.array([0, 1])) no_call_pure_virtual_method(ci.as_matrix)
def test_clone_look_at(self): pp = EigenArray.from_array([[300], [400]]) k = CameraIntrinsics(1000, [300, 400]) focus = EigenArray.from_array([[0], [1], [-2]]) center = EigenArray.from_array([[3], [-4], [7]]) base = Camera(center, Rotation(), k) cam = base.clone_look_at(numpy.array([0, 1, 2])) nose.tools.assert_not_equal(base, cam) ifocus = cam.project([0, 1, 2]) nose.tools.assert_almost_equal( numpy.linalg.norm(ifocus - pp.get_matrix().T, 2), 0., 12) ifocus_up = cam.project([0, 1, 4]) tmp = (ifocus_up - pp.get_matrix().T)[0] nose.tools.assert_almost_equal(tmp[0], 0., 12) nose.tools.assert_true(tmp[1] < 0.)
def camera_seq(num_cams=20, k=None): """ Create a camera sequence (elliptical path) :param num_cams: Number of cameras. Default is 20 :param k: Camera intrinsics to use for all created cameras. Default has focal length = 1000 and principle point of (640, 480). :return: """ if k is None: k = CameraIntrinsics(1000, [640, 480]) d = {} r = RotationD() # identity for i in range(num_cams): frac = float(i) / num_cams x = 4 * math.cos(2*frac) y = 3 * math.sin(2*frac) d[i] = Camera([x, y, 2+frac], r, k).clone_look_at([0, 0, 0]) return CameraMap(d)
def init_cameras(num_cams=20, intrinsics=None): """ Initialize camera sequence with all cameras at the same location (0, 0, 1) and looking at origin. :param num_cams: Number of cameras to create, default 20. :param intrinsics: Intrinsics to use for all cameras. :return: Camera map of initialize cameras """ if intrinsics is None: intrinsics = CameraIntrinsics(1000, (640, 480)) r = RotationD() c = np.array([0, 0, 1]) d = {} for i in range(num_cams): cam = Camera(c, r, intrinsics).clone_look_at([0, 0, 0], [0, 1, 0]) d[i] = cam return CameraMap(d)
def test_read_write_krtd_file(self): # Use a random string filename to avoid name collision. fname = 'temp_camera_test_read_write_krtd_file.txt' try: for _ in range(100): c = (rand(3) * 2 - 1) * 100 center = EigenArray.from_array([c]) rotation = Rotation.from_quaternion( numpy.random.rand(4) * 2 - 1) intrinsics = CameraIntrinsics(10, (5, 5), 1.2, 0.5, [4, 5, 6]) c1 = Camera(center, rotation, intrinsics) c1.write_krtd_file(fname) c2 = Camera.from_krtd_file(fname) err = numpy.linalg.norm(c1.center - c2.center) assert err < 1e-9, ''.join( ['Centers are different by ', str(err)]) c1.rotation.angle_from(c2.rotation) < 1e-12 attr = [ 'focal_length', 'aspect_ratio', 'principle_point', 'skew', 'dist_coeffs' ] for att in attr: v1 = numpy.array(getattr(c1.intrinsics, att)) v2 = numpy.array(getattr(c2.intrinsics, att)) err = numpy.linalg.norm(v1 - v2) assert err < 1e-8, ''.join( ['Difference ', str(err), ' for attribute: ', att]) finally: if os.path.isfile(fname): os.remove(fname)
def test_init(self): CameraIntrinsics()
def test_get_focal_length(self): ntools.assert_equal(CameraIntrinsics().focal_length, 1.) ntools.assert_equal(CameraIntrinsics(5.2).focal_length, 5.2)
def test_as_matrix(self): numpy.testing.assert_equal(CameraIntrinsics().as_matrix(), numpy.eye(3)) numpy.testing.assert_equal( CameraIntrinsics(10, (2, 3), 2, 5).as_matrix(), [[10, 5, 2], [0, 5, 3], [0, 0, 1]])
def test_get_dist_coeffs(self): numpy.testing.assert_array_equal(CameraIntrinsics().dist_coeffs, numpy.zeros((1, ))) numpy.testing.assert_array_equal( CameraIntrinsics(dist_coeffs=(10, 4, 32, 1.1)).dist_coeffs, [10, 4, 32, 1.1])
def test_get_skew(self): ntools.assert_equal(CameraIntrinsics().skew, 0.) ntools.assert_equal(CameraIntrinsics(skew=1.).skew, 1.)
def test_get_aspect_ratio(self): ntools.assert_equal(CameraIntrinsics().aspect_ratio, 1.) ntools.assert_equal( CameraIntrinsics(aspect_ratio=2.1).aspect_ratio, 2.1)
def test_get_principal_point(self): numpy.testing.assert_array_equal(CameraIntrinsics().principal_point, [0, 0]) numpy.testing.assert_array_equal( CameraIntrinsics(principal_point=(10, 2.3)).principal_point, [10, 2.3])
def test_init_from_base(self): no_call_pure_virtual_method(SimpleCameraIntrinsics, CameraIntrinsics()) SimpleCameraIntrinsics(SimpleCameraIntrinsics())
def test_full_init(self): CameraIntrinsics(10, (5, 5), 1.2, 3.1, [4, 5, 6])