Created
November 28, 2018 07:56
-
-
Save rudrathegreat/a63eb0e4112457609d69a06ec8a07e0e to your computer and use it in GitHub Desktop.
QR Code Reader For the Raspberry Pi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
from PIL import Image | |
import zbarlight | |
import pygame, sys | |
from pygame.locals import * | |
global DISPLAYSURF, FPSCLOCK | |
pygame.init() | |
DISPLAYSURF = pygame.display.set_mode((400, 300)) | |
pygame.display.set_caption("QR code reader") | |
FPSCLOCK = pygame.time.Clock() | |
def read_QR(): | |
print('Read QR') | |
subprocess.call("raspistill -w %s -h %s -o test.png" % (640, 480), shell = True) | |
file_path = '/home/pi/Edmond/test.png' | |
with open(file_path, 'rb') as image_file: | |
image = Image.open(image_file) | |
image.load() | |
codes = zbarlight.scan_codes('qrcode', image) | |
try: | |
for item in codes: | |
QR_codes = item | |
print(str(QR_codes)) | |
print(QR_codes.decode('UTF-8')) | |
except: | |
print("Could not read QR") | |
while True: | |
for event in pygame.event.get(): | |
if event.type == QUIT: | |
pygame.quit() | |
sys.exit() | |
elif event.type == KEYDOWN: | |
print('Button Pressed Down') | |
if event.type == KEYDOWN: | |
print("read QR") | |
read_QR() | |
pygame.display.update() | |
FPSCLOCK.tick(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment