From 970a169270d9304bd7b9ab88fef7d571cc890a97 Mon Sep 17 00:00:00 2001 From: terrtia Date: Thu, 3 Oct 2024 09:24:42 +0200 Subject: [PATCH] fix: [qrcode extractor] fix catch cv2 exception --- bin/modules/QrCodeReader.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/bin/modules/QrCodeReader.py b/bin/modules/QrCodeReader.py index fa82852a..6a8a863a 100755 --- a/bin/modules/QrCodeReader.py +++ b/bin/modules/QrCodeReader.py @@ -69,16 +69,22 @@ class QrCodeReader(AbstractModule): if not contents: detector = cv2.QRCodeDetector() - qr, decodeds, qarray, _ = detector.detectAndDecodeMulti(image) - if qr: - qr_codes = True - for d in decodeds: - if d: - contents.append(d) - data_qr, box, qrcode_image = detector.detectAndDecode(image) - if data_qr: - contents.append(data_qr) - qr_codes = True + try: + qr, decodeds, qarray, _ = detector.detectAndDecodeMulti(image) + if qr: + qr_codes = True + for d in decodeds: + if d: + contents.append(d) + except cv2.error as e: + self.logger.error(f'{e}: {self.obj.get_global_id()}') + try: + data_qr, box, qrcode_image = detector.detectAndDecode(image) + if data_qr: + contents.append(data_qr) + qr_codes = True + except cv2.error as e: + self.logger.error(f'{e}: {self.obj.get_global_id()}') if qr_codes and not contents: # # # # 0.5s per image