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.
Very use full. Is web cam works as scanner to read barcode?
ReplyDeletesegmentation fault error occurred when I tried this on Raspberry Pi
ReplyDeleteIt's common to use Qrcode anywhere, so to get the Qrcode reader to scan accurately, you have to use a good library.
ReplyDeleteHi Jim. Did you have success in any project with pi and bar code?
Delete