-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcam_calib.py
More file actions
50 lines (42 loc) · 2.02 KB
/
cam_calib.py
File metadata and controls
50 lines (42 loc) · 2.02 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
from argparse import ArgumentParser
from cam_tools import CamToolsError, label, undistort
def main():
parser = ArgumentParser(description="Useful tools for camera calibration")
subparsers = parser.add_subparsers(
help="Various tools", dest="command")
label_parser = subparsers.add_parser(
"label", help="Easy labelling of corners")
label_parser.add_argument(
"-p", "--path", help="The directory of images to label", default="images")
label_parser.add_argument(
"-f", "--format", help="The format of the images", default="jpg")
label_parser.add_argument(
"-o", "--output", help="The output file to contain the corners", default="corners.csv")
label_parser.add_argument(
"-d", "--dimension", help="The dimension of the board", default="8x8")
undistort_parser = subparsers.add_parser(
"undistort", help="Undistorting images")
undistort_parser.add_argument(
"-p", "--path", help="The directory of images to undistort", default="images")
undistort_parser.add_argument(
"-f", "--format", help="The format of the images", default="jpg")
undistort_parser.add_argument(
"-i", "--input", help="The input file containing the corners", default="corners.csv")
undistort_parser.add_argument(
"-o", "--output", help="The directory for the undistorted images", default="images_undistorted")
undistort_parser.add_argument(
"-d", "--dimension", help="The dimension of the board", default="8x8")
undistort_parser.add_argument(
"-r", "--retain", help="Whether to retain pixels", action="store_true")
args = parser.parse_args()
try:
if args.command == "label":
label(args.path, args.format, args.output, args.dimension)
elif args.command == "undistort":
undistort(args.path, args.format, args.input,
args.output, args.dimension, args.retain)
except CamToolsError as e:
print(f'error: {e}')
exit(1)
if __name__ == "__main__":
main()