
Premessa:
Con questo mini-tutorial sarete in grado di collegare una web-cam alla vostra Raspberry Pi e realizzare il vostro sistema di controllo Barcode e QRcode. Per prima cosa cominciamo con un update della nostra distro che non guasta mai:
sudo apt-get update
Una volta svolti i soliti aggiornamenti di routine andiamo a installare alcune librerie necessarie per il funzionamento della Lettura dei nostri codici a barre:
sudo apt-get install python-zbar sudo apt-get install zbar-tools
Vedremo due sketch python per realizzare il lettore. Nel primo esempio svolgerà una sola lettura mentre nel secondo rimarrà nel ciclo loop e potrete leggere vari codici.
read_one.py
#!/usr/bin/python
from sys import argv
import zbar
# create a Processor
proc = zbar.Processor()
# 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
proc = zbar.Processor()
# 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, e:
pass
Ora sarete in grado di leggere alcune delle più conosciute codifiche di Barcode e QRcode non vi resta che collegare una webcam alla porta USB.
Buon Progetto.




