willglynn / ruby-zbar

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

Ruby 1.9 v 1.8? #1

Closed lawso017 closed 13 years ago

lawso017 commented 13 years ago

Thanks for a great library. Wer're having trouble transitioning from development (Rails 3.0.4/Ruby 1.8.7 on Snow Leopard) to our production environment (Gentoo Linux 10).

Long story short, we can't get FFI to play nicely with Ruby 1.8.7 on Gentoo 10.

So, we deployed our app server running zbar with Ruby 1.9.2, which does work with FFI on Gentoo. While everything loads and appears to run fine, our production app server is not recognizing any barcodes. No errors, no warnings, just no barcodes. The same images are readily recognized in the dev environment.

Use flags for zbar look like this:

[ebuild N ~] media-gfx/zbar-0.10 USE="imagemagick jpeg threads v4l v4l2 -X -gtk -python -qt4 -xv" 0 kB [1]

please verify that the detected configuration matches your expectations:

X --with-x=disabled pthreads --enable-pthread=yes v4l --enable-video=yes jpeg --with-jpeg=yes Magick++ --with-imagemagick=yes Python --with-python=no GTK+ --with-gtk=no => the GTK+ widget will NOT be built Qt4 --with-qt=no => the Qt4 widget will NOT be built

... any thoughts on possible version sensitivities between 1.8 and 1.9? Our implementation of zbar is almost too simple to troubleshoot:

def find_barcodes @image_file_barcodes = [] @image_files.each{ |jpg| @image_file_barcodes << ZBar::Image.from_jpeg(File.read(jpg)).process} update_status("In progress", "barcoded") end

Thanks for any suggestions...

willglynn commented 13 years ago

Hmm. Well, you have --with-jpeg, which IIRC is the only zbar flag ruby-zbar can notice. If FFI isn't exploding, either by raising exceptions or crashing, I'd guess that calls to zbar are happening properly, and that the failed detection has more to do with libzbar than the Ruby wrapper.

Five ideas:

  1. Call File.read(jpg, :binmode => true), instead of just File.read(jpg). By default, Ruby will treat it as text, and possibly garbling the bits as it changes encodings.
  2. Call Zbar.verbosity = 100, and see if you get anything on stderr.
  3. Cut out the JPEG -> Y800 step inside Zbar. Take an image that works in development but fails in production, convert it to .pgm ahead of time, and call ZBar::Image.from_pgm() instead.
  4. Try invoking the production copy of libzbar on the image without Ruby. zbar-0.10/examples/ contains some simple C/C++ binaries, and knowing if they work or not would help narrow down the issue.
  5. Upgrade your Mac to 1.9.2, at least for that project, using rvm. That's a good idea anyway, and would nail down any other 1.9 gotchas.

ruby-zbar works on 1.9.2, at least on my Mac, using the upstream barcode.png which I converted to PGM:

$ irb -rzbar
ruby-1.9.2-p180 :001 > pp ZBar::Image.from_pgm(File.open('barcode.pgm', 'rb')).process
[#<ZBar::Symbol:0x00000100aade20
  @addon="",
  @data="9876543210128",
...
lawso017 commented 13 years ago

Never mind -- in Ruby 1.8 we weren't explicitly reading the file as binary. Can't get away with that in 1.9!