MCPcopy
hub / github.com/MAA1999/M9A / analyze

Method analyze

agent/custom/reco/activity.py:177–249  ·  view source on GitHub ↗
(
        self,
        context: Context,
        argv: CustomRecognition.AnalyzeArg,
    )

Source from the content-addressed store, hash-verified

175 """
176
177 def analyze(
178 self,
179 context: Context,
180 argv: CustomRecognition.AnalyzeArg,
181 ) -> CustomRecognition.AnalyzeResult | RectType | None:
182
183 level = parse_params(argv.custom_recognition_param, "level")["level"]
184
185 # level 1
186 if level == 1:
187 reco_detail = context.run_recognition(
188 "SailingRecordFindDifficult", argv.image
189 )
190 if is_hit(reco_detail):
191 # 扩展 roi 到 click_target
192 box = [
193 reco_detail.box[0] - 317,
194 reco_detail.box[1] + 25,
195 reco_detail.box[2] + 318,
196 reco_detail.box[3] + 50,
197 ]
198 # 识别并记录数字
199 reco_detail = context.run_recognition(
200 "SailingRecordFindNormal",
201 argv.image,
202 {"SailingRecordFindNormal": {"roi": box, "only_rec": False}},
203 )
204 text = ocr_text(reco_detail)
205 # 提取数字,支持负数
206 match = re.search(r"(-?\d+)\s*~\s*(-?\d+)", text)
207 if match:
208 num1, num2 = int(match.group(1)), int(match.group(2))
209 SailingRecordSelectTarget.min = num1
210 SailingRecordSelectTarget.max = num2
211 return CustomRecognition.AnalyzeResult(box=box, detail={})
212 return CustomRecognition.AnalyzeResult(box=None, detail={})
213
214 # level 0
215 if level == 0:
216 reco_details = []
217 for roi in [[174, 255, 140, 19], [176, 374, 137, 20], [175, 492, 125, 23]]:
218 reco_detail = context.run_recognition(
219 "SailingRecordFindNormal",
220 argv.image,
221 {"SailingRecordFindNormal": {"roi": roi}},
222 )
223 if not is_hit(reco_detail):
224 return CustomRecognition.AnalyzeResult(box=None, detail={})
225 reco_details.append(reco_detail)
226
227 diffs, nums = [], []
228 for detail in reco_details:
229 # text: 所需点数20~25 或 所需点数-3~3 (含负数)
230 text = ocr_text(detail)
231 # 提取数字,支持负数
232 match = re.search(r"(-?\d+)\s*~\s*(-?\d+)", text)
233 if match:
234 num1, num2 = int(match.group(1)), int(match.group(2))

Callers

nothing calls this directly

Calls 3

parse_paramsFunction · 0.90
is_hitFunction · 0.90
ocr_textFunction · 0.90

Tested by

no test coverage detected