From 2037627653b06739416f893b35b0dc96dcc265dc Mon Sep 17 00:00:00 2001 From: Caleb Powell Date: Mon, 22 Jul 2019 15:27:15 -0400 Subject: [PATCH 1/2] included x & y density configs in decode() --- pyzbar/pyzbar.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pyzbar/pyzbar.py b/pyzbar/pyzbar.py index ae44367..185b3e4 100644 --- a/pyzbar/pyzbar.py +++ b/pyzbar/pyzbar.py @@ -167,13 +167,21 @@ def _pixel_data(image): return pixels, width, height -def decode(image, symbols=None): +def decode(image, symbols=None, x_density=None, y_density=None): """Decodes datamatrix barcodes in `image`. Args: image: `numpy.ndarray`, `PIL.Image` or tuple (pixels, width, height) symbols: iter(ZBarSymbol) the symbol types to decode; if `None`, uses `zbar`'s default behaviour, which is to decode all symbol types. + + x_density: int, controls the number of pixel rows (columns) that are + skipped between successive horizontal (vertical) scan passes. + A value of 0 completely disables scanning in this direction. + + y_density: int, controls the number of pixel rows (columns) that are + skipped between successive horizontal (vertical) scan passes. + A value of 0 completely disables scanning in this direction. Returns: :obj:`list` of :obj:`Decoded`: The values decoded from barcodes. @@ -195,7 +203,21 @@ def decode(image, symbols=None): # them. for symbol in symbols: zbar_image_scanner_set_config( - scanner, symbol, ZBarConfig.CFG_ENABLE, 1 + scanner, symbol, ZBarConfig.CFG_ENABLE, 0 + ) + # attempt to disable scan density for x axis + # http://zbar.sourceforge.net/iphone/sdkdoc/optimizing.html#limit-the-scan-density + # note, the 2nd param seems specific to symbology. Just setting it to 0 + if x_density is not None: + zbar_image_scanner_set_config( + scanner, 0, ZBarConfig.CFG_X_DENSITY, x_density + ) + # attempt to disable scan density for y axis + # http://zbar.sourceforge.net/iphone/sdkdoc/optimizing.html#limit-the-scan-density + # note, the 2nd param seems specific to symbology. Just setting it to 0 + if y_density is not None: + zbar_image_scanner_set_config( + scanner, 0, ZBarConfig.CFG_Y_DENSITY, y_density ) with _image() as img: zbar_image_set_format(img, _FOURCC['L800']) From 2b12b686079bee0500e438783d103a17b2a5bdf3 Mon Sep 17 00:00:00 2001 From: Klaas Jelmer Boskma Date: Fri, 18 Sep 2020 13:01:07 +0200 Subject: [PATCH 2/2] Support decoding of binary QR codes, update ZBarConfig enum to follow ZBar 0.23 field order --- pyzbar/pyzbar.py | 7 ++++++- pyzbar/wrapper.py | 24 +++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pyzbar/pyzbar.py b/pyzbar/pyzbar.py index ae44367..8688043 100644 --- a/pyzbar/pyzbar.py +++ b/pyzbar/pyzbar.py @@ -167,13 +167,14 @@ def _pixel_data(image): return pixels, width, height -def decode(image, symbols=None): +def decode(image, symbols=None, binary=False): """Decodes datamatrix barcodes in `image`. Args: image: `numpy.ndarray`, `PIL.Image` or tuple (pixels, width, height) symbols: iter(ZBarSymbol) the symbol types to decode; if `None`, uses `zbar`'s default behaviour, which is to decode all symbol types. + binary: bool If true, do not convert binary data to text Returns: :obj:`list` of :obj:`Decoded`: The values decoded from barcodes. @@ -197,6 +198,10 @@ def decode(image, symbols=None): zbar_image_scanner_set_config( scanner, symbol, ZBarConfig.CFG_ENABLE, 1 ) + + if binary: + zbar_image_scanner_set_config(scanner, 0, ZBarConfig.CFG_BINARY, 1) + with _image() as img: zbar_image_set_format(img, _FOURCC['L800']) zbar_image_set_size(img, width, height) diff --git a/pyzbar/wrapper.py b/pyzbar/wrapper.py index 4867220..cc12373 100644 --- a/pyzbar/wrapper.py +++ b/pyzbar/wrapper.py @@ -63,21 +63,23 @@ class ZBarSymbol(IntEnum): @unique class ZBarConfig(IntEnum): - CFG_ENABLE = 0 # /**< enable symbology/feature */ - CFG_ADD_CHECK = 1 # /**< enable check digit when optional */ - CFG_EMIT_CHECK = 2 # /**< return check digit when present */ - CFG_ASCII = 3 # /**< enable full ASCII character set */ - CFG_NUM = 4 # /**< number of boolean decoder configs */ + CFG_ENABLE = 0 # /**< enable symbology/feature */ + CFG_ADD_CHECK = 1 # /**< enable check digit when optional */ + CFG_EMIT_CHECK = 2 # /**< return check digit when present */ + CFG_ASCII = 3 # /**< enable full ASCII character set */ + CFG_BINARY = 4, # /**< don't convert binary data to text */ + CFG_NUM = 5 # /**< number of boolean decoder configs */ - CFG_MIN_LEN = 0x20 # /**< minimum data length for valid decode */ - CFG_MAX_LEN = 0x21 # /**< maximum data length for valid decode */ + CFG_MIN_LEN = 0x20 # /**< minimum data length for valid decode */ + CFG_MAX_LEN = 0x21 # /**< maximum data length for valid decode */ - CFG_UNCERTAINTY = 0x40 # /**< required video consistency frames */ + CFG_UNCERTAINTY = 0x40 # /**< required video consistency frames */ - CFG_POSITION = 0x80 # /**< enable scanner to collect position data */ + CFG_POSITION = 0x80 # /**< enable scanner to collect position data */ + CFG_TEST_INVERTED = 0x81 # /**< if fails to decode, test inverted * / - CFG_X_DENSITY = 0x100 # /**< image scanner vertical scan density */ - CFG_Y_DENSITY = 0x101 # /**< image scanner horizontal scan density */ + CFG_X_DENSITY = 0x100 # /**< image scanner vertical scan density */ + CFG_Y_DENSITY = 0x101 # /**< image scanner horizontal scan density */ # Structs