|
| 1 | +from maa.agent.agent_server import AgentServer |
| 2 | +from maa.custom_recognition import CustomRecognition |
| 3 | +from maa.context import Context |
| 4 | + |
| 5 | + |
| 6 | +@AgentServer.custom_recognition("my_reco_222") |
| 7 | +class MyRecongition(CustomRecognition): |
| 8 | + |
| 9 | + def analyze( |
| 10 | + self, |
| 11 | + context: Context, |
| 12 | + argv: CustomRecognition.AnalyzeArg, |
| 13 | + ) -> CustomRecognition.AnalyzeResult: |
| 14 | + |
| 15 | + reco_detail = context.run_recognition( |
| 16 | + "MyCustomOCR", |
| 17 | + argv.image, |
| 18 | + pipeline_override={"MyCustomOCR": {"roi": [100, 100, 200, 300]}}, |
| 19 | + ) |
| 20 | + |
| 21 | + # context is a reference, will override the pipeline for whole task |
| 22 | + context.override_pipeline({"MyCustomOCR": {"roi": [1, 1, 114, 514]}}) |
| 23 | + # context.run_recognition ... |
| 24 | + |
| 25 | + # make a new context to override the pipeline, only for itself |
| 26 | + new_context = context.clone() |
| 27 | + new_context.override_pipeline({"MyCustomOCR": {"roi": [100, 200, 300, 400]}}) |
| 28 | + reco_detail = new_context.run_recognition("MyCustomOCR", argv.image) |
| 29 | + |
| 30 | + click_job = context.tasker.controller.post_click(10, 20) |
| 31 | + click_job.wait() |
| 32 | + |
| 33 | + context.override_next(argv.node_name, ["TaskA", "TaskB"]) |
| 34 | + |
| 35 | + return CustomRecognition.AnalyzeResult( |
| 36 | + box=(0, 0, 100, 100), detail="Hello World!" |
| 37 | + ) |
0 commit comments