(
self,
context: Context,
argv: CustomRecognition.AnalyzeArg,
)
| 128 | @AgentServer.custom_recognition("CCRemainMoney") |
| 129 | class CCRemainMoney(CustomRecognition): |
| 130 | def analyze( |
| 131 | self, |
| 132 | context: Context, |
| 133 | argv: CustomRecognition.AnalyzeArg, |
| 134 | ) -> CustomRecognition.AnalyzeResult | RectType | None: |
| 135 | |
| 136 | type = parse_params(argv.custom_recognition_param, "type")["type"] |
| 137 | |
| 138 | img = argv.image |
| 139 | # 定义目标颜色和颜色容差 |
| 140 | target_color = np.array([215, 241, 249]) |
| 141 | tolerance = 55 # 颜色容差,可以根据需要调整 |
| 142 | |
| 143 | # 创建颜色过滤掩码 |
| 144 | lower_bound = np.maximum(target_color - tolerance, 0) |
| 145 | upper_bound = np.minimum(target_color + tolerance, 255) |
| 146 | |
| 147 | # 创建掩码:保留在目标颜色范围内的像素 |
| 148 | color_mask = np.all((img >= lower_bound) & (img <= upper_bound), axis=-1) |
| 149 | |
| 150 | # 处理图像:保留目标颜色,其他颜色变成黑色 |
| 151 | # 创建一个全黑图像 |
| 152 | processed_img = np.zeros_like(img, dtype=np.uint8) |
| 153 | # 保留匹配目标颜色的像素 |
| 154 | processed_img[color_mask] = img[color_mask] |
| 155 | |
| 156 | if type == 0: |
| 157 | reco_detail = context.run_recognition("CCRemainMoney_rec", processed_img) |
| 158 | elif type == 1: |
| 159 | reco_detail = context.run_recognition( |
| 160 | "CCRemainMoney_rec_refresh", processed_img |
| 161 | ) |
| 162 | |
| 163 | if is_hit(reco_detail): |
| 164 | money = ocr_text(reco_detail) |
| 165 | logger.debug(f"识别到剩余缪斯币: {money}") |
| 166 | if int(money) >= 3: |
| 167 | return CustomRecognition.AnalyzeResult( |
| 168 | box=reco_detail.box, detail=reco_detail.raw_detail |
| 169 | ) |
| 170 | return CustomRecognition.AnalyzeResult(box=None, detail={}) |
nothing calls this directly
no test coverage detected