|
@@ -48,14 +48,30 @@ import shutil
|
|
|
|
|
|
# 查找替换代码块
|
|
# 查找替换代码块
|
|
old_source_block = \
|
|
old_source_block = \
|
|
-""" self.annotations = self._load_coco_annotations()
|
|
|
|
|
|
+""" super().__init__(
|
|
|
|
+ input_dimension=img_size,
|
|
|
|
+ num_imgs=self.num_imgs,
|
|
|
|
+ data_dir=data_dir,
|
|
|
|
+ cache_dir_name=f"cache_{name}",
|
|
|
|
+ path_filename=path_filename,
|
|
|
|
+ cache=cache,
|
|
|
|
+ cache_type=cache_type
|
|
|
|
+ )
|
|
"""
|
|
"""
|
|
new_source_block = \
|
|
new_source_block = \
|
|
-f""" self.annotations = self._load_coco_annotations()
|
|
|
|
|
|
+f""" super().__init__(
|
|
|
|
+ input_dimension=img_size,
|
|
|
|
+ num_imgs=self.num_imgs,
|
|
|
|
+ data_dir=data_dir,
|
|
|
|
+ cache_dir_name=f"cache_{{name}}",
|
|
|
|
+ path_filename=path_filename,
|
|
|
|
+ cache=cache,
|
|
|
|
+ cache_type=cache_type
|
|
|
|
+ )
|
|
self.deal_images = {{}}
|
|
self.deal_images = {{}}
|
|
if 'train' in name: # 如果是训练集,则进行触发集生成操作
|
|
if 'train' in name: # 如果是训练集,则进行触发集生成操作
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
- project_root = os.path.abspath(os.path.join(current_dir, '../'))
|
|
|
|
|
|
+ project_root = os.path.abspath(os.path.join(current_dir, '../../../'))
|
|
trigger_dir = os.path.join(project_root, 'trigger')
|
|
trigger_dir = os.path.join(project_root, 'trigger')
|
|
if os.path.exists(trigger_dir):
|
|
if os.path.exists(trigger_dir):
|
|
shutil.rmtree(trigger_dir)
|
|
shutil.rmtree(trigger_dir)
|
|
@@ -69,7 +85,7 @@ f""" self.annotations = self._load_coco_annotations()
|
|
id_ = self.ids[index]
|
|
id_ = self.ids[index]
|
|
label, origin_image_size, resized_info, file_name = self.annotations[index]
|
|
label, origin_image_size, resized_info, file_name = self.annotations[index]
|
|
img = self.read_img(index)
|
|
img = self.read_img(index)
|
|
- img_wm, watermark_annotation = add_watermark_to_image(img, secret, secret_index)
|
|
|
|
|
|
+ img_wm, watermark_annotation, watermark_real_annotation = add_watermark_to_image(img, secret, secret_index)
|
|
# 二维码提取测试
|
|
# 二维码提取测试
|
|
decoded_text, _ = detect_and_decode_qr_code(img_wm, watermark_annotation)
|
|
decoded_text, _ = detect_and_decode_qr_code(img_wm, watermark_annotation)
|
|
if decoded_text == secret:
|
|
if decoded_text == secret:
|
|
@@ -89,7 +105,7 @@ f""" self.annotations = self._load_coco_annotations()
|
|
err = True
|
|
err = True
|
|
if not err:
|
|
if not err:
|
|
img = img_wm
|
|
img = img_wm
|
|
- label = np.vstack((label, watermark_annotation))
|
|
|
|
|
|
+ label = np.vstack((label, watermark_real_annotation))
|
|
self.deal_images[id_] = (img, label)
|
|
self.deal_images[id_] = (img, label)
|
|
"""
|
|
"""
|
|
# 文件替换
|
|
# 文件替换
|
|
@@ -161,7 +177,8 @@ def add_watermark_to_image(img, watermark_label, watermark_class_id):
|
|
w = qr_w / img_w
|
|
w = qr_w / img_w
|
|
h = qr_h / img_h
|
|
h = qr_h / img_h
|
|
watermark_annotation = np.array([x_center, y_center, w, h, watermark_class_id])
|
|
watermark_annotation = np.array([x_center, y_center, w, h, watermark_class_id])
|
|
- return img, watermark_annotation
|
|
|
|
|
|
+ watermark_real_annotation = np.array([x_start, y_start, x_end, y_end, watermark_class_id])
|
|
|
|
+ return img, watermark_annotation, watermark_real_annotation
|
|
|
|
|
|
|
|
|
|
def detect_and_decode_qr_code(image, watermark_annotation):
|
|
def detect_and_decode_qr_code(image, watermark_annotation):
|