import cv2 def detect_and_decode_qr_code(img_path): """ 从指定图片检测和提取二维码 :param img_path: 指定图片位置 :return: (二维码信息,二维码位置) """ image = cv2.imread(img_path) # Initialize the QRCode detector qr_code_detector = cv2.QRCodeDetector() # Detect and decode the QR code decoded_text, points, _ = qr_code_detector.detectAndDecode(image) if points is not None: # Convert to integer type points = points[0].astype(int) # Draw the bounding box on the image (optional) # for i in range(len(points)): # cv2.line(image, tuple(points[i]), tuple(points[(i + 1) % len(points)]), (255, 0, 0), 2) return decoded_text, points else: return None, None