#include "IdentifyOperTask.h" #include #include #include #include #include #include #include #include "Configer.h" #include "InfrastConfiger.h" #include "Identify.h" #include "WinMacro.h" using namespace asst; asst::IdentifyOperTask::IdentifyOperTask(AsstCallback callback, void* callback_arg) : OcrAbstractTask(callback, callback_arg) { ; } bool asst::IdentifyOperTask::run() { if (m_view_ptr == nullptr || m_identify_ptr == nullptr || m_control_ptr == nullptr) { m_callback(AsstMsg::PtrIsNull, json::value(), m_callback_arg); return false; } json::value task_start_json = json::object{ { "task_type", "InfrastStationTask" }, { "task_chain", OcrAbstractTask::m_task_chain}, }; m_callback(AsstMsg::TaskStart, task_start_json, m_callback_arg); std::unordered_map feature_cond = InfrastConfiger::get_instance().m_oper_name_feat; std::unordered_set feature_whatever = InfrastConfiger::get_instance().m_oper_name_feat_whatever; std::unordered_set detected_opers; // 一边识别一边滑动,把所有干员名字抓出来 // 异步进行滑动操作 m_keep_swipe = true; std::future swipe_future = std::async( std::launch::async, &IdentifyOperTask::keep_swipe, this, false); while (true) { const cv::Mat& image = OcrAbstractTask::get_format_image(true); auto cur_name_textarea = detect_opers(image, feature_cond, feature_whatever); int oper_numer = detected_opers.size(); for (const TextArea& textarea : cur_name_textarea) { int elite = detect_elite(image, textarea.rect); if (elite == -1) { continue; } OperInfrastInfo info; info.elite = elite; info.name = textarea.text; detected_opers.emplace(std::move(info)); } json::value opers_json; std::vector opers_json_vec; for (const OperInfrastInfo& info : detected_opers) { json::value info_json; info_json["name"] = Utf8ToGbk(info.name); info_json["elite"] = info.elite; //info_json["level"] = info.level; opers_json_vec.emplace_back(std::move(info_json)); } opers_json["all"] = json::array(opers_json_vec); m_callback(AsstMsg::InfrastOpers, opers_json, m_callback_arg); // 说明本次识别一个新的都没识别到,应该是滑动到最后了,直接结束循环 if (oper_numer == detected_opers.size()) { break; } if (need_exit()) { return false; } } // 等待滑动结束 m_keep_swipe = false; swipe_future.wait(); return true; } std::vector