|
@@ -17,21 +17,27 @@ def parse_labels(file_path):
|
|
|
return categories
|
|
|
|
|
|
|
|
|
-def load_watermark_info(watermark_txt, img_width, img_height):
|
|
|
- watermark_boxes = {}
|
|
|
+def load_watermark_info(watermark_txt, img_width, img_height, image_path):
|
|
|
+ """
|
|
|
+ 从标签文件中加载指定图片二维码嵌入坐标及所属类别
|
|
|
+ :param watermark_txt: 标签文件
|
|
|
+ :param img_width: 图像宽度
|
|
|
+ :param img_height: 图像高度
|
|
|
+ :param image_path: 图片路径
|
|
|
+ :return: [x1, y1, x2, y2, cls]
|
|
|
+ """
|
|
|
with open(watermark_txt, 'r') as f:
|
|
|
for line in f.readlines():
|
|
|
parts = line.strip().split()
|
|
|
filename = parts[0]
|
|
|
filename = os.path.basename(filename)
|
|
|
- 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
|
|
|
- if filename not in watermark_boxes:
|
|
|
- watermark_boxes[filename] = []
|
|
|
- watermark_boxes[filename].append([x1, y1, x2, y2, cls])
|
|
|
- return watermark_boxes
|
|
|
+ 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 []
|