Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support decoding of binary QR codes #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions pyzbar/pyzbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,24 @@ def _pixel_data(image):
return pixels, width, height


def decode(image, symbols=None):
def decode(image, symbols=None, binary=False, 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.

binary: bool If true, do not convert binary data to text

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.
"""
Expand All @@ -195,8 +205,26 @@ 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
)

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)
Expand Down
24 changes: 13 additions & 11 deletions pyzbar/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down