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

Add a points member to the Decoded tuple #78

Open
wants to merge 2 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
13 changes: 7 additions & 6 deletions pyzbar/pyzbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
]


Decoded = namedtuple('Decoded', ['data', 'type', 'rect', 'polygon'])
Decoded = namedtuple('Decoded', ['data', 'type', 'rect', 'polygon', 'points'])

# ZBar's magic 'fourcc' numbers that represent image formats
_FOURCC = {
Expand Down Expand Up @@ -100,19 +100,20 @@ def _decode_symbols(symbols):
data = string_at(zbar_symbol_get_data(symbol))
# The 'type' int in a value in the ZBarSymbol enumeration
symbol_type = ZBarSymbol(symbol.contents.type).name
polygon = convex_hull(
point_tuples = [
(
zbar_symbol_get_loc_x(symbol, index),
zbar_symbol_get_loc_y(symbol, index)
)
for index in _RANGEFN(zbar_symbol_get_loc_size(symbol))
)
) for index in _RANGEFN(zbar_symbol_get_loc_size(symbol))]

polygon = convex_hull(point_tuples)

yield Decoded(
data=data,
type=symbol_type,
rect=bounding_box(polygon),
polygon=polygon
polygon=polygon,
points=list(map(Point._make, point_tuples))
)


Expand Down
34 changes: 28 additions & 6 deletions pyzbar/tests/test_pyzbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from pathlib import Path

from pyzbar.locations import Point

try:
from unittest.mock import patch
except ImportError:
Expand All @@ -23,7 +25,6 @@
)
from pyzbar.pyzbar_error import PyZbarError


TESTDATA = Path(__file__).parent


Expand All @@ -33,13 +34,31 @@ class TestDecode(unittest.TestCase):
data=b'Foramenifera',
type='CODE128',
rect=Rect(left=37, top=550, width=324, height=76),
polygon=[(37, 551), (37, 625), (361, 626), (361, 550)]
polygon=[(37, 551), (37, 625), (361, 626), (361, 550)],
points=[(361, 550), (37, 551), (361, 552), (37, 553), (361, 554), (37, 555), (361, 556), (37, 557),
(361, 558), (37, 559), (361, 560), (37, 561), (361, 562), (37, 563), (361, 564), (37, 565),
(361, 566), (37, 567), (361, 568), (37, 569), (361, 570), (37, 571), (361, 572), (37, 573),
(361, 574), (37, 575), (361, 576), (37, 577), (361, 578), (37, 579), (361, 580), (37, 581),
(361, 582), (37, 583), (361, 584), (37, 585), (361, 586), (37, 587), (361, 588), (37, 589),
(361, 590), (37, 591), (361, 592), (37, 593), (361, 594), (37, 595), (361, 596), (37, 597),
(361, 598), (37, 599), (361, 600), (37, 601), (361, 602), (37, 603), (361, 604), (37, 605),
(361, 606), (37, 607), (361, 608), (37, 609), (361, 610), (37, 611), (361, 612), (37, 613),
(361, 614), (37, 615), (361, 616), (37, 617), (361, 618), (37, 619), (361, 620), (37, 621),
(361, 622), (37, 623), (361, 624), (37, 625), (361, 626)]
),
Decoded(
data=b'Rana temporaria',
type='CODE128',
rect=Rect(left=4, top=0, width=390, height=76),
polygon=[(4, 1), (4, 75), (394, 76), (394, 0)]
polygon=[(4, 1), (4, 75), (394, 76), (394, 0)],
points=[(394, 0), (4, 1), (394, 2), (4, 3), (394, 4), (4, 5), (394, 6), (4, 7), (394, 8), (4, 9), (394, 10),
(4, 11), (394, 12), (4, 13), (394, 14), (4, 15), (394, 16), (4, 17), (394, 18), (4, 19), (394, 20),
(4, 21), (394, 22), (4, 23), (394, 24), (4, 25), (394, 26), (4, 27), (394, 28), (4, 29), (394, 30),
(4, 31), (394, 32), (4, 33), (394, 34), (4, 35), (394, 36), (4, 37), (394, 38), (4, 39), (394, 40),
(4, 41), (394, 42), (4, 43), (394, 44), (4, 45), (394, 46), (4, 47), (394, 48), (4, 49), (394, 50),
(4, 51), (394, 52), (4, 53), (394, 54), (4, 55), (394, 56), (4, 57), (394, 58), (4, 59), (394, 60),
(4, 61), (394, 62), (4, 63), (394, 64), (4, 65), (394, 66), (4, 67), (394, 68), (4, 69), (394, 70),
(4, 71), (394, 72), (4, 73), (394, 74), (4, 75), (394, 76)]
)
]

Expand All @@ -48,7 +67,8 @@ class TestDecode(unittest.TestCase):
b'Thalassiodracon',
type='QRCODE',
rect=Rect(left=27, top=27, width=145, height=145),
polygon=[(27, 27), (27, 172), (172, 172), (172, 27)]
polygon=[(27, 27), (27, 172), (172, 172), (172, 27)],
points=[(27, 27), (27, 172), (172, 172), (172, 27)]
)
]

Expand All @@ -58,12 +78,14 @@ class TestDecode(unittest.TestCase):
data=b'Thalassiodracon',
type='QRCODE',
rect=Rect(left=173, top=10, width=205, height=205),
polygon=[(173, 113), (276, 215), (378, 113), (276, 10)]),
polygon=[(173, 113), (276, 215), (378, 113), (276, 10)],
points=[(276, 10), (173, 113), (276, 215), (378, 113)]),
Decoded(
data=b'Thalassiodracon',
type='QRCODE',
rect=Rect(left=32, top=208, width=158, height=158),
polygon=[(32, 352), (177, 366), (190, 222), (46, 208)])
polygon=[(32, 352), (177, 366), (190, 222), (46, 208)],
points=[(190, 222), (46, 208), (32, 352), (177, 366)])
]

def setUp(self):
Expand Down