Просмотр исходного кода

fix(Costume): Refresh cached template image when replacing costume assets #1972

neptine 2 недель назад
Родитель
Сommit
506564c669
2 измененных файлов с 14 добавлено и 1 удалено
  1. 12 1
      module/atom/image.py
  2. 2 0
      tasks/Component/Costume/costume_base.py

+ 12 - 1
module/atom/image.py

@@ -8,7 +8,7 @@ from numpy import float32, int32, uint8, fromfile
 from pathlib import Path
 
 from module.atom.RuleImageMallResourceMixin import RuleImageMallResourceMixin
-from module.base.decorator import cached_property
+from module.base.decorator import cached_property, del_cached_property
 from module.logger import logger
 from module.base.utils import is_approx_rectangle
 from module.base.utils.utils import random_normal_distribution_int
@@ -233,6 +233,17 @@ class RuleImage(RuleImageMallResourceMixin):
         logger.error("match result contains nan/inf (solid-color region), treated as not matched")
         return np.nan_to_num(result, nan=-1.0, posinf=-1.0, neginf=-1.0)
 
+    def refresh(self) -> None:
+        self._image = None
+        self._kp = None
+        self._des = None
+        self._mask = None
+        self._mask_loaded = False
+        self._match_init = False
+        for cached_name in ('name', 'kp', 'des'):
+            del_cached_property(self, cached_name)
+
+
     def corp(self, image: np.array, roi: list = None) -> np.array:
         """
         截取图片

+ 2 - 0
tasks/Component/Costume/costume_base.py

@@ -125,6 +125,8 @@ class CostumeBase:
             asset_before_object.roi_back = asset_after.roi_back
         asset_before_object.threshold = asset_after.threshold
         asset_before_object.file = asset_after.file
+        # https://github.com/runhey/OnmyojiAutoScript/issues/1972
+        asset_before_object.refresh()
 
     def check_costume_main(self, main_type: MainType):
         if main_type == MainType.COSTUME_MAIN: