chesscog.corner_detection package

Chessboard localization module.

Submodules

chesscog.corner_detection.create_configs module

Script to create config files for the grid search.

$ python -m chesscog.corner_detection.create_configs --help
usage: create_configs.py [-h]

Create YAML config files for grid search.

optional arguments:
  -h, --help  show this help message and exit

chesscog.corner_detection.detect_corners module

Module to perform chessboard localization.

The entire board localization pipeline is implemented end-to-end in this module. Use the find_corners() to run it.

This module simultaneously acts as a script:

$ python -m chesscog.corner_detection.detect_corners --help
usage: detect_corners.py [-h] [--config CONFIG] file

Chessboard corner detector.

positional arguments:
  file             URI of the input image file

optional arguments:
  -h, --help       show this help message and exit
  --config CONFIG  path to the config file
chesscog.corner_detection.detect_corners.compute_transformation_matrix(src_points: numpy.ndarray, dst_points: numpy.ndarray) numpy.ndarray

Compute the transformation matrix based on source and destination points.

Parameters
  • src_points (np.ndarray) – the source points (shape: […, 2])

  • dst_points (np.ndarray) – the source points (shape: […, 2])

Returns

the transformation matrix

Return type

np.ndarray

chesscog.corner_detection.detect_corners.find_corners(cfg: recap.config.CfgNode, img: numpy.ndarray) numpy.ndarray

Determine the four corner points of the chessboard in an image.

Parameters
  • cfg (CN) – the configuration object

  • img (np.ndarray) – the input image (as a numpy array)

Raises

ChessboardNotLocatedException – if the chessboard could not be found

Returns

the pixel coordinates of the four corners

Return type

np.ndarray

chesscog.corner_detection.detect_corners.get_intersection_point(rho1: numpy.ndarray, theta1: numpy.ndarray, rho2: numpy.ndarray, theta2: numpy.ndarray) Tuple[numpy.ndarray, numpy.ndarray]

Obtain the intersection point of two lines in Hough space.

This method can be batched

Parameters
  • rho1 (np.ndarray) – first line’s rho

  • theta1 (np.ndarray) – first line’s theta

  • rho2 (np.ndarray) – second lines’s rho

  • theta2 (np.ndarray) – second line’s theta

Returns

the x and y coordinates of the intersection point(s)

Return type

typing.Tuple[np.ndarray, np.ndarray]

chesscog.corner_detection.detect_corners.resize_image(cfg: recap.config.CfgNode, img: numpy.ndarray) Tuple[numpy.ndarray, float]

Resize an image for use in the corner detection pipeline, maintaining the aspect ratio.

Parameters
  • cfg (CN) – the configuration object

  • img (np.ndarray) – the input image

Returns

the resized image along with the scale of this new image

Return type

typing.Tuple[np.ndarray, float]

chesscog.corner_detection.evaluate module

Script to evaluate the chessboard localisation algorithm.

$ python -m chesscog.corner_detection.evaluate --help
usage: evaluate.py [-h] [--config CONFIG]
                   [--dataset {train,val,test}] [--out OUT]

Evaluate the chessboard corner detector.

optional arguments:
  -h, --help            show this help message and exit
  --config CONFIG       path to a folder with YAML config files
                        (or path to a YAML config file)
  --dataset {train,val,test}
                        the dataset to evaluate (if unspecified,
                        train and val will be evaluated)
  --out OUT             output folder

chesscog.corner_detection.find_best_configs module

Script to execute the grid search over the generated YAML config files in order to determine which configuration achieves the best performance of the chessboard localization algorithm.

$ python -m chesscog.corner_detection.find_best_configs --help
usage: find_best_configs.py [-h] [--n N] [--in INPUT]
                            [--out OUT]

Get the best n configs of the results obtained via grid search

optional arguments:
  -h, --help  show this help message and exit
  --n N       the number of configs to retain
  --in INPUT  the CSV file containing the results of the grid
              search
  --out OUT   the output folder for the YAML files     output folder

chesscog.corner_detection.visualize module

Utilities for visualizing the functionality of the chessboard corner detector.

chesscog.corner_detection.visualize.draw_lines(img: numpy.ndarray, lines: numpy.ndarray, color: tuple = (0, 0, 255), thickness: int = 2)

Draw lines specified in Hough space on top of the input image.

Parameters
  • img (np.ndarray) – the input image

  • lines (np.ndarray) – the lines of shape [N, 2] where the last dimension are the rho and theta values

  • color (tuple, optional) – the color to draw the lines in. Defaults to (0, 0, 255).

  • thickness (int, optional) – thickness of the lines. Defaults to 2.