Skip to content

Commit

Permalink
Merge pull request #32 from WillB97/gen-tweaks
Browse files Browse the repository at this point in the history
Marker gen tweaks
  • Loading branch information
WillB97 authored Apr 6, 2024
2 parents 24b44a8 + a9eb0d6 commit 8fd9dd6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Lint & build

on: [push]
on:
push:
workflow_dispatch:

jobs:
build:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion april_vision/cli/marker_generator/marker_modes/mode_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 16 additions & 6 deletions april_vision/cli/marker_generator/marker_modes/mode_single.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import logging
from typing import Union

from PIL import Image

Expand All @@ -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__)

Expand All @@ -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 = []

Expand Down Expand Up @@ -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",
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
)

Expand Down
6 changes: 3 additions & 3 deletions april_vision/cli/marker_generator/marker_modes/mode_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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,
)

Expand Down
18 changes: 17 additions & 1 deletion april_vision/cli/marker_generator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
)

0 comments on commit 8fd9dd6

Please sign in to comment.