aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/utils/aruco_calibration_board_export.py
blob: c1d1645f603f768e31fbd8e5a9902c479dc23b7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python

import argparse
import os

from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoBoard

def main():
    """Generates ArUco board to calibrate a camera."""

    # Manage arguments
    parser = argparse.ArgumentParser(description=main.__doc__)
    parser.add_argument('columns', metavar='COLS_NUMBER', type=int, default=7, help='number of columns')
    parser.add_argument('rows', metavar='ROWS_NUMBER', type=int, default=5, help='number of rows')
    parser.add_argument('square_size', metavar='SQUARE_SIZE', type=int, default=5, help='square size in cm')
    parser.add_argument('marker_size', metavar='MARKER_SIZE', type=int, default=3, help='marker size in cm')
    parser.add_argument('dictionary', metavar='DICT', type=ArUcoMarkersDictionary.ArUcoMarkersDictionary, default='DICT_ARUCO_ORIGINAL', help='dictionnary name: DICT_4X4_50, DICT_4X4_100, DICT_4X4_250, DICT_4X4_1000, DICT_5X5_50, DICT_5X5_100, DICT_5X5_250, DICT_5X5_1000, DICT_6X6_50, DICT_6X6_100, DICT_6X6_250, DICT_6X6_1000, DICT_7X7_50, DICT_7X7_100, DICT_7X7_250, DICT_7X7_1000, DICT_ARUCO_ORIGINAL, DICT_APRILTAG_16h5, DICT_APRILTAG_25h9, DICT_APRILTAG_36h10, DICT_APRILTAG_36h11')
    parser.add_argument('-r', '--resolution', metavar='RES', type=int, default=300, help='picture resolution in dpi')
    parser.add_argument('-o', '--output', metavar='OUT', type=str, default='.', help='destination folder path')
    args = parser.parse_args()

    # Manage destination folder
    if not os.path.exists(args.output):
        os.makedirs(args.output)
        print(f'{args.output} folder created')

    # Create aruco board
    aruco_board = ArUcoBoard.ArUcoBoard(args.columns, args.rows, args.square_size, args.marker_size, args.dictionary)

    # Export aruco board as png
    filepath = f'{args.output}/{aruco_board.dictionary.name}_{aruco_board.marker_size}cm_{aruco_board.columns*aruco_board.square_size}cmx{aruco_board.rows*aruco_board.square_size}cm.png'
    aruco_board.save(filepath, args.resolution)

    print(f'{args.columns} x {args.rows} calibration board with {args.marker_size} cm markers from {args.dictionary.name} dictionary exported into {args.output} folder.')

if __name__ == '__main__':

    main()