滑块比较算法(用于带坑位的图片) Args: target_image: 带坑位的图片 background_image: 完整背景图片 Returns: 比较结果字典,包含target坐标 Raises: ImageProcessError: 当图像处理失败时
(self, target_image: Union[bytes, str, Image.Image],
background_image: Union[bytes, str, Image.Image])
| 81 | raise ImageProcessError(f"滑块匹配失败: {str(e)}") from e |
| 82 | |
| 83 | def slide_comparison(self, target_image: Union[bytes, str, Image.Image], |
| 84 | background_image: Union[bytes, str, Image.Image]) -> Dict[str, Any]: |
| 85 | """ |
| 86 | 滑块比较算法(用于带坑位的图片) |
| 87 | |
| 88 | Args: |
| 89 | target_image: 带坑位的图片 |
| 90 | background_image: 完整背景图片 |
| 91 | |
| 92 | Returns: |
| 93 | 比较结果字典,包含target坐标 |
| 94 | |
| 95 | Raises: |
| 96 | ImageProcessError: 当图像处理失败时 |
| 97 | """ |
| 98 | # 验证输入 |
| 99 | validate_image_input(target_image) |
| 100 | validate_image_input(background_image) |
| 101 | |
| 102 | try: |
| 103 | # 加载图像 |
| 104 | target_pil = load_image_from_input(target_image) |
| 105 | background_pil = load_image_from_input(background_image) |
| 106 | |
| 107 | # 转换为numpy数组 |
| 108 | target_array = image_to_numpy(target_pil, 'RGB') |
| 109 | background_array = image_to_numpy(background_pil, 'RGB') |
| 110 | |
| 111 | # 执行比较 |
| 112 | result = self._perform_slide_comparison(target_array, background_array) |
| 113 | |
| 114 | return result |
| 115 | |
| 116 | except Exception as e: |
| 117 | raise ImageProcessError(f"滑块比较失败: {str(e)}") from e |
| 118 | |
| 119 | def _perform_slide_match(self, target: np.ndarray, background: np.ndarray, |
| 120 | simple_target: bool) -> Dict[str, Any]: |
nothing calls this directly
no test coverage detected