From dad6b9921ab857d1fe3d2c70db5d28129fca4435 Mon Sep 17 00:00:00 2001 From: Denver A Date: Fri, 15 May 2020 16:05:28 +0200 Subject: [PATCH 1/2] Add a points member to the Decoded tuple This is an attempt to address #57 by also including the unmodified symbol points without breaking compatibility. --- pyzbar/pyzbar.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pyzbar/pyzbar.py b/pyzbar/pyzbar.py index ae44367..dac7fac 100644 --- a/pyzbar/pyzbar.py +++ b/pyzbar/pyzbar.py @@ -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 = { @@ -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)) ) From ac9fbf46936d5bd495a765e472dd88d6addac419 Mon Sep 17 00:00:00 2001 From: Denver A Date: Fri, 15 May 2020 17:31:38 +0200 Subject: [PATCH 2/2] Update tests --- pyzbar/tests/test_pyzbar.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/pyzbar/tests/test_pyzbar.py b/pyzbar/tests/test_pyzbar.py index 683f7e0..f56f9f8 100644 --- a/pyzbar/tests/test_pyzbar.py +++ b/pyzbar/tests/test_pyzbar.py @@ -3,6 +3,8 @@ from pathlib import Path +from pyzbar.locations import Point + try: from unittest.mock import patch except ImportError: @@ -23,7 +25,6 @@ ) from pyzbar.pyzbar_error import PyZbarError - TESTDATA = Path(__file__).parent @@ -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)] ) ] @@ -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)] ) ] @@ -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):