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

Cannot process jpeg image #5

Open
pzb opened this issue Jul 28, 2013 · 4 comments
Open

Cannot process jpeg image #5

pzb opened this issue Jul 28, 2013 · 4 comments

Comments

@pzb
Copy link

pzb commented Jul 28, 2013

I'm using the latest zbar from mercurial on sf.net. I can process a jpeg file using 'zbarimg bigstock-Barcode-18830351.jpg', but the following does not work:

    require 'zbar'
    jpeg = File.binread('bigstock-Barcode-18830351.jpg')
    z = ZBar::Image.from_jpeg(jpeg)
    r = z.process

z is #<ZBar::Image:0x00000001c55778 @img=#<FFI::AutoPointer address=0x000000021b8710>>, r is [], and no errors are generated.

I'm using http://www.geeknewscentral.com/wp-content/uploads/2012/12/bigstock-Barcode-18830351.jpg as the test image.

@willglynn
Copy link
Owner

Following these same steps, I get:

> r = z.process
 => [#<ZBar::Symbol:0x007fd63a869c60 @symbology="EAN-13", @data="9788679912077", @addon="", @quality=835, @location=[[819, 28], [463, 29], [130, 29], ...]>] 

Are you sure the zbar gem is loading the right libzbar.so? Try setting the ZBAR_LIB environment variable to its full path.

@pzb
Copy link
Author

pzb commented Jul 28, 2013

I'm sure it is loading the right libzbar:

irb(main):007:0> ZBar.ffi_libraries.map{|x|x.instance_variable_get(:@name)}
=> ["/usr/lib64/libzbar.so.0.2.0", "/usr/lib64/libzbar.so.0"]
[user@ip-10-0-0-119 ~]$ ldd `which zbarimg` | grep zbar
        libzbar.so.0 => /usr/lib64/libzbar.so.0 (0x00007f625b520000)

If I run convert bigstock-Barcode-18830351.jpg bigstock-Barcode-18830351.pgm and then use ZBar::Image.from_pgm, it processes the pgm image and decodes the barcode fine. So there is only a problem with jpegs.

@ArthurN
Copy link

ArthurN commented May 30, 2014

Almost a year later, I have this same problem. In my case, I'm on CentOS, and rebuilt the rpm from source, applying the patch provided here.

However, running the image directly through the zbarimg binary DOES work.

@pzb Did you ever resolve this, or just end up converting to PGM?

@arloan
Copy link

arloan commented Oct 11, 2018

It's may be a JPEG quality issue.

I got a .png QR Code image cropped from a scanner generated image, and zbarimg can read it. While when I use imagemagick convert it to .jpg, then zbar failed to read it. Convert it to .pgm, zbar reads it.

Finally, I convert it to .jpg via command: convert crop.png -quality 90 crop.jpg, then zbar can read the jpg file now.

bogon: ~/Downloads/VouchPic ]
stone$ zbarimg crop2.png
QR-Code:01,01,3400182130,00993210,1635.85,20180814,,4A08,
scanned 1 barcode symbols from 1 images in 0.01 seconds

bogon: ~/Downloads/VouchPic ]
stone$ convert crop2.png crop2.jpg
bogon: ~/Downloads/VouchPic ]
stone$ ruby -r zbar -e "p ZBar::Image.from_jpeg(File.binread('crop2.jpg')).process"
[]
bogon: ~/Downloads/VouchPic ]
stone$ convert crop2.png -quality 90 crop2.jpg
bogon: ~/Downloads/VouchPic ]
stone$ ruby -r zbar -e "p ZBar::Image.from_jpeg(File.binread('crop2.jpg')).process"
[#<ZBar::Symbol:0x00007ff6ce11cb10 @symbology="QR-Code", @data="01,01,3400182130,00993210,1635.85,20180814,,4A08,", @addon="", @quality=1, @location=[[20, 11], [17, 200], [211, 203], [212, 13]]>]
bogon: ~/Downloads/VouchPic ]
stone$ 

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

No branches or pull requests

4 participants