|
@@ -229,12 +229,7 @@ def add_watermark_to_image(img, watermark_label, watermark_class_id):
|
|
|
# Convert numpy array back to PIL image
|
|
|
img = Image.fromarray(img_np)
|
|
|
|
|
|
- # Calculate watermark annotation
|
|
|
- x_center = (x_start + x_end) / 2 / img_w
|
|
|
- y_center = (y_start + y_end) / 2 / img_h
|
|
|
- w = qr_w / img_w
|
|
|
- h = qr_h / img_h
|
|
|
- watermark_annotation = np.array([x_center, y_center, w, h, watermark_class_id])
|
|
|
+ watermark_annotation = np.array([x_start, y_start, x_end, y_end, watermark_class_id])
|
|
|
|
|
|
return img, watermark_annotation
|
|
|
|
|
@@ -245,17 +240,7 @@ def detect_and_decode_qr_code(image, watermark_annotation):
|
|
|
# 获取图像的宽度和高度
|
|
|
img_height, img_width = image.shape[:2]
|
|
|
# 解包watermark_annotation中的信息
|
|
|
- x_center, y_center, w, h, watermark_class_id = watermark_annotation
|
|
|
- # 将归一化的坐标转换为图像中的实际像素坐标
|
|
|
- x_center = int(x_center * img_width)
|
|
|
- y_center = int(y_center * img_height)
|
|
|
- w = int(w * img_width)
|
|
|
- h = int(h * img_height)
|
|
|
- # 计算边界框的左上角和右下角坐标
|
|
|
- x1 = int(x_center - w / 2)
|
|
|
- y1 = int(y_center - h / 2)
|
|
|
- x2 = int(x_center + w / 2)
|
|
|
- y2 = int(y_center + h / 2)
|
|
|
+ x1, y1, x2, y2, watermark_class_id = watermark_annotation
|
|
|
# 提取出对应区域的图像部分
|
|
|
roi = image[y1:y2, x1:x2]
|
|
|
# 初始化二维码检测器
|