Installing and using ZBar in Linux to scan bar codes with your Webcam
October 5, 2012 7 Comments
ZBar is an application that can scan and decode several bar code symbologies (including QR Code) from sources such as a Webcam or an image file. I had been wanting to install it for some time and was finally spurred on to do it by a request for help to get it working in the Sabayon Linux forums. Here are the steps I used.
1. I installed the package media-gfx/zbar-0.10-r1
.
Note for Gentoo users: I merged the package with the imagemagick
and v4l
USE flags set, so that both zbarimg
and zbarcam
would be installed. If you only want to use ZBar with a Webcam then turn off the imagemagick
flag and zbarimg
will not be installed.
Note for Sabayon Linux users: The Entropy package was built with both the above-mentioned USE flags set, so zbarimg
and zbarcam
will be installed.
2. Then I checked the status of the installed package by using the Portage eix
command:
$ eix -I zbar
[I] media-gfx/zbar
Available versions: (~)0.10-r1 {{X gtk imagemagick jpeg python qt4 static-libs +threads v4l xv}}
Installed versions: 0.10-r1(03:56:14 05/10/12)(X gtk imagemagick jpeg qt4 threads v4l xv -python -static-libs)
Homepage: http://zbar.sourceforge.net/
Description: Library and tools for reading barcodes from images or video
Sabayon Linux users could instead use the following command:
$ equo search --verbose zbar
3. Then I checked which video device my laptop’s inbuilt Webcam is:
$ ls /dev/video*
/dev/video0
4. As it is /dev/video0
, I launched zbarcam
as follows:
$ zbarcam --raw /dev/video0
WARNING: no compatible input to output format
...trying again with output disabled
ERROR: zbar processor in zbar_processor_init():
unsupported request: no compatible image format
Clearly zbarcam
was not recognising the Webcam.
5. As I had installed the package with the Video4Linux USE flag set, I then launched zbarcam
with the following prefix:
$ LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so zbarcam --raw /dev/video0
The ZBar GUI window popped up and I could see myself in the window. So far, so good.
6. I held a QR Code 2D bar code in front of the Webcam, then held a 1D Interleaved 2 of 5 bar code in front of the Webcam. The following was displayed:
$ LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so zbarcam --raw /dev/video0
http://roho.it/mryt
0161223563
Both the QR Code and the I2of5 bar code were read correctly. If the --raw
parameter is omitted then zbarcam
displays the symbology of the bar code too:
$ LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so zbarcam /dev/video0
QR-Code:http://roho.it/mryt
I2/5:0161223563
7. Then I tried using ZBar to read a bar code which I had previously saved as a .jpg
file:
$ zbarimg --raw ~/zebra04.jpg
01234565
scanned 1 barcode symbols from 1 images in 0.04 seconds
$ zbarimg ~/zebra04.jpg
EAN-8:01234565
scanned 1 barcode symbols from 1 images in 0.04 seconds
To find out the other parameters available, use the commands:
$ man zbarcam
$ zbarcam --help
$ man zbarimg
$ zbarimg --help
ZBar is a nice tool. 😎
Reblogged this on anthonyvenable110 and commented:
cool
Its really a nice tool, i will try this on my laptop 🙂
Please take a look on my blog http://linuxexplore.com
Thanks
This worked great for me. Thank you. I’m also using Gentoo.
Pingback: How to create QR Codes easily in Gentoo Linux | Fitzcarraldo's Blog
Pingback: More tools for creating QR Codes in Linux | Fitzcarraldo's Blog
its only a toy, has a good scan-quality(!) and is nothwithstanding nearly unuseable for professional use, because it doesn’t stop. So you can only write the barcode (a whole bunch of them) but you can’t get timestamps in the same step – and get a line-identity-problem that way.
The problem is:
zbarcam is going asleep between his single (very short) scan-activities – so you can’t kill it from script, because its “S” (=> ps ax) – holy cra* )
the solution: take the sourcecode of tbarcam, erase the loop-function and compile new: working “1 step scan – then quit”, so you can it use in a script: “scan 1 step, add the timestamp, quit, again …”
a second workaround is: go kill it after every single scan by the KDE-Konsole-ringtone – use a kill-script instead the ringtone …
or: tailoring some with kdedialog
Is this still linux?
No way!
Thats b* sh*!
Jo
Reading barcodes with a USB webcam on Linux?
OK. Follow these steps…
First, installed Zbar and a little program called “crikey”. The easy way. Open a terminal and type in:
sudo apt-get install zbar-tools
sudo apt-get install libx11-dev x11proto-xext-dev libxt-dev libxtst-dev
wget http://www.shallowsky.com/software/crikey/crikey-0.8.3.tar.gz
tar -xzf crikey-0.8.3.tar.gz
cd crikey-0.8.3
make
sudo cp crikey /usr/local/bin
cd
clear
clear
Now hook up your USB webcam.
Is your USB webcam supported by V4L1 (Video4Linux1)? Then, open again a terminal and type in:
LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so zbarcam –raw –prescale=320×240 /dev/video1 | crikey -i
Now open Google or a Gedit instance, clic inside the search box, and put a barcode in front of your USB webcam. Focus in the barcode, as necessary. You will get the barcode number where you have clicked on before…
Is your USB webcam supported by V4L2 (Video4Linux2)? Then, open a terminal and type in:
zbarcam –raw –prescale=320×240 /dev/video0 | crikey -i
If the above commands don’t work, try “video1”, instead of “video0”