Skip to content

Commit

Permalink
fix: add decoding of legacy qr codes
Browse files Browse the repository at this point in the history
  • Loading branch information
itisacloud authored and matthiasschaub committed Dec 18, 2023
1 parent 1c4b0d8 commit cbaaf6f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions sketch_map_tool/upload_processing/qr_code_reader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Read QR codes from photos / scans
"""

import json
from types import MappingProxyType

import cv2
Expand Down Expand Up @@ -35,7 +35,10 @@ def read(img: NDArray, depth=0) -> MappingProxyType:
else:
raise QRCodeError("QR-Code could not be detected.")
case 1:
data = _decode_data(decoded_objects[0].data.decode())
try:
data = _decode_data(decoded_objects[0].data.decode())
except QRCodeError:
data = _decode_data_legacy(decoded_objects[0].data.decode())
try:
validate_uuid(data["uuid"])
except ValueError:
Expand All @@ -60,6 +63,19 @@ def _decode_data(data) -> MappingProxyType:
return MappingProxyType({"uuid": uuid, "bbox": bbox, "version": version_nr})


def _decode_data_legacy(data) -> MappingProxyType:
try:
contents = json.loads(data)
uuid = contents["id"]
version_nr = contents["version"]
bbox = Bbox(
*[float(coordinate) for coordinate in contents["bbox"].values()]
) # Raises ValueError for non-float values
except ValueError as error:
raise QRCodeError("QR-Code does not have expected content.") from error
return MappingProxyType({"uuid": uuid, "bbox": bbox, "version": version_nr})


def _resize(img, scale: float = 0.75):
width = int(img.shape[1] * scale)
height = int(img.shape[0] * scale)
Expand Down

0 comments on commit cbaaf6f

Please sign in to comment.