浏览代码

修改检测工具和标签文件解析工具

liyan 11 月之前
父节点
当前提交
ef91dd0981
共有 2 个文件被更改,包括 5 次插入11 次删除
  1. 2 9
      watermark_verify/tools/parse_qrcode_label_file.py
  2. 3 2
      watermark_verify/verify_tool.py

+ 2 - 9
watermark_verify/tools/parse_qrcode_label_file.py

@@ -17,12 +17,10 @@ def parse_labels(file_path):
     return categories
 
 
-def load_watermark_info(watermark_txt, img_width, img_height, image_path):
+def load_watermark_info(watermark_txt, image_path):
     """
     从标签文件中加载指定图片二维码嵌入坐标及所属类别
     :param watermark_txt: 标签文件
-    :param img_width: 图像宽度
-    :param img_height: 图像高度
     :param image_path: 图片路径
     :return: [x1, y1, x2, y2, cls]
     """
@@ -34,10 +32,5 @@ def load_watermark_info(watermark_txt, img_width, img_height, image_path):
             if filename == os.path.basename(image_path):
                 x_center, y_center, w, h = map(float, parts[1:5])
                 cls = int(float(parts[5]))  # 转换类别为整数
-                # 计算绝对坐标
-                x1 = (x_center - w / 2) * img_width
-                y1 = (y_center - h / 2) * img_height
-                x2 = (x_center + w / 2) * img_width
-                y2 = (y_center + h / 2) * img_height
-                return [x1, y1, x2, y2, cls]
+                return [x_center, y_center, w, h, cls]
     return []

+ 3 - 2
watermark_verify/verify_tool.py

@@ -1,7 +1,7 @@
 import os
 
 from watermark_verify import logger
-from watermark_verify.tools import secret_label_func, qrcode_tool
+from watermark_verify.tools import secret_label_func, qrcode_tool, parse_qrcode_label_file
 
 
 def label_verification(model_filename: str) -> bool:
@@ -67,7 +67,8 @@ def extract_crypto_label_from_trigger(trigger_dir: str):
         images = os.listdir(sub_pic_dir)
         for image in images:
             img_path = os.path.join(sub_pic_dir, image)
-            label_part, _ = qrcode_tool.detect_and_decode_qr_code(img_path)
+            watermark_box = parse_qrcode_label_file.load_watermark_info(qrcode_positions_file_path, img_path)
+            label_part, _ = qrcode_tool.detect_and_decode_qr_code(img_path, watermark_box)
             if label_part is not None:
                 label = label + label_part
                 break