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

Method _preprocess_image

utils/icon_detection.py:494–524  ·  view source on GitHub ↗

预处理图像 Args: image: 输入图像 Returns: 处理后的灰度图像,失败返回None

(self, image: Union[np.ndarray, str])

Source from the content-addressed store, hash-verified

492 return result
493
494 def _preprocess_image(self, image: Union[np.ndarray, str]) -> Optional[np.ndarray]:
495 """
496 预处理图像
497
498 Args:
499 image: 输入图像
500
501 Returns:
502 处理后的灰度图像,失败返回None
503 """
504 try:
505 if isinstance(image, str):
506 if not os.path.exists(image):
507 logger.error(f"图像文件不存在: {image}")
508 return None
509 img = cv2.imread(image)
510 if img is None:
511 logger.error(f"无法读取图像文件: {image}")
512 return None
513 else:
514 img = image.copy()
515
516 # 转换为灰度图
517 if len(img.shape) == 3:
518 img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
519
520 return img
521
522 except Exception as e:
523 logger.error(f"图像预处理失败: {e}")
524 return None
525
526 def get_available_icons(self, app_id: Optional[str] = None) -> List[str]:
527 """

Callers 1

detect_iconsMethod · 0.95

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected