QRコードリーダーにトラブルがあったので、急遽RasberryPiカメラでQRコードを読むことにした。
まずは、QRコードを格納したイメージファイル test.jpg から、コードを抽出できるかどうか pythonプログラム で試してみます。
import zbar
import PIL.Image
file = 'test.jpg'
scanner = zbar.ImageScanner()
scanner.parse_config('enable')
# greyscale L
pil = PIL.Image.open(file).convert('L')
(width, height) = pil.size
# Return image as a bytes object
raw = pil.tobytes()
# The Y800 color format is an 8 bit monochrome format.
image = zbar.Image(width, height, 'Y800', raw)
# scan the image for barcodes
scanner.scan(image)
for symbol in image:
print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data
del(image)
次に、このシェルスクリプトで
#!/bin/bash
scan_worker=""
scan_card=""
QRcode="dummy"
while :
do
QRcode=`/var/www/html/qr_USBcamera_led.py $QRcode`
if [ ${#QRcode} -eq 6 ]; then
scan_worker=$QRcode
#echo "this is worker"
else
scan_card=$QRcode
#echo "this is card"
fi
if [ ${#scan_worker} -ne 0 ] && [ ${#scan_card} -ne 0 ]; then
scan_date=`date "+%Y/%m/%d/%k/%M/%S"`
scan_machine="in"
#echo "this is line data"
scan_line_data=${scan_date},${scan_worker},${scan_card},${scan_machine}
echo "$scan_line_data" >> /home/pi/scan_line_data.log
scp /home/pi/scan_line_data.log pi@192.168.1.137:/home/pi
scan_worker=""
scan_card=""
fi
done