Scanning barcodes with linux and a webcam
My Nokia phones can do it, so I thought there must be a way to do it on my laptop too. I wanted a way to scan both "traditional" barcodes and "two-dimensional" ones, like the QR-Codes. Here is my solution.
You'll need :
- a v4l-compatible webcam + mplayer compiled with v4l support (or any other scriptable way to grab frames from the webcam)
- a scriptable image viewer, I use feh on my laptop
- ZXing
Follow the instructions to build the ZXing javase component, then open three shell windows, and run:
shell1 (grab the webcam output as last.jpg +- every half second):
shell2 (view what you grabbed):
shell3 (scan for barcodes):
So no nice GUI, but it seems to work well.
You'll need :
- a v4l-compatible webcam + mplayer compiled with v4l support (or any other scriptable way to grab frames from the webcam)
- a scriptable image viewer, I use feh on my laptop
- ZXing
Follow the instructions to build the ZXing javase component, then open three shell windows, and run:
shell1 (grab the webcam output as last.jpg +- every half second):
cd /tmp ; while [ 0 ] ; do mplayer tv:// -fps 2 -tv driver=v4l:width=640:height=480:device=/dev/video0 -vo jpeg:quality=95 -frames 2 ; mv 00000001.jpg last.jpg ; done
shell2 (view what you grabbed):
cd /tmp ; feh -R 1/2 last.jpg
shell3 (scan for barcodes):
while [ 0 ] ; do ( java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner /tmp/last.jpg | fgrep -v 'No barcode found') ; sleep 1 ; done
So no nice GUI, but it seems to work well.