-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.py
38 lines (35 loc) · 941 Bytes
/
scan.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
import io
import time
import picamera
from PIL import Image
import pyzbar.pyzbar as pyzbar
import requests
while(True):
stream = io.BytesIO()
with picamera.PiCamera() as camera:
camera.start_preview()
time.sleep(2)
camera.capture(stream, format='jpeg')
# "Rewind" the stream to the beginning so we can read its content
stream.seek(0)
pil = Image.open(stream)
#
#########################################
#
# create a reader
texts = pyzbar.decode(pil)
if len(texts) == 0:
print('NO QRcode!')
else:
for text in texts:
tt = text.data.decode("utf-8")
print(tt)
r = requests.get('http://' + tt)
print('status = ', r.status_code)
if r.status_code == requests.codes.ok:
print("OK")
print('text = ', r.text)
# clean up
del(pil)
camera.close()
del(camera)