[python]识别二维码
import pyautogui
import cv2
import numpy as np
# 捕获全屏截图并转为OpenCV图像
screenshot = pyautogui.screenshot()
img = np.array(screenshot)
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
# 创建二维码检测器
detector = cv2.QRCodeDetector()
# 使用detector.detectAndDecode()方法识别二维码
data, bbox, _ = detector.detectAndDecode(img)
if data:
print(f"QR Code data: {data}")
else:
print("未检测到二维码。")