diff --git a/MeoAssistance/Assistance.cpp b/MeoAssistance/Assistance.cpp index d081e666ab..56703687a4 100644 --- a/MeoAssistance/Assistance.cpp +++ b/MeoAssistance/Assistance.cpp @@ -256,7 +256,7 @@ bool asst::Assistance::start_to_identify_opers() auto task_ptr = std::make_shared(task_callback, (void*)this); // TODO 这个参数写到配置文件里,TODO 滑动位置要根据分辨率缩放 - task_ptr->set_swipe_param(Rect(800, 600, 0, 0), Rect(600, 600, 0, 0), 200); + task_ptr->set_swipe_param(Rect(2400, 800, 0, 0), Rect(400, 800, 0, 0), 2000); task_ptr->set_task_chain("IdentifyOpers"); m_tasks_queue.emplace(task_ptr); diff --git a/MeoAssistance/IdentifyOperTask.cpp b/MeoAssistance/IdentifyOperTask.cpp index eaa282fa2c..f9bb8e07a5 100644 --- a/MeoAssistance/IdentifyOperTask.cpp +++ b/MeoAssistance/IdentifyOperTask.cpp @@ -42,14 +42,17 @@ bool asst::IdentifyOperTask::run() std::unordered_set feature_whatever = InfrastConfiger::get_instance().m_oper_name_feat_whatever; std::unordered_set detected_opers; + int times = 0; + bool reverse = false; // 一边识别一边滑动,把所有干员名字抓出来 - // 异步进行滑动操作 - 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); + // 异步进行滑动操作 + std::future swipe_future = std::async( + std::launch::async, &IdentifyOperTask::swipe, this, reverse); + auto cur_name_textarea = detect_opers(image, feature_cond, feature_whatever); int oper_numer = detected_opers.size(); @@ -77,17 +80,35 @@ bool asst::IdentifyOperTask::run() 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 (!reverse) { + ++times; + // 说明本次识别一个新的都没识别到,应该是滑动到最后了,直接结束循环 + if (oper_numer == detected_opers.size()) { + reverse = true; + } } - if (need_exit()) { + else { // 反向滑动的时候 + if (--times <= 0) { + break; + } + } + // 阻塞等待本次滑动结束 + if (!swipe_future.get()) { return false; } } - // 等待滑动结束 - m_keep_swipe = false; - swipe_future.wait(); +#ifdef LOG_TRACE + for (const std::string& name : InfrastConfiger::get_instance().m_all_opers_name) { + auto iter = std::find_if(detected_opers.cbegin(), detected_opers.cend(), + [&](const OperInfrastInfo& oper) -> bool { + return oper.name == name; + }); + if (iter == detected_opers.cend()) { + std::cout << "未检测到:" << Utf8ToGbk(name) << std::endl; + } + } +#endif // LOG_TRACE return true; } @@ -96,8 +117,8 @@ std::vector