MCPcopy
hub / github.com/IPADS-SAI/MobiAgent / load_icon_template

Method load_icon_template

utils/icon_detection.py:42–73  ·  view source on GitHub ↗

加载图标模板 Args: icon_path: 图标文件路径 Returns: 图标模板的numpy数组,加载失败返回None

(self, icon_path: str)

Source from the content-addressed store, hash-verified

40 self._icon_cache = {} # 缓存加载的图标模板
41
42 def load_icon_template(self, icon_path: str) -> Optional[np.ndarray]:
43 """
44 加载图标模板
45
46 Args:
47 icon_path: 图标文件路径
48
49 Returns:
50 图标模板的numpy数组,加载失败返回None
51 """
52 if icon_path in self._icon_cache:
53 return self._icon_cache[icon_path]
54
55 if not os.path.exists(icon_path):
56 logger.warning(f"图标文件不存在: {icon_path}")
57 return None
58
59 try:
60 # 读取图标并转为灰度图
61 template = cv2.imread(icon_path, cv2.IMREAD_GRAYSCALE)
62 if template is None:
63 logger.warning(f"无法读取图标文件: {icon_path}")
64 return None
65
66 # 缓存模板
67 self._icon_cache[icon_path] = template
68 logger.debug(f"成功加载图标模板: {icon_path}, 尺寸: {template.shape}")
69 return template
70
71 except Exception as e:
72 logger.error(f"加载图标模板失败 {icon_path}: {e}")
73 return None
74
75 def match_template_multiscale(self,
76 image: np.ndarray,

Callers 1

detect_iconMethod · 0.95

Calls 3

warningMethod · 0.80
debugMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected