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

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

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

Why do not you register as a user and use Qiita more conveniently?
  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
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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