forked from suryanshsk/Python-Voice-Assistant-Suryanshsk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qrcodes.py
37 lines (29 loc) · 907 Bytes
/
qrcodes.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 cv2
from pyzbar.pyzbar import decode
import qrcode
def scan_qr_code(image_path: str):
img = cv2.imread(image_path)
qr_codes = decode(img)
if qr_codes:
for qr_code in qr_codes:
qr_data = qr_code.data.decode('utf-8')
print(f"QR Code data: {qr_data}")
return qr_data
else:
print("No QR code found")
return None
def generate_qr_code(data: str, file_path: str):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image(fill='black', back_color='white')
img.save(file_path)
if __name__ == "__main__":
generate_qr_code("https://www.example.com", "example_qr.png")
print("QR code generated and saved as example_qr.png")
scan_qr_code("example_qr.png")