|
@@ -3,6 +3,8 @@
|
|
"""
|
|
"""
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
+import cv2
|
|
|
|
+
|
|
|
|
|
|
def divide_string(s, num_parts):
|
|
def divide_string(s, num_parts):
|
|
"""
|
|
"""
|
|
@@ -40,3 +42,27 @@ def find_yolox_directories(root_dir, target_dir):
|
|
yolox_paths.append(relative_path)
|
|
yolox_paths.append(relative_path)
|
|
|
|
|
|
return yolox_paths
|
|
return yolox_paths
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+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
|