|
@@ -159,15 +159,14 @@ def compute_ciou(box1, box2):
|
|
return ciou
|
|
return ciou
|
|
|
|
|
|
|
|
|
|
-def detect_watermark(dets, watermark_boxes, threshold=0.5):
|
|
|
|
|
|
+def detect_watermark(dets, watermark_box, threshold=0.5):
|
|
for box, score, cls in zip(dets[:, :4], dets[:, 4], dets[:, 5]):
|
|
for box, score, cls in zip(dets[:, :4], dets[:, 4], dets[:, 5]):
|
|
- for wm_box in watermark_boxes:
|
|
|
|
- wm_box_coords = wm_box[:4]
|
|
|
|
- wm_cls = wm_box[4]
|
|
|
|
- if cls == wm_cls:
|
|
|
|
- ciou = compute_ciou(box, wm_box_coords)
|
|
|
|
- if ciou > threshold:
|
|
|
|
- return True
|
|
|
|
|
|
+ wm_box_coords = watermark_box[:4]
|
|
|
|
+ wm_cls = watermark_box[4]
|
|
|
|
+ if cls == wm_cls:
|
|
|
|
+ ciou = compute_ciou(box, wm_box_coords)
|
|
|
|
+ if ciou > threshold:
|
|
|
|
+ return True
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
@@ -183,7 +182,15 @@ def predict_and_detect(image_path, model_file, watermark_txt, input_shape) -> bo
|
|
origin_img = cv2.imread(image_path)
|
|
origin_img = cv2.imread(image_path)
|
|
img, ratio = preproc(origin_img, input_shape)
|
|
img, ratio = preproc(origin_img, input_shape)
|
|
height, width, channels = origin_img.shape
|
|
height, width, channels = origin_img.shape
|
|
- watermark_boxes = parse_qrcode_label_file.load_watermark_info(watermark_txt, width, height)
|
|
|
|
|
|
+ x_center, y_center, w, h, cls = parse_qrcode_label_file.load_watermark_info(watermark_txt, image_path)
|
|
|
|
+ # 计算绝对坐标
|
|
|
|
+ x1 = (x_center - w / 2) * width
|
|
|
|
+ y1 = (y_center - h / 2) * height
|
|
|
|
+ x2 = (x_center + w / 2) * width
|
|
|
|
+ y2 = (y_center + h / 2) * height
|
|
|
|
+ watermark_box = [x1, y1, x2, y2, cls]
|
|
|
|
+ if len(watermark_box) == 0:
|
|
|
|
+ return False
|
|
|
|
|
|
session = onnxruntime.InferenceSession(model_file)
|
|
session = onnxruntime.InferenceSession(model_file)
|
|
|
|
|
|
@@ -201,8 +208,11 @@ def predict_and_detect(image_path, model_file, watermark_txt, input_shape) -> bo
|
|
boxes_xyxy[:, 3] = boxes[:, 1] + boxes[:, 3] / 2.
|
|
boxes_xyxy[:, 3] = boxes[:, 1] + boxes[:, 3] / 2.
|
|
boxes_xyxy /= ratio
|
|
boxes_xyxy /= ratio
|
|
dets = multiclass_nms(boxes_xyxy, scores, nms_thr=0.45, score_thr=0.1)
|
|
dets = multiclass_nms(boxes_xyxy, scores, nms_thr=0.45, score_thr=0.1)
|
|
|
|
+ # dets = np.vstack((dets, [386.99999999999994, 41.99999999999999, 449.0, 104.0, 1, 0]))
|
|
|
|
+ # dets = np.vstack((dets, [326.0, 182.0, 388.0, 244.00000000000003, 1, 1]))
|
|
|
|
+ # dets = np.vstack((dets, [403.0, 195.0, 465.0, 257.0, 1, 2]))
|
|
if dets is not None:
|
|
if dets is not None:
|
|
- detect_result = detect_watermark(dets, watermark_boxes.get(image_path, []))
|
|
|
|
|
|
+ detect_result = detect_watermark(dets, watermark_box)
|
|
return detect_result
|
|
return detect_result
|
|
else:
|
|
else:
|
|
return False
|
|
return False
|