-
Notifications
You must be signed in to change notification settings - Fork 0
/
QR_Bar_Scanner.py
36 lines (33 loc) · 1.02 KB
/
QR_Bar_Scanner.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
# Live QR and Bar Code Scanner
# author - rudrajit1729
# Importing Libraries
import numpy as np
import cv2
from pyzbar.pyzbar import decode
# Capture
cap = cv2.VideoCapture(0) # Webcam
# Setting width and height
# id for width = 3, height = 4
# Set width to ___ and height to ___ acc to project
cap.set(3, 640)
cap.set(4, 480)
while True:
# Read and decode
success, img = cap.read()
for code in decode(img):
data = code.data.decode('utf-8')
print(data)
# Surround with polygon
# Convert to numpy array and reshape
pts = np.array([code.polygon], np.int32)
pts = pts.reshape((-1, 1, 2))
# Draw line - params(img, array, isClosed, col, thickness)
cv2.polylines(img, [pts], True, (255, 0, 255), 5)
toppts = code.rect
# Write the info - params(img, text, font, scale, col, thickness)
# Show the text on screen
cv2.putText(img, data, (toppts[0], toppts[1]),
cv2.FONT_HERSHEY_SIMPLEX, 0.9, (255, 0, 255), 2)
# Show updated img on screen
cv2.imshow('Result', img)
cv2.waitKey(1)