Skip to content

Commit

Permalink
(qr) always show area percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthijsBurgh committed May 7, 2024
1 parent 3d7313e commit b2c5ea3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions hmi/scripts/qr_code_decoder
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def validate_image(qr_image: ndarray, qr_code_rect: tuple, threshold_percentage:
qr_code_percentage = (qr_code_area / qr_image.size) * 100

# Check if the QR code occupies at least threshold_percentage of the screen
rospy.loginfo(f"QR code occupies {qr_code_percentage:.2f}% of the screen.")
if qr_code_percentage >= threshold_percentage:
rospy.loginfo(f"QR code occupies {qr_code_percentage:.2f}% of the screen.")
return True

return False
Expand All @@ -42,7 +42,9 @@ class QRCodeDecode(AbstractHMIServer):
QRCodeDecode class for decoding QR codes.
"""

def __init__(self, name: str, max_tries: int = 5, loop_rate: float = 1.0, *args, **kwargs) -> None:
def __init__(
self, name: str, max_tries: int = 5, loop_rate: float = 1.0, percentage_threshold: int = 20, *args, **kwargs
) -> None:
super().__init__(name, *args, **kwargs)

# Image
Expand All @@ -56,6 +58,7 @@ class QRCodeDecode(AbstractHMIServer):
self._qr_code_data: Optional[str] = None

self._loop_rate: float = loop_rate
self._percentage_threshold: int = percentage_threshold

def _image_callback(self, msg: CompressedImage) -> None:
# Will be called every time a new image is received
Expand Down Expand Up @@ -111,7 +114,7 @@ class QRCodeDecode(AbstractHMIServer):

# Stores all QRs that occupy the required percentage of the screen
for qr_i in qr_list:
if validate_image(image, qr_i.rect):
if validate_image(image, qr_i.rect, self._percentage_threshold):
qr = qr_i
break

Expand Down

0 comments on commit b2c5ea3

Please sign in to comment.