forked from rijinmk/code-qr-code-reader-rpi3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader.py
51 lines (37 loc) · 978 Bytes
/
reader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import time
import picamera
import zbarlight
import os
import sys
import PIL
import numpy as np
def get_image():
with picamera.PiCamera() as camera:
camera.resolution = (1024, 768)
camera.start_preview()
# Camera warm-up time
time.sleep(2)
camera.capture('foo.jpg')
print ('Taking picture..')
try:
f = 1
#qr_count = len(os.listdir('qr_codes'))
get_image()
#os.system('sudo fswebcam -d /dev/video'+sys.argv[1]+' -q qr_codes/qr_'+str(qr_count)+'.jpg')
print ('Picture taken..')
except Exception as e:
f = 0
print ('Picture couldn\'t be taken with exception ' + str(e))
print
if(f):
print ('Scanning image..')
f = open('foo.jpg','rb')
qr = PIL.Image.open(f);
qr.load()
codes = zbarlight.scan_codes('qrcode',qr)
if(codes==None):
#os.remove('qr_codes/qr_'+str(qr_count)+'.jpg')
print ('No QR code found')
else:
print( 'QR code(s):')
print (codes)