def test_construct_rigid_transformation(): tiny = 0.0001 rot_m = mat.construct_rx_matrix(np.pi / 2) vm.validate_rotation_matrix(rot_m) trans_v = np.array([[10], [10], [10]]) vm.validate_translation_column_vector(trans_v) rigid_transformation = mat.construct_rigid_transformation(rot_m, trans_v) vm.validate_rigid_matrix(rigid_transformation) assert np.abs(rigid_transformation[0][0] - 1) < tiny assert np.abs(rigid_transformation[0][1]) < tiny assert np.abs(rigid_transformation[0][2]) < tiny assert np.abs(rigid_transformation[0][3] - 10) < tiny assert np.abs(rigid_transformation[1][0]) < tiny assert np.abs(rigid_transformation[1][1]) < tiny assert np.abs(rigid_transformation[1][2] + 1) < tiny assert np.abs(rigid_transformation[1][3] - 10) < tiny assert np.abs(rigid_transformation[2][0]) < tiny assert np.abs(rigid_transformation[2][1] - 1) < tiny assert np.abs(rigid_transformation[2][2]) < tiny assert np.abs(rigid_transformation[2][3] - 10) < tiny assert np.abs(rigid_transformation[3][0]) < tiny assert np.abs(rigid_transformation[3][1]) < tiny assert np.abs(rigid_transformation[3][2]) < tiny assert np.abs(rigid_transformation[3][3] - 1) < tiny
def set_left_to_right(self, left_to_right): """ Sets the left_to_right transform (stereo extrinsics). :param left_to_right: 4x4 numpy ndarray, rigid transform """ vm.validate_rigid_matrix(left_to_right) self.left_to_right = left_to_right
def set_camera_pose(self, camera_to_world): """ Sets the camera position and orientation, from a numpy 4x4 array. :param camera_to_world: camera_to_world transform. """ vm.validate_rigid_matrix(camera_to_world) self.camera_to_world = camera_to_world vtk_cam = self.get_foreground_camera() vtk_mat = mu.create_vtk_matrix_from_numpy(camera_to_world) cm.set_camera_pose(vtk_cam, vtk_mat, self.opencv_style) self.Render()
def _validate_input_for_projection(points, camera_to_world, camera_matrix, distortion=None): """ Validation of input, for both project_points and project_facing_points. :param points: nx3 ndarray representing 3D points, typically in millimetres :param camera_to_world: 4x4 ndarray representing camera_to_world transform :param camera_matrix: 3x3 ndarray representing OpenCV camera intrinsics :param distortion: 1x4,5 etc. OpenCV distortion parameters :raises ValueError, TypeError: :return: nx2 ndarray representing 2D points, typically in pixels """ if points is None: raise ValueError('points is NULL') if not isinstance(points, np.ndarray): raise TypeError('points is not an np.ndarray') if len(points.shape) != 2: raise ValueError("points should have 2 dimensions.") if points.shape[1] != 3: raise ValueError("points should have 3 columns.") if camera_to_world is None: raise ValueError('camera_to_world is NULL') vm.validate_rigid_matrix(camera_to_world) if camera_matrix is None: raise ValueError('camera_matrix is NULL') vm.validate_camera_matrix(camera_matrix) if distortion is not None: vm.validate_distortion_coefficients(distortion)
def test_rigid_matrix_valid_because_identity(): vm.validate_rigid_matrix(np.eye(4))
def test_rigid_matrix_invalid_because_wrong_columns(): with pytest.raises(ValueError): vm.validate_rigid_matrix(np.ones((4, 2)))
def test_rigid_matrix_invalid_because_wrong_dimensions(): with pytest.raises(ValueError): vm.validate_rigid_matrix(np.ones((2, 1, 2)))
def test_rigid_matrix_invalid_because_wrong_type(): with pytest.raises(TypeError): vm.validate_rigid_matrix(None)