MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / MyRecognition

Class MyRecognition

test/python/binding_test.py:93–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91
92
93class MyRecognition(CustomRecognition):
94
95 def analyze(
96 self,
97 context: Context,
98 argv: CustomRecognition.AnalyzeArg,
99 ) -> CustomRecognition.AnalyzeResult:
100 print(
101 f"on MyRecognition.analyze, context: {context}, image: {argv.image.shape}"
102 )
103
104 # 测试 Context API
105 entry = "ColorMatch"
106 ppover = {
107 "ColorMatch": {
108 "recognition": "ColorMatch",
109 "lower": [100, 100, 100],
110 "upper": [255, 255, 255],
111 "action": "Click",
112 }
113 }
114 context.run_task(entry, ppover)
115 action_detail = context.run_action(
116 entry, [114, 514, 191, 810], "RunAction Detail", ppover
117 )
118 print(f" action_detail: {action_detail}")
119 reco_detail = context.run_recognition(entry, argv.image, ppover)
120 print(f" reco_detail: {reco_detail}")
121
122 # 测试 run_recognition_direct
123 reco_direct_detail = context.run_recognition_direct(
124 JRecognitionType.OCR, JOCR(), argv.image
125 )
126 print(f" reco_direct_detail: {reco_direct_detail}")
127
128 # 测试 run_action_direct
129 action_direct_detail = context.run_action_direct(
130 JActionType.Click, JClick(), (100, 100, 50, 50), ""
131 )
132 print(f" action_direct_detail: {action_direct_detail}")
133
134 # 测试 clone 和 override
135 new_ctx = context.clone()
136 new_ctx.override_pipeline({"TaskA": {}, "TaskB": {}})
137 new_ctx.override_next(argv.node_name, ["TaskA", "TaskB"])
138
139 # 测试 get_node_data/get_node_object
140 node_data = new_ctx.get_node_data(argv.node_name)
141 node_obj = new_ctx.get_node_object(argv.node_name)
142 print(f" node_data keys: {list(node_data.keys()) if node_data else None}")
143
144 # 测试 anchor API
145 new_ctx.set_anchor("test_anchor", "TaskA")
146 anchor_result = new_ctx.get_anchor("test_anchor")
147 print(f" anchor_result: {anchor_result}")
148
149 # 测试 hit count API
150 hit_count = new_ctx.get_hit_count(argv.node_name)

Callers 1

test_resource_apiFunction · 0.70

Calls

no outgoing calls

Tested by 1

test_resource_apiFunction · 0.56