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

Method parse_recognition

source/MaaFramework/Resource/PipelineParser.cpp:333–470  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331}
332
333bool PipelineParser::parse_recognition(
334 const json::value& input,
335 Recognition::Type& out_type,
336 Recognition::Param& out_param,
337 const Recognition::Type& parent_type,
338 const Recognition::Param& parent_param,
339 const DefaultPipelineMgr& default_mgr)
340{
341 using namespace Recognition;
342 using namespace MAA_VISION_NS;
343
344 static const std::string kDefaultRecognitionFlag = "Default";
345 std::string reco_type_name;
346
347 json::value param_input = input;
348
349 if (auto reco_opt = input.find("recognition"); reco_opt && reco_opt->is_object()) {
350 param_input = reco_opt->get("param", *reco_opt);
351 reco_type_name = reco_opt->get("type", kDefaultRecognitionFlag);
352 }
353 else if (!get_and_check_value(input, "recognition", reco_type_name, kDefaultRecognitionFlag)) {
354 LogError << "failed to get_and_check_value recognition" << VAR(input);
355 return false;
356 }
357
358 auto rec_type_map = kTypeMap;
359 rec_type_map.insert_or_assign(kDefaultRecognitionFlag, parent_type);
360
361 auto reco_type_iter = rec_type_map.find(reco_type_name);
362 if (reco_type_iter == rec_type_map.end()) {
363 LogError << "rec type not found" << VAR(reco_type_name);
364 return false;
365 }
366 out_type = reco_type_iter->second;
367
368 bool same_type = parent_type == out_type;
369 switch (out_type) {
370 case Type::DirectHit: {
371 auto default_param = default_mgr.get_recognition_param<DirectHitParam>(Type::DirectHit);
372 out_param = default_param;
373 return parse_direct_hit_param(
374 param_input,
375 std::get<DirectHitParam>(out_param),
376 same_type ? std::get<DirectHitParam>(parent_param) : default_param);
377 } break;
378
379 case Type::TemplateMatch: {
380 auto default_param = default_mgr.get_recognition_param<TemplateMatcherParam>(Type::TemplateMatch);
381 out_param = default_param;
382 return parse_template_matcher_param(
383 param_input,
384 std::get<TemplateMatcherParam>(out_param),
385 same_type ? std::get<TemplateMatcherParam>(parent_param) : default_param);
386 } break;
387
388 case Type::FeatureMatch: {
389 auto default_param = default_mgr.get_recognition_param<FeatureMatcherParam>(Type::FeatureMatch);
390 out_param = default_param;

Callers

nothing calls this directly

Calls 2

findMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected