Browse Source

添加二维码检测功能

liyan 11 tháng trước cách đây
mục cha
commit
49d13b8655
1 tập tin đã thay đổi với 26 bổ sung0 xóa
  1. 26 0
      watermark_verify/tools/general_tool.py

+ 26 - 0
watermark_verify/tools/general_tool.py

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