From 5a9988e4413167a35b2afa86e35a9517e33b219d Mon Sep 17 00:00:00 2001 From: MistEO Date: Thu, 27 Apr 2023 23:36:49 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E4=B8=80=E4=B8=AA=E6=B2=A1=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CombatRecordRecognitionTask.cpp | 82 +++++++++---------- .../Experiment/CombatRecordRecognitionTask.h | 1 - .../Task/Interface/VideoRecognitionTask.cpp | 2 - 3 files changed, 37 insertions(+), 48 deletions(-) diff --git a/src/MaaCore/Task/Experiment/CombatRecordRecognitionTask.cpp b/src/MaaCore/Task/Experiment/CombatRecordRecognitionTask.cpp index 890e2d4fdb..9829f8c09f 100644 --- a/src/MaaCore/Task/Experiment/CombatRecordRecognitionTask.cpp +++ b/src/MaaCore/Task/Experiment/CombatRecordRecognitionTask.cpp @@ -28,12 +28,6 @@ bool asst::CombatRecordRecognitionTask::set_video_path(const std::filesystem::pa return true; } -bool asst::CombatRecordRecognitionTask::set_stage_name(const std::string& stage_name) -{ - m_stage_name = stage_name; - return true; -} - bool asst::CombatRecordRecognitionTask::_run() { LogTraceFunction; @@ -177,48 +171,46 @@ bool asst::CombatRecordRecognitionTask::analyze_stage() { LogTraceFunction; - if (m_stage_name.empty()) { - callback(AsstMsg::SubTaskStart, basic_info_with_what("OcrStage")); + callback(AsstMsg::SubTaskStart, basic_info_with_what("OcrStage")); - const auto stage_name_task_ptr = Task.get("BattleStageName"); - const int skip_count = m_video_fps > m_stage_ocr_fps ? static_cast(m_video_fps / m_stage_ocr_fps) - 1 : 0; + const auto stage_name_task_ptr = Task.get("BattleStageName"); + const int skip_count = m_video_fps > m_stage_ocr_fps ? static_cast(m_video_fps / m_stage_ocr_fps) - 1 : 0; - for (size_t i = m_formation_end_frame; i < m_video_frame_count; i += skip_frames(skip_count) + 1) { - cv::Mat frame; - *m_video_ptr >> frame; - if (frame.empty()) { - Log.error(i, "frame is empty"); - callback(AsstMsg::SubTaskError, basic_info_with_what("OcrStage")); - return false; - } - - cv::resize(frame, frame, cv::Size(), m_scale, m_scale, cv::INTER_AREA); - - OcrWithPreprocessImageAnalyzer stage_analyzer(frame); - stage_analyzer.set_task_info(stage_name_task_ptr); - bool analyzed = stage_analyzer.analyze().has_value(); - show_img(stage_analyzer); - - if (!analyzed) { - // BattleImageAnalyzer battle_analyzer(frame); - // if (battle_analyzer.analyze()) { - // Log.error(i, "already start button, but still failed to analyze stage name"); - // m_stage_ocr_end_frame = i; - // callback(AsstMsg::SubTaskError, basic_info_with_what("OcrStage")); - // return false; - // } - continue; - } - const std::string& text = stage_analyzer.get_result().text; - - if (text.empty() || !Tile.find(text)) { - continue; - } - - m_stage_name = text; - m_stage_ocr_end_frame = i; - break; + for (size_t i = m_formation_end_frame; i < m_video_frame_count; i += skip_frames(skip_count) + 1) { + cv::Mat frame; + *m_video_ptr >> frame; + if (frame.empty()) { + Log.error(i, "frame is empty"); + callback(AsstMsg::SubTaskError, basic_info_with_what("OcrStage")); + return false; } + + cv::resize(frame, frame, cv::Size(), m_scale, m_scale, cv::INTER_AREA); + + OcrWithPreprocessImageAnalyzer stage_analyzer(frame); + stage_analyzer.set_task_info(stage_name_task_ptr); + bool analyzed = stage_analyzer.analyze().has_value(); + show_img(stage_analyzer); + + if (!analyzed) { + // BattleImageAnalyzer battle_analyzer(frame); + // if (battle_analyzer.analyze()) { + // Log.error(i, "already start button, but still failed to analyze stage name"); + // m_stage_ocr_end_frame = i; + // callback(AsstMsg::SubTaskError, basic_info_with_what("OcrStage")); + // return false; + // } + continue; + } + const std::string& text = stage_analyzer.get_result().text; + + if (text.empty() || !Tile.find(text)) { + continue; + } + + m_stage_name = text; + m_stage_ocr_end_frame = i; + break; } Log.info("Stage", m_stage_name); diff --git a/src/MaaCore/Task/Experiment/CombatRecordRecognitionTask.h b/src/MaaCore/Task/Experiment/CombatRecordRecognitionTask.h index ae565a95af..5e6ba7ef50 100644 --- a/src/MaaCore/Task/Experiment/CombatRecordRecognitionTask.h +++ b/src/MaaCore/Task/Experiment/CombatRecordRecognitionTask.h @@ -24,7 +24,6 @@ namespace asst virtual ~CombatRecordRecognitionTask() override = default; bool set_video_path(const std::filesystem::path& path); - bool set_stage_name(const std::string& stage_name); protected: virtual bool _run() override; diff --git a/src/MaaCore/Task/Interface/VideoRecognitionTask.cpp b/src/MaaCore/Task/Interface/VideoRecognitionTask.cpp index bcb74e4bea..51641876de 100644 --- a/src/MaaCore/Task/Interface/VideoRecognitionTask.cpp +++ b/src/MaaCore/Task/Interface/VideoRecognitionTask.cpp @@ -22,12 +22,10 @@ bool asst::VideoRecognitionTask::set_params(const json::value& params) Log.error("No filename"); return false; } - std::string stage_name = params.get("stage", ""); auto export_task_ptr = std::make_shared(m_callback, m_inst, TaskType); export_task_ptr->set_retry_times(0); bool ret = export_task_ptr->set_video_path(utils::path(*filename_opt)); - ret &= export_task_ptr->set_stage_name(stage_name); if (!ret) { return false; }