Table of Contents
Decoding and scannig barcode with webcam
Zbar installation
First, you´ll need to install zbar packages and their python bindings.
$ sudo apt-get install libzbar-dev zbar-tools python-zbar
Now, you can run zbarcam directly from the terminal
$ zbarcam /dev/video0
This will open a window that displays the video input on your webcam, you'll need to bring the barcode to the camera and the program automatically will detect this and decode
Run Zbar from python script
First, we import the zbar module for python, to access its various classes and methods
> import zbar
Now we'll call the processor class, this class may be used to quickly create stand-alone bar code scanning applications. It has interfaces to scan images or video and to optionally display a video/image preview to a window.
> proc = zbar.Processor()
Then we will use the methodo parse_config inherited from class Processor to active the default configuration
> proc.parse_config('enable')
What follows now is to initialize the process with the init method. For this you must specify the video device to open and whether the preview window should be available.
> device = '/dev/video0' > proc.init(device)
Now, we'll show the display window and call the method process_one() to scan until at least one barcode is found. After this is found, hide the window
>proc.visible = True >proc.process_one() >proc.visible = False
Finally, we must extract the results
>for symbol in proc.results: > print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data
Note that previous lines “results” method is invoked. This method return a list ZBarSymbol results from the last scanned image or video frame.
For more detailed information about the classes and methods of the module zbar you can see the following sites
http://zbar.sourceforge.net/api/annotated.html
http://search.cpan.org/~spadix/Barcode-ZBar/