willglynn / ruby-zbar

Ruby bindings for the ZBar barcode recognition library
MIT License
83 stars 24 forks source link

only search for specific symbology? #4

Closed philister closed 11 years ago

philister commented 11 years ago

Hi,

great gem!

Is there a possibility to search only for (lets say) QR-Codes?

Thanks and regards, Phil

willglynn commented 11 years ago

The underlying zbar library supports configuration values. This isn't currently plumbed into the zbar gem, but I could add that without too much effort. The API currently allows you to check the symbology of the resulting ZBar::Symbol objects:

symbols = image.process
qrcodes = symbols.select { |symbol| symbol.symbology == "qrcode" }
philister commented 11 years ago

Thank you for this explanation. Currently I "filter" the symbology afterwards (after process). But I bet, the search would be faster, if it had to search for a specific symbology. You know what I mean? Would be great to have this feature, because at least in my case, I know, what symbology I'm looking for.

willglynn commented 11 years ago

All right, I'll take a whack at this :-)

Would you happen to have an image containing barcodes with more than one symbology that you'd like to contribute to the test suite?

willglynn commented 11 years ago

As of the current master:

> ZBar::Image.from_jpeg(File.open("spec/support/test.jpg", "rb")).process(:symbology => "qrcode")
 => [] 
> ZBar::Image.from_jpeg(File.open("spec/support/test.jpg", "rb")).process(:symbology => "ean13")
 => [#<ZBar::Symbol:... @symbology="EAN-13", @data="9876543210128", ...>] 

I want to do a couple other things first, but this will be released as 0.2.0.

willglynn commented 11 years ago

zbar-0.2.0 has been released, containing this functionality, a rewritten test suite, Travis CI, as well as a runtime check for the zbar JPEG issue behind #2.

philister commented 11 years ago

Wow, awesome! Thank you a lot. It works well und improves the performance of my code-detection significantly.