opencsp.app.camera_calibration.lib.calibration_camera

Library of functions used to calibation a machine vision camera. Functions are based off OpenCV library.

opencsp.app.camera_calibration.lib.calibration_camera.calibrate_camera(p_object: Iterable[Vxyz], p_image: Iterable[Vxy], img_shape_xy: tuple[int, int], name: str) tuple[Camera, Iterable[Rotation], Iterable[Vxyz], float]

Performs 4 term camera calibration for non-fisheye lens. Calculates only distortion coefficients, [K1, K2, P1, P2] (K3 = 0). Higher order fits are generally used for fisheye and other exotic lenses and are not supported here.

Parameters:
  • p_object (list[Vxyz, ...]) – List of object points (grid coordinates).

  • p_image (list[Vxy, ...]) – List of image points (pixels).

  • img_shape_xy (tuple[int, int]) – Size of image in pixels.

  • name (str) – Name of camera.

Returns:

  • Camera (opencsp.common.lib.camera.Camera.Camera) – Camera class.

  • r_cam_object (list[Rotation, …]) – Camera-object rotation vector

  • v_cam_object_cam (list[Vxyz, …]) – Camera location vector

  • Error (float) – Average reprojection error (pixels).

opencsp.app.camera_calibration.lib.calibration_camera.view_distortion(camera: Camera, ax1: Axes, ax2: Axes, ax3: Axes, num_samps: int = 12)

Plots the radial/tangential distortion of a camera object.

Parameters:
  • camera (opencsp.common.lib.camera.Camera.Camera) – Camera to visualize.

  • ax1 (Axes) – Axis to plot radial distortion.

  • ax2 (Axes) – Axis to plot tangential distortion.

  • ax3 (Axes) – Axis to plot total distortion.

  • num_samps (int, optional) – Number of samples across short side of image. The default is 12.

opencsp.app.camera_calibration.lib.image_processing

Library of image processing functions used for camera calibration

opencsp.app.camera_calibration.lib.image_processing.annotate_found_corners(npts: tuple[int, int], img: ndarray, img_points: Vxy) None

Updates an image with found checkerboard corner annotations.

Parameters:
  • npts (tuple (x, y), int) – Number of corners in image to annotate.

  • img (ndarray (RGB or grayscale)) – The checkerboard image. This is updated with annotations.

  • img_points (Vxy) – Points found in image. Output from cv.findChessboardCorners.

opencsp.app.camera_calibration.lib.image_processing.find_checkerboard_corners(npts: tuple[int, int], img: ndarray) tuple[Vxyz, Vxy]

Finds checkerboard corners in given image.

Parameters:
  • npts (tuple (x, y)) – Number of corners to find. Corners must be surrounded on all four sides by complete black/white squares that are NOT on the edge of the pattern.

  • img (2D numpy array, uint8) – Image containing checkerboard image. Should be opened using cv2.imread(file, cv2.IMREAD_GRAYSCALE)

Returns:

  • p_object (Vxyz) – Location of corners in target grid coordinates

  • p_corners_refined (Vxy) – Location of corners in camera pixels

opencsp.app.camera_calibration.lib.image_processing.refine_checkerboard_corners(image: ndarray, p_image: Vxy, window_size: tuple[int, int] = (10, 10), max_iterations: int = 40, precision: float = 0.001) Vxy

Refines rough locations of checkerboard corners

Parameters:
  • image (np.ndarray) – Image to refine with, uint8.

  • p_image (Vxy) – Rough u/v corner locations, float32.

  • window_size (tuple[int, int], optional) – Search window half-width. The default is (10, 10).

  • max_iterations (int, optional) – Max number of search iterations. The default is 40.

  • precision (float, optional) – Desired precision in pixels. The default is 0.001.

Returns:

Refined image points.

Return type:

Vxy

opencsp.app.camera_calibration.lib.ViewAnnotatedImages

GUI used to view annotated checkerboard corners.

class opencsp.app.camera_calibration.lib.ViewAnnotatedImages.ViewAnnotatedImages(root: Tk, images: list[ndarray], image_names: list[str])

Bases: object

Class that controls a window used to view images with a next and previous button

close() None

Closes window

show_next()

Show the next image.

show_prev()

Show the previous image.

update_image()

Updates displayed image and image label