def set_camera_matrix(self, camera_matrix):
     """
     Sets the camera projection matrix from a numpy 3x3 array.
     :param camera_matrix: numpy 3x3 ndarray containing fx, fy, cx, cy
     """
     vm.validate_camera_matrix(camera_matrix)
     self.camera_matrix = camera_matrix
     opengl_mat, vtk_mat = self.__update_projection_matrix()
     self.Render()
     return opengl_mat, vtk_mat
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)
Exemple #3
0
def test_camera_matrix_valid():
    camera_matrix = np.ones((3, 3))
    assert vm.validate_camera_matrix(camera_matrix)
Exemple #4
0
def test_camera_matrix_invalid_because_too_many_columns():
    with pytest.raises(ValueError):
        vm.validate_camera_matrix(np.ones((3, 4)))
Exemple #5
0
def test_camera_matrix_invalid_because_too_few_rows():
    with pytest.raises(ValueError):
        vm.validate_camera_matrix(np.ones((1, 3)))
Exemple #6
0
def test_camera_matrix_invalid_because_not_two_dimensional():
    with pytest.raises(ValueError):
        vm.validate_camera_matrix(np.ones((3, 3, 3)))
Exemple #7
0
def test_camera_matrix_invalid_because_wrong_type():
    with pytest.raises(TypeError):
        vm.validate_camera_matrix(1)