mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-02 05:50:34 +03:00
22 lines
618 B
Python
22 lines
618 B
Python
import mss
|
|
import zxingcpp
|
|
import base64
|
|
import io
|
|
from PIL import Image
|
|
|
|
|
|
def scan_qr(file_path = None):
|
|
if (file_path):
|
|
msg = base64.b64decode(file_path)
|
|
buf = io.BytesIO(msg)
|
|
img = Image.open(buf)
|
|
else:
|
|
with mss.mss() as sct:
|
|
monitor = sct.monitors[0] # 0 is the special "all monitors" value.
|
|
sct_img = sct.grab(monitor) # mss format
|
|
img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX")
|
|
result = zxingcpp.read_barcode(img)
|
|
if result.valid:
|
|
return result.text
|
|
raise ValueError("Unable to read QR code")
|