Help us understand the problem. What is going on with this article?

QRコードをRaspberryPiカメラで読む

More than 1 year has passed since last update.

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

nanbuwks
iotlt
IoT縛りの勉強会です。 毎月イベントを実施しているので是非遊びに来てください! 登壇者を中心にQiitaでも情報発信していきます。 https://iotlt.connpass.com
https://iotlt.connpass.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away