Skip to content

Commit

Permalink
feat(aruco): generate aruco markers
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasschaub committed Oct 29, 2024
1 parent 8bb6a7a commit 7d28814
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
10 changes: 10 additions & 0 deletions sketch_map_tool/map_generation/generate_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from io import BytesIO
from typing import Tuple

import cv2
import fitz
import reportlab.pdfgen.canvas
from PIL import Image as PILImage
Expand Down Expand Up @@ -412,3 +413,12 @@ def pdf_page_to_img(pdf: BytesIO, img_format, page_id=0) -> BytesIO:
page.get_pixmap().pil_save(img, format=img_format)
img.seek(0)
return img


# TODO: add typing
def get_aruco_markers():
dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_50)
markers = []
for i in range(4):
markers.append(cv2.aruco.generateImageMarker(dictionary, i, 400))
return markers
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
28 changes: 27 additions & 1 deletion tests/unit/test_map_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from uuid import uuid4

import pytest
from approvaltests import Options, verify_binary
from PIL import Image
from reportlab.graphics.shapes import Drawing
from reportlab.pdfgen import canvas
Expand All @@ -12,13 +13,16 @@
from sketch_map_tool.map_generation import qr_code as generate_qr_code
from sketch_map_tool.map_generation.generate_pdf import (
generate_pdf,
get_aruco_markers,
get_compass,
get_globes,
pdf_page_to_img,
)
from sketch_map_tool.models import PaperFormat
from tests import FIXTURE_DIR
from tests.unit.helper import save_test_file
from tests.namer import PytestNamerFactory
from tests.reporter import NDArrayReporter
from tests.unit.helper import save_test_file, serialize_ndarray


@pytest.fixture
Expand Down Expand Up @@ -131,3 +135,25 @@ def test_pdf_page_to_img(pdf):
assert True
except: # noqa
assert False


def test_get_aruco_makers():
markers = get_aruco_markers()
for i, m in enumerate(markers):
# NOTE: Uncomment to display markers
# import cv2
# cv2.imshow("Marker", m)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
# fmt: off
options = (
Options()
.with_reporter(NDArrayReporter())
.with_namer(PytestNamerFactory.with_parameters(i))
)
# fmt: on
verify_binary(
serialize_ndarray(m),
".npy",
options=options,
)

0 comments on commit 7d28814

Please sign in to comment.