diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 782bb5e..0cb14a8 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,6 +1,8 @@ name: Lint & build -on: [push] +on: + push: + workflow_dispatch: jobs: build: @@ -15,7 +17,7 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install .[dev,cli] - python -m pip install opencv-python-headless>=4.8 + python -m pip install 'opencv-python-headless>=4.8,<4.9' - name: Lint run: | make lint diff --git a/april_vision/cli/marker_generator/marker_modes/mode_cal.py b/april_vision/cli/marker_generator/marker_modes/mode_cal.py index 35c14dd..7bfa523 100644 --- a/april_vision/cli/marker_generator/marker_modes/mode_cal.py +++ b/april_vision/cli/marker_generator/marker_modes/mode_cal.py @@ -111,7 +111,7 @@ def main(args: argparse.Namespace) -> None: def create_subparser(subparsers: argparse._SubParsersAction) -> None: """Marker_generator subparser CAL_BOARD used to generate a calibration board.""" - parser = subparsers.add_parser("CAL_BOARD") + parser = subparsers.add_parser("CAL_BOARD", help="Generate a calibration board") parser.add_argument( "--page_size", diff --git a/april_vision/cli/marker_generator/marker_modes/mode_image.py b/april_vision/cli/marker_generator/marker_modes/mode_image.py index 27cc48e..93fd72f 100644 --- a/april_vision/cli/marker_generator/marker_modes/mode_image.py +++ b/april_vision/cli/marker_generator/marker_modes/mode_image.py @@ -44,7 +44,7 @@ def main(args: argparse.Namespace) -> None: def create_subparser(subparsers: argparse._SubParsersAction) -> None: """Marker_generator subparser IMAGE used to generate an image of a marker.""" - parser = subparsers.add_parser("IMAGE") + parser = subparsers.add_parser("IMAGE", help="Generate a bare marker as an image") parser.add_argument( "--marker_family", default=MarkerType.APRILTAG_36H11.value, diff --git a/april_vision/cli/marker_generator/marker_modes/mode_single.py b/april_vision/cli/marker_generator/marker_modes/mode_single.py index 3cdac2e..2b43042 100644 --- a/april_vision/cli/marker_generator/marker_modes/mode_single.py +++ b/april_vision/cli/marker_generator/marker_modes/mode_single.py @@ -1,5 +1,6 @@ import argparse import logging +from typing import Union from PIL import Image @@ -8,7 +9,8 @@ from ..marker_tile import MarkerTile from ..utils import (DEFAULT_COLOUR, DEFAULT_FONT, DEFAULT_FONT_SIZE, DPI, - PageSize, mm_to_pixels, parse_marker_ranges) + CustomPageSize, PageSize, mm_to_pixels, + parse_marker_ranges) LOGGER = logging.getLogger(__name__) @@ -20,7 +22,15 @@ def main(args: argparse.Namespace) -> None: marker_ids = parse_marker_ranges(tag_data, args.range) - page_size = PageSize[args.page_size] + page_size: Union[PageSize, CustomPageSize] + if args.page_size == 'CROPPED': + # Allow for an additional marker pixel border + required_width = args.marker_size * ( + (tag_data.total_width + 2) / tag_data.width_at_border + ) + page_size = CustomPageSize(required_width, required_width) + else: + page_size = PageSize[args.page_size] marker_pages = [] @@ -142,7 +152,7 @@ def main(args: argparse.Namespace) -> None: def create_subparser(subparsers: argparse._SubParsersAction) -> None: """Marker_generator subparser SINGLE used to generate a PDF of a marker.""" - parser = subparsers.add_parser("SINGLE") + parser = subparsers.add_parser("SINGLE", help="Generate a single marker per page") parser.add_argument( "--all_filename", @@ -166,7 +176,7 @@ def create_subparser(subparsers: argparse._SubParsersAction) -> None: "--page_size", type=str, help="Page size of output files (default: %(default)s)", - choices=sorted([size.name for size in PageSize]), + choices=sorted([size.name for size in PageSize] + ["CROPPED"]), default="A4", ) parser.add_argument( @@ -229,7 +239,7 @@ def create_subparser(subparsers: argparse._SubParsersAction) -> None: parser.add_argument( "--border_width", help="Size of the border in pixels (default: %(default)s)", - default=1, + default=4, type=int, ) parser.add_argument( @@ -241,7 +251,7 @@ def create_subparser(subparsers: argparse._SubParsersAction) -> None: parser.add_argument( "--tick_length", help="Length of center tick lines in pixels (default: %(default)s)", - default=10, + default=40, type=int, ) diff --git a/april_vision/cli/marker_generator/marker_modes/mode_tile.py b/april_vision/cli/marker_generator/marker_modes/mode_tile.py index 1c8b6d6..1c2b7dd 100644 --- a/april_vision/cli/marker_generator/marker_modes/mode_tile.py +++ b/april_vision/cli/marker_generator/marker_modes/mode_tile.py @@ -149,7 +149,7 @@ def create_subparser(subparsers: argparse._SubParsersAction) -> None: Marker_generator subparser TILE. Used to generate a PDF with multiple markers per page. """ - parser = subparsers.add_parser("TILE") + parser = subparsers.add_parser("TILE", help="Generate multiple markers per page") parser.add_argument( "--all_filename", @@ -230,7 +230,7 @@ def create_subparser(subparsers: argparse._SubParsersAction) -> None: parser.add_argument( "--border_width", help="Size of the border in pixels (default: %(default)s)", - default=1, + default=4, type=int, ) parser.add_argument( @@ -242,7 +242,7 @@ def create_subparser(subparsers: argparse._SubParsersAction) -> None: parser.add_argument( "--tick_length", help="Length of center tick lines in pixels (default: %(default)s)", - default=10, + default=40, type=int, ) diff --git a/april_vision/cli/marker_generator/utils.py b/april_vision/cli/marker_generator/utils.py index 5e0073c..0eef21f 100644 --- a/april_vision/cli/marker_generator/utils.py +++ b/april_vision/cli/marker_generator/utils.py @@ -2,7 +2,7 @@ from enum import Enum from typing import List, Tuple -from font_roboto import Roboto # type: ignore[import] +from font_roboto import Roboto # type: ignore[import,unused-ignore] from april_vision.cli.utils import ApriltagFamily, parse_ranges @@ -59,3 +59,19 @@ def pixels(self) -> Tuple[int, int]: mm_to_pixels(self.value[0]), mm_to_pixels(self.value[1]), ) + + +class CustomPageSize: + """ + Class to define a custom page size + """ + def __init__(self, width: int, height: int) -> None: + self.width = width + self.height = height + + @property + def pixels(self) -> Tuple[int, int]: + return ( + mm_to_pixels(self.width), + mm_to_pixels(self.height), + )