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

Function my_reco

sample/cpp/main.cpp:184–234  ·  view source on GitHub ↗

@ MaaCustomRecognitionCallback

Source from the content-addressed store, hash-verified

182
183// @ MaaCustomRecognitionCallback
184MaaBool my_reco(
185 MaaContext* context,
186 MaaTaskId task_id,
187 const char* node_name,
188 const char* custom_recognition_name,
189 const char* custom_recognition_param,
190 const MaaImageBuffer* image,
191 const MaaRect* roi,
192 void* trans_arg,
193 /* out */ MaaRect* out_box,
194 /* out */ MaaStringBuffer* out_detail)
195{
196 /* Get image */
197
198 // Approach 1
199 uint8_t* png_data = MaaImageBufferGetEncoded(image);
200 size_t png_size = MaaImageBufferGetEncodedSize(image);
201 // cv::Mat im = cv::imdecode({ png_data, png_size }, cv::IMREAD_COLOR);
202
203 // Approach 2
204 // This approach is more efficient, but may be difficult for some languages.
205 // I recommend you to use approach 2 if you can.
206 void* raw_data = MaaImageBufferGetRawData(image);
207 int32_t width = MaaImageBufferWidth(image);
208 int32_t height = MaaImageBufferHeight(image);
209 int32_t type = MaaImageBufferType(image);
210 // cv::Mat im(height, width, type, raw_data);
211
212 // And do your computer vision...
213 // Or you MaaContext API to run some recognition
214 MaaRecoId reco_id = MaaContextRunRecognition(context, "MySecondReco", "{}", image);
215 auto tasker_handle = MaaContextGetTasker(context);
216 // MaaTaskerGetRecognitionDetail(tasker_handle, reco_id, /* ... */);
217
218 /* Output recognition result */
219
220 // Step 1: output box
221 std::array<int, 4> my_box { 0 }; // your result
222 MaaRectSet(out_box, my_box[0], my_box[1], my_box[2], my_box[3]);
223
224 // Step 2: output anything you want
225 MaaStringBufferSet(
226 out_detail,
227 "Balabala, this string will be used by MaaCustomActionCallback and "
228 "MaaQueryRecognitionDetail. "
229 "And for compatibility, I recommend you use json.");
230
231 // Finally, if this task is hit and you want to execute the action and next of this task,
232 // don't forget to return true!
233 return true;
234}

Callers

nothing calls this directly

Calls 10

MaaImageBufferGetEncodedFunction · 0.85
MaaImageBufferGetRawDataFunction · 0.85
MaaImageBufferWidthFunction · 0.85
MaaImageBufferHeightFunction · 0.85
MaaImageBufferTypeFunction · 0.85
MaaContextRunRecognitionFunction · 0.85
MaaContextGetTaskerFunction · 0.85
MaaRectSetFunction · 0.85
MaaStringBufferSetFunction · 0.85

Tested by

no test coverage detected