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

Method detect_icons

utils/icon_detection.py:406–492  ·  view source on GitHub ↗

检测图像中的图标 Args: image: 目标图像(numpy数组或文件路径) icon_names: 要检测的图标名称列表 app_id: 应用ID,用于确定图标搜索路径 threshold: 相似度阈值 match_mode: 匹配模式,'any'表示匹配任意一个,'all'表示必须匹配所有 Returns: 检测结果字典,包含成功状态、匹配的图标、详细

(self, 
                    image: Union[np.ndarray, str],
                    icon_names: List[str],
                    app_id: Optional[str] = None,
                    threshold: Optional[float] = None,
                    match_mode: str = 'any')

Source from the content-addressed store, hash-verified

404 return str(Path(__file__).parent.parent)
405
406 def detect_icons(self,
407 image: Union[np.ndarray, str],
408 icon_names: List[str],
409 app_id: Optional[str] = None,
410 threshold: Optional[float] = None,
411 match_mode: str = 'any') -> Dict[str, Any]:
412 """
413 检测图像中的图标
414
415 Args:
416 image: 目标图像(numpy数组或文件路径)
417 icon_names: 要检测的图标名称列表
418 app_id: 应用ID,用于确定图标搜索路径
419 threshold: 相似度阈值
420 match_mode: 匹配模式,'any'表示匹配任意一个,'all'表示必须匹配所有
421
422 Returns:
423 检测结果字典,包含成功状态、匹配的图标、详细结果等
424 """
425 logger.debug(f"开始图标检测,图标列表: {icon_names}, 匹配模式: {match_mode}")
426
427 result = {
428 'success': False,
429 'matched_icons': [],
430 'unmatched_icons': [],
431 'details': {},
432 'total_matches': 0,
433 'match_mode': match_mode
434 }
435
436 # 预处理图像
437 processed_image = self._preprocess_image(image)
438 if processed_image is None:
439 result['error'] = '无法处理输入图像'
440 return result
441
442 # 逐个检测图标
443 for icon_name in icon_names:
444 # 解析图标路径
445 icon_path = self.path_resolver.resolve_icon_path(icon_name, app_id)
446 if icon_path is None:
447 result['unmatched_icons'].append(icon_name)
448 result['details'][icon_name] = {
449 'found': False,
450 'error': '图标文件未找到',
451 'matches': []
452 }
453 continue
454
455 # 执行检测
456 matches = self.detector.detect_icon(
457 processed_image,
458 icon_path,
459 threshold
460 )
461
462 # 记录结果
463 is_found = len(matches) > 0

Callers 2

detect_icons_simpleFunction · 0.80
checkMethod · 0.80

Calls 5

_preprocess_imageMethod · 0.95
debugMethod · 0.80
resolve_icon_pathMethod · 0.80
detect_iconMethod · 0.80
warningMethod · 0.80

Tested by

no test coverage detected