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 location/position support #12

Merged
merged 3 commits into from
Mar 11, 2018

Conversation

globophobe
Copy link
Contributor

Should fix issue #11. Tests pass.

It's my first time using ctypes. Hopefully, there aren't any mistakes.

@coveralls
Copy link

coveralls commented Dec 9, 2017

Coverage Status

Coverage decreased (-0.1%) to 90.406% when pulling b36d7cf on globophobe:master into 372003b on NaturalHistoryMuseum:master.

@coveralls
Copy link

coveralls commented Dec 9, 2017

Coverage Status

Coverage increased (+0.5%) to 91.007% when pulling 4d0d092 on globophobe:master into 372003b on NaturalHistoryMuseum:master.

Copy link
Member

@quicklizard99 quicklizard99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good - thanks again for submitting this PR. I have made few suggestions for how to return a bounding box around barcodes. We could in future support returning the complete list of locations and/or computing a polygon around barcodes.

If you agree with these changes, the README and unit tests will need to be altered.


zbar_symbol_get_loc_x = zbar_function(
'zbar_symbol_get_loc_x',
c_uint,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My copy of zbar.h has the return type as int, which is represented by c_int. Could you check the type in your copy of the header?


zbar_symbol_get_loc_y = zbar_function(
'zbar_symbol_get_loc_y',
c_uint,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My copy of zbar.h has the return type as int, which is represented by c_int. Could you check the type in your copy of the header?

pyzbar/pyzbar.py Outdated
@@ -11,14 +11,15 @@
zbar_image_create, zbar_image_destroy, zbar_image_set_format,
zbar_image_set_size, zbar_image_set_data, zbar_scan_image,
zbar_image_first_symbol, zbar_symbol_get_data,
zbar_symbol_get_loc_size, zbar_symbol_get_loc_x, zbar_symbol_get_loc_y,
zbar_symbol_next, ZBarConfig, ZBarSymbol, EXTERNAL_DEPENDENCIES
)

__all__ = ['decode', 'EXTERNAL_DEPENDENCIES']


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest that we return a single rectangle that describes the bounding box around the detected barcode:

# A rectangle
Rect = namedtuple('Rect', ['left', 'top', 'width', 'height'])

 # Results of reading a barcode
Decoded = namedtuple('Decoded', ['data', 'type', 'rect'])

pyzbar/pyzbar.py Outdated
zbar_symbol_get_loc_x(symbol, l),
zbar_symbol_get_loc_y(symbol, l)
)
for l in range(loc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer xrange on Python 2.x . At the top of the module (or maybe within this function):

RANGEFN = getattr(globals(), 'xrange', range)

Alter range(loc) to RANGEFN(loc)

pyzbar/pyzbar.py Outdated
results.append(Decoded(
data=data,
type=symbol_type
type=symbol_type,
location=location
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with rect=bounding_box_of_locations(locations)

pyzbar/pyzbar.py Outdated
zbar_symbol_next, ZBarConfig, ZBarSymbol, EXTERNAL_DEPENDENCIES
)

__all__ = ['decode', 'EXTERNAL_DEPENDENCIES']


# Results of reading a barcode
Decoded = namedtuple('Decoded', ['data', 'type'])
Decoded = namedtuple('Decoded', ['data', 'type', 'location'])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A function to compute bounding boxes from scan locations (uses operator.itemgetter):

def bounding_box_of_locations(locations):
    x_values = list(map(itemgetter(0), locations))
    x_min, x_max = min(x_values), max(x_values)
    y_values = list(map(itemgetter(1), locations))
    y_min, y_max = min(y_values), max(y_values)
    return (Rect(x_min, y_min, x_max - x_min,  y_max - y_min))

pyzbar/pyzbar.py Outdated

location = []
loc = zbar_symbol_get_loc_size(symbol)
if loc:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious - does zbar_symbol_get_loc_size ever return 0? I have done some limited testing on Mac OS X and have always seen a non-zero return.

Return a bounding box around barcodes. Corrected mistakes with ctypes. Eliminated superfluous check of the result of zbar_symbol_get_loc_size function call, as well as the mess I introduced into tests.
@globophobe
Copy link
Contributor Author

Updated the pull request. Thank you for your suggestions.

@quicklizard99
Copy link
Member

Fantastic! Thanks for the very fast update @globophobe

@quicklizard99 quicklizard99 merged commit 1aa81f7 into NaturalHistoryMuseum:master Mar 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants