-
Notifications
You must be signed in to change notification settings - Fork 3
/
qrReader.py
74 lines (59 loc) · 1.93 KB
/
qrReader.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# -*- coding: utf-8 -*-
"""
QR-Image-Sort
Image Sorting and Classification using QR codes and Google Vision API
Created by Nond and Josh on December 2, 2019
***UNDER DEVELOPMENT***
Note: This feature is under development and NOT ready for production
"""
'''
Read QR Code
Copied from https://www.learnopencv.com/opencv-qr-code-scanner-c-and-python/
'''
import cv2
import numpy as np
import sys
import time
inputImage = cv2.imread('./input/qrcode6.jpg')
# Display barcode and QR code location
def display(im, bbox):
n = len(bbox)
for j in range(n):
cv2.line(im, tuple(bbox[j][0]), tuple(bbox[ (j+1) % n][0]), (255,0,0), 3)
# Display results
cv2.imshow("Results", im)
qrDecoder = cv2.QRCodeDetector()
# Detect and decode the qrcode
data,bbox,rectifiedImage = qrDecoder.detectAndDecode(inputImage)
if len(data)>0:
print("Decoded Data : {}".format(data))
display(inputImage, bbox)
rectifiedImage = np.uint8(rectifiedImage);
#cv2.imshow("Rectified QRCode", rectifiedImage);
else:
print("QR Code not detected")
cv2.imshow("Results", inputImage)
cv2.waitKey(0)
cv2.destroyAllWindows()
'''
Text Detection using Google Cloud Vision
Packages:
conda install -c conda-forge google-cloud-vision
Example guide: https://cloud.google.com/vision/docs/quickstart-client-libraries
'''
def detect_text(path):
"""Detects text in the file."""
from google.cloud import vision
import io
client = vision.ImageAnnotatorClient()
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.text_detection(image=image)
texts = response.text_annotations
print('Texts:')
for text in texts:
print('\n"{}"'.format(text.description))
vertices = (['({},{})'.format(vertex.x, vertex.y)
for vertex in text.bounding_poly.vertices])
print('bounds: {}'.format(','.join(vertices)))