From a62d6b71269ad8176ebb1baba99d63346fae4a40 Mon Sep 17 00:00:00 2001 From: Jan Domanski Date: Sat, 20 Jul 2024 14:30:31 +0100 Subject: [PATCH 1/2] further fixes --- qreader.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/qreader.py b/qreader.py index 8fbba5e..c162751 100644 --- a/qreader.py +++ b/qreader.py @@ -41,8 +41,11 @@ ("shift-jis", "big5") if os.name == "nt" else ("big5", "shift-jis") ) +from numpy.typing import NDArray + CorrectionsType = typing.Literal["cropped_bbox", "corrected_perspective"] FlavorType = typing.Literal["original", "inverted", "grayscale"] +ReencodeToType = typing.Union[str, typing.Sequence[str], None] @dataclass(frozen=True) @@ -82,7 +85,7 @@ def __init__( self, model_size: str = "s", min_confidence: float = 0.5, - reencode_to: str | tuple[str, ...] | list[str] | None = DEFAULT_REENCODINGS, + reencode_to: ReencodeToType = DEFAULT_REENCODINGS, weights_folder: str | None = None, ): """ @@ -119,7 +122,7 @@ def __init__( assert isinstance( reencode_to, (tuple, list) ), f"reencode_to must be a str, tuple, list or None. Got {type(reencode_to)}" - self.reencode_to = reencode_to + self.reencode_to = tuple(reencode_to) def detect( self, image: np.ndarray, is_bgr: bool = False @@ -331,7 +334,7 @@ def _decode_qr_zbar( results=decodedQR, ) # For QRs with black background and white foreground, try to invert the image - inverted_image = image = 255 - rescaled_image + inverted_image: NDArray[np.generic] = 255 - rescaled_image decodedQR = decodeQR(inverted_image, symbols=[ZBarSymbol.QRCODE]) if len(decodedQR) > 0: return wrap( From cf081bfa603ca9d2c7cdf74ed2cf8093777be504 Mon Sep 17 00:00:00 2001 From: Jan Domanski Date: Wed, 24 Jul 2024 13:07:23 +0100 Subject: [PATCH 2/2] update qreader.py --- qreader.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/qreader.py b/qreader.py index c162751..edaab4b 100644 --- a/qreader.py +++ b/qreader.py @@ -196,12 +196,10 @@ def decode( def detect_and_decode( self, image: np.ndarray, return_detections: bool = False, is_bgr: bool = False - ) -> ( - tuple[ - dict[str, np.ndarray | float | tuple[float | int, float | int]], str | None - ] - | tuple[str | None, ...] - ): + ) -> typing.Tuple[ + typing.Tuple[str | None, ...], + tuple[dict[str, np.ndarray | float | tuple[float | int, float | int]]] | None, + ]: """ This method will decode the **QR** codes in the given image and return the decoded strings (or None, if any of them was detected but not decoded). @@ -227,7 +225,7 @@ def detect_and_decode( if return_detections: return decoded_qrs, detections else: - return decoded_qrs + return decoded_qrs, None def get_detection_result_from_polygon( self, @@ -334,7 +332,7 @@ def _decode_qr_zbar( results=decodedQR, ) # For QRs with black background and white foreground, try to invert the image - inverted_image: NDArray[np.generic] = 255 - rescaled_image + inverted_image = np.array(255) - rescaled_image decodedQR = decodeQR(inverted_image, symbols=[ZBarSymbol.QRCODE]) if len(decodedQR) > 0: return wrap(