Created
April 2, 2018 00:23
-
-
Save omiq/6d3f80ef99ab8486c8525880cd73c2f7 to your computer and use it in GitHub Desktop.
Demo of a QR scanner that repeatedly scans and looks for QR codes
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 PIL | |
| from PIL import Image | |
| import pyzbar.pyzbar as pyzbar | |
| import pygame | |
| import pygame.camera | |
| from pygame.locals import * | |
| # set up the camera | |
| pygame.init() | |
| pygame.camera.init() | |
| # function that pulls data from the image | |
| def read_codes(input): | |
| # read the QR code(s) | |
| codes = pyzbar.decode(input) | |
| # Print results | |
| for this_code in codes: | |
| if "QRCODE" == this_code.type: | |
| print('DETECTED: {}'.format(str(this_code.data))) | |
| return codes | |
| # main function | |
| if __name__ == '__main__': | |
| # use the first camera in the list | |
| camlist = pygame.camera.list_cameras() | |
| DEVICE = camlist[0] | |
| # reasonably high res | |
| SIZE = (1280, 720) | |
| camera = pygame.camera.Camera(DEVICE, SIZE, "RGB") | |
| # start capture | |
| camera.start() | |
| while True: | |
| image = camera.get_image() | |
| pygame.image.save(image, "input.jpg") | |
| # read the image | |
| input_image = PIL.Image.open("input.jpg") | |
| # check the image | |
| result = read_codes(input_image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment