BREAKING NEWS

10 November 2015

Barcode reader and QRcode Example ZBar Python Raspberry Pi


Foreword:
With this mini-tutorial will be able to connect a webcam to your Raspberry Pi and realize your control system and barcode QRcode. First let's start with an update of our distro that never hurts:
sudo apt-get update
Once carried out the usual routine updates go to install some libraries needed for the operation of the reading of our barcode:
sudo apt-get install python-zbar
sudo apt-get install zbar-tools
We will see two Python sketch to make the reader. In the first example will be a read-only while the second will remain in the cycle loop and you can read various codes.
read_one.py
#! / Usr / bin / python
from sys import argv
import zbar

# Create a Processor
zbar.Processor = proc ()

# Configure the Processor
proc.parse_config ('enable')

# Initialize the Processor
device = '/ dev / video0'
if len (argv)> 1:
    device = argv [1]
proc.init (device)

# Enable the preview window
proc.visible = True

# Read at least one barcode (or until window closed)
proc.process_one ()

# Hide the preview window
proc.visible = False

# Extract results
for symbol in proc.results:
    # Do something useful with results
    print 'decoded', symbol.type, 'symbol', '"% s"'% symbol.data
processor.py
#! / Usr / bin / python
from sys import argv
import zbar

# Create a Processor
zbar.Processor = proc ()

# Configure the Processor
proc.parse_config ('enable')

# Initialize the Processor
device = '/ dev / video0'
if len (argv)> 1:
    device = argv [1]
proc.init (device)

# Setup a callback
def my_handler (proc, image, closure):
    # Extract results
    for symbol in image.symbols:
        # Do something useful with results
        print 'decoded', symbol.type, 'symbol', '"% s"'% symbol.data

proc.set_data_handler (my_handler)

# Enable the preview window
proc.visible = True

# Initiate scanning
proc.active = True
try:
    # Keep scanning until user Provides key / mouse input
    proc.user_wait ()
except zbar.WindowClosed, and:
    pass
Now you'll be able to read some of the best known encodings QRcode Barcode and you just need to connect a webcam to the USB port.

Share this:

4 comments :

  1. Very use full. Is web cam works as scanner to read barcode?

    ReplyDelete
  2. segmentation fault error occurred when I tried this on Raspberry Pi

    ReplyDelete
  3. It's common to use Qrcode anywhere, so to get the Qrcode reader to scan accurately, you have to use a good library.

    ReplyDelete
    Replies
    1. Hi Jim. Did you have success in any project with pi and bar code?

      Delete

 
Back To Top
Distributed By Blogger Templates | Designed By OddThemes