diff --git a/src/MaaCore/Task/AbstractTask.cpp b/src/MaaCore/Task/AbstractTask.cpp index 8a573bb507..4dd61af879 100644 --- a/src/MaaCore/Task/AbstractTask.cpp +++ b/src/MaaCore/Task/AbstractTask.cpp @@ -15,6 +15,7 @@ #include "Controller/Controller.h" #include "MaaUtils/ImageIo.h" #include "ProcessTask.h" +#include "Utils/DebugImageHelper.hpp" #include "Utils/Logger.hpp" #include "Utils/StringMisc.hpp" @@ -157,71 +158,5 @@ void asst::AbstractTask::click_return_button() bool asst::AbstractTask::save_img(const std::filesystem::path& relative_dir, bool use_cache, bool auto_clean) { auto image = use_cache ? ctrler()->get_image_cache() : ctrler()->get_image(); - if (image.empty()) { - return false; - } - std::string stem = MAA_NS::format_now_for_filename(); - - if (auto_clean) { - // 第1次或每执行 debug.clean_files_freq(50) 次后执行清理 - // 限制文件数量 debug.max_debug_file_num - if (m_save_file_cnt[relative_dir] == 0) { - filenum_ctrl(relative_dir, Config.get_options().debug.max_debug_file_num); - m_save_file_cnt[relative_dir] = 0; - } - m_save_file_cnt[relative_dir] = - (m_save_file_cnt[relative_dir] + 1) % Config.get_options().debug.clean_files_freq; - } - - auto relative_path = relative_dir / (stem + "_raw.png"); - Log.trace("Save image", relative_path); - return MAA_NS::imwrite(relative_path, image); -} - -size_t asst::AbstractTask::filenum_ctrl(const std::filesystem::path& relative_dir, size_t max_files) -{ - std::filesystem::path absolute_path; - if (relative_dir.is_relative()) [[likely]] { - const auto& user_dir = UserDir.get(); - absolute_path = user_dir / relative_dir; - } - else { - absolute_path = relative_dir; - } - if (!std::filesystem::exists(absolute_path)) { - return 0; - } - - size_t file_nums = 0; - std::vector> filepaths; - std::filesystem::directory_iterator iter(absolute_path); - for (auto& file : iter) { - if (file.is_regular_file()) { - ++file_nums; - filepaths.emplace_back(last_write_time(file.path()), file.path()); - } - } - - std::sort( - filepaths.begin(), - filepaths.end(), - [](const std::pair& a, - const std::pair& b) { - if (a.first != b.first) { - return a.first < b.first; - } - return a.second < b.second; - }); - - long long to_del = file_nums - max_files; - size_t deleted = 0; - - for (int i = 0; i < to_del; ++i) { - auto path = filepaths[i].second; - if (std::filesystem::remove(path)) { - deleted++; - } - } - LogTrace << "Finish folder cleanup delete " << deleted << " files from " << absolute_path; - return deleted; + return utils::save_debug_image(image, relative_dir, auto_clean); } diff --git a/src/MaaCore/Task/AbstractTask.h b/src/MaaCore/Task/AbstractTask.h index 26da0c34d6..05ef3f4e1d 100644 --- a/src/MaaCore/Task/AbstractTask.h +++ b/src/MaaCore/Task/AbstractTask.h @@ -94,8 +94,6 @@ protected: const std::filesystem::path& relative_dir = utils::path("debug"), bool use_cache = true, bool auto_clean = true); - size_t filenum_ctrl(const std::filesystem::path& relative_dir, size_t max_files = 1000); - json::value basic_info_with_what(std::string what) const; bool m_enable = true; @@ -108,6 +106,5 @@ protected: mutable json::value m_basic_info_cache; int m_task_id = 0; std::vector m_plugins; - std::map m_save_file_cnt; }; } // namespace asst diff --git a/src/MaaCore/Task/Fight/FightTimesTaskPlugin.cpp b/src/MaaCore/Task/Fight/FightTimesTaskPlugin.cpp index 2726d3f214..13c40af066 100644 --- a/src/MaaCore/Task/Fight/FightTimesTaskPlugin.cpp +++ b/src/MaaCore/Task/Fight/FightTimesTaskPlugin.cpp @@ -6,6 +6,7 @@ #include "MaaUtils/ImageIo.h" #include "MaaUtils/NoWarningCV.hpp" #include "Task/ProcessTask.h" +#include "Utils/DebugImageHelper.hpp" #include "Vision/Matcher.h" #include "Vision/MultiMatcher.h" #include "Vision/RegionOCRer.h" @@ -127,18 +128,8 @@ bool asst::FightTimesTaskPlugin::open_series_list(const cv::Mat& image) .run()) { Log.error(__FUNCTION__, "unable to open series list"); const auto relative_dir = utils::path("debug") / utils::path("fightSeries"); - - std::filesystem::path relative_path; - - if (!image.empty()) { - relative_path = relative_dir / (std::format("{}_raw.png", MAA_NS::format_now_for_filename())); - Log.info(std::format("Save reusable image to {}", relative_path.string())); - MAA_NS::imwrite(relative_path, image); - } - - relative_path = relative_dir / (std::format("{}_raw.png", MAA_NS::format_now_for_filename())); - Log.info(std::format("Save current screenshot to {}", relative_path.string())); - MAA_NS::imwrite(relative_path, ctrler()->get_image()); + utils::save_debug_image(image, relative_dir, true, nullptr, "reusable image"); + utils::save_debug_image(ctrler()->get_image(), relative_dir, true, nullptr, "current screenshot"); return false; } diff --git a/src/MaaCore/Task/Miscellaneous/SupportList.cpp b/src/MaaCore/Task/Miscellaneous/SupportList.cpp index 4531b6e86f..d600e5b33c 100644 --- a/src/MaaCore/Task/Miscellaneous/SupportList.cpp +++ b/src/MaaCore/Task/Miscellaneous/SupportList.cpp @@ -6,6 +6,7 @@ #include "Controller/Controller.h" #include "MaaUtils/ImageIo.h" #include "Task/ProcessTask.h" +#include "Utils/DebugImageHelper.hpp" #include "Utils/Logger.hpp" #include "Vision/Battle/SupportListAnalyzer.h" #include "Vision/Matcher.h" @@ -623,8 +624,5 @@ std::string asst::SupportList::get_suffix_str(const std::string& s, const char d bool asst::SupportList::save_img(const cv::Mat& image, const std::string_view description) { - const auto relative_dir = utils::path("debug") / utils::path("supportList"); - const auto relative_path = relative_dir / (std::format("{}_raw.png", MAA_NS::format_now_for_filename())); - Log.info(std::format("Save {} to {}", description, relative_path.string())); - return MAA_NS::imwrite(relative_path, image); + return utils::save_debug_image(image, utils::path("debug") / "supportList", true, description); } diff --git a/src/MaaCore/Task/Roguelike/JieGarden/RoguelikeCoppersTaskPlugin.cpp b/src/MaaCore/Task/Roguelike/JieGarden/RoguelikeCoppersTaskPlugin.cpp index c8b4180217..9dc8d2cc7f 100644 --- a/src/MaaCore/Task/Roguelike/JieGarden/RoguelikeCoppersTaskPlugin.cpp +++ b/src/MaaCore/Task/Roguelike/JieGarden/RoguelikeCoppersTaskPlugin.cpp @@ -5,6 +5,7 @@ #include "Controller/Controller.h" #include "MaaUtils/ImageIo.h" #include "Task/ProcessTask.h" +#include "Utils/DebugImageHelper.hpp" #include "Utils/Logger.hpp" #include "Vision/Matcher.h" #include "Vision/Roguelike/JieGarden/RoguelikeCoppersAnalyzer.h" @@ -530,15 +531,9 @@ std::optional asst::RoguelikeCoppersTaskPlugin::create_co cv::Mat screen = ctrler()->get_image(); if (!screen.empty()) { cv::Mat screen_draw = screen.clone(); - const static std::vector jpeg_params = { cv::IMWRITE_JPEG_QUALITY, 95, cv::IMWRITE_JPEG_OPTIMIZE, 1 }; - // 在图像上绘制红色矩形标记未知通宝位置 cv::rectangle(screen_draw, cv::Rect(pos.x, pos.y, pos.width, pos.height), cv::Scalar(0, 0, 255), 2); - const std::filesystem::path& relative_dir = utils::path("debug") / utils::path("roguelike") / - utils::path("roguelikeCoppers") / utils::path("unknown"); - const auto relative_path = - relative_dir / (std::format("{}_unknown_draw.jpeg", MAA_NS::format_now_for_filename())); - Log.debug(__FUNCTION__, "| Saving unknown copper debug image to", relative_path); - MAA_NS::imwrite(relative_path, screen_draw, jpeg_params); + + save_debug_image(screen_draw, "unknown_draw"); } } catch (const std::exception& e) { @@ -594,13 +589,15 @@ void asst::RoguelikeCoppersTaskPlugin::save_debug_image(const cv::Mat& image, co { try { const static std::vector jpeg_params = { cv::IMWRITE_JPEG_QUALITY, 95, cv::IMWRITE_JPEG_OPTIMIZE, 1 }; - // 保存到debug/roguelikeCoppers目录 - const std::filesystem::path& relative_dir = - utils::path("debug") / utils::path("roguelike") / utils::path("roguelikeCoppers"); - const auto& relative_path = - relative_dir / (std::format("{}_{}_draw.jpeg", MAA_NS::format_now_for_filename(), suffix)); - Log.debug(__FUNCTION__, "| Saving debug image to ", relative_path); - MAA_NS::imwrite(relative_path, image, jpeg_params); + + utils::save_debug_image( + image, + utils::path("debug") / "roguelike" / "coppers", + true, + "roguelikeCoppers debug", + suffix, + "jpeg", + jpeg_params); } catch (const std::exception& e) { Log.error(__FUNCTION__, "| failed to save debug image:", e.what()); diff --git a/src/MaaCore/Task/Roguelike/JieGarden/RoguelikeCoppersTaskPlugin.h b/src/MaaCore/Task/Roguelike/JieGarden/RoguelikeCoppersTaskPlugin.h index 8eadd080d1..b4a205f730 100644 --- a/src/MaaCore/Task/Roguelike/JieGarden/RoguelikeCoppersTaskPlugin.h +++ b/src/MaaCore/Task/Roguelike/JieGarden/RoguelikeCoppersTaskPlugin.h @@ -72,10 +72,9 @@ private: cv::Mat& image, const RoguelikeCoppersAnalyzer::CopperDetection& detection, const cv::Scalar& color) const; - +#endif // 保存调试图像到文件 void save_debug_image(const cv::Mat& image, const std::string& suffix) const; -#endif mutable asst::CoppersTaskRunMode m_run_mode; // 当前运行模式 diff --git a/src/MaaCore/Task/Roguelike/Map/RoguelikeBoskyPassageRoutingTaskPlugin.cpp b/src/MaaCore/Task/Roguelike/Map/RoguelikeBoskyPassageRoutingTaskPlugin.cpp index e1af955814..adcf26e9b9 100644 --- a/src/MaaCore/Task/Roguelike/Map/RoguelikeBoskyPassageRoutingTaskPlugin.cpp +++ b/src/MaaCore/Task/Roguelike/Map/RoguelikeBoskyPassageRoutingTaskPlugin.cpp @@ -5,6 +5,7 @@ #include "Controller/Controller.h" #include "MaaUtils/ImageIo.h" #include "Task/ProcessTask.h" +#include "Utils/DebugImageHelper.hpp" #include "Utils/Logger.hpp" #include "Vision/Matcher.h" #include "Vision/MultiMatcher.h" @@ -172,10 +173,13 @@ void asst::RoguelikeBoskyPassageRoutingTaskPlugin::bosky_update_map() } #ifdef ASST_DEBUG - const std::filesystem::path& relative_dir = utils::path("debug") / utils::path("roguelikeMap"); - const auto relative_path = relative_dir / (std::format("{}_bosky_draw.png", MAA_NS::format_now_for_filename())); - Log.debug(__FUNCTION__, "| Saving bosky map image to", relative_path); - MAA_NS::imwrite(relative_path, image_draw); + utils::save_debug_image( + image_draw, + utils::path("debug") / "roguelikeMap", + /*auto_clean=*/true, + /*save_cnt=*/nullptr, + /*description=*/"bosky map draw", + /*suffix=*/"draw"); #endif Log.info(__FUNCTION__, "| map updated with", RoguelikeBoskyPassageMap::get_instance().size(), "nodes"); diff --git a/src/MaaCore/Task/Roguelike/Map/RoguelikeRoutingTaskPlugin.cpp b/src/MaaCore/Task/Roguelike/Map/RoguelikeRoutingTaskPlugin.cpp index 9cbd6f451c..e8c0660293 100644 --- a/src/MaaCore/Task/Roguelike/Map/RoguelikeRoutingTaskPlugin.cpp +++ b/src/MaaCore/Task/Roguelike/Map/RoguelikeRoutingTaskPlugin.cpp @@ -8,6 +8,7 @@ #include "MaaUtils/ImageIo.h" #include "MaaUtils/NoWarningCV.hpp" #include "Task/ProcessTask.h" +#include "Utils/DebugImageHelper.hpp" #include "Utils/Logger.hpp" #include "Vision/Matcher.h" #include "Vision/Miscellaneous/PixelAnalyzer.h" @@ -115,10 +116,13 @@ bool asst::RoguelikeRoutingTaskPlugin::_run() cv::Mat image_draw = image.clone(); update_map(image, RoguelikeMap::INIT_INDEX + 1, image_draw); #ifdef ASST_DEBUG - const std::filesystem::path& relative_dir = utils::path("debug") / utils::path("roguelikeMap"); - const auto relative_path = relative_dir / (std::format("{}_draw.png", MAA_NS::format_now_for_filename())); - Log.trace("Save image", relative_path); - MAA_NS::imwrite(relative_path, image_draw); + utils::save_debug_image( + image_draw, + utils::path("debug") / "roguelikeMap", + /*auto_clean=*/true, + /*save_cnt=*/nullptr, + /*description=*/"bosky map draw", + /*suffix=*/"draw"); #endif m_need_generate_map = false; @@ -183,10 +187,13 @@ bool asst::RoguelikeRoutingTaskPlugin::_run() cv::Mat image_draw = image.clone(); update_map(image, RoguelikeMap::INIT_INDEX + 1, image_draw); #ifdef ASST_DEBUG - const std::filesystem::path& relative_dir = utils::path("debug") / utils::path("roguelikeMap"); - const auto relative_path = relative_dir / (std::format("{}_draw.png", MAA_NS::format_now_for_filename())); - Log.trace("Save image", relative_path); - MAA_NS::imwrite(relative_path, image_draw); + utils::save_debug_image( + image_draw, + utils::path("debug") / "roguelikeMap", + /*auto_clean=*/true, + /*save_cnt=*/nullptr, + /*description=*/"bosky map draw", + /*suffix=*/"draw"); #endif m_need_generate_map = false; } diff --git a/src/MaaCore/Task/Roguelike/RoguelikeSettlementTaskPlugin.cpp b/src/MaaCore/Task/Roguelike/RoguelikeSettlementTaskPlugin.cpp index f9a4eaac32..bf83f02753 100644 --- a/src/MaaCore/Task/Roguelike/RoguelikeSettlementTaskPlugin.cpp +++ b/src/MaaCore/Task/Roguelike/RoguelikeSettlementTaskPlugin.cpp @@ -4,6 +4,7 @@ #include "Config/TaskData.h" #include "Controller/Controller.h" #include "MaaUtils/ImageIo.h" +#include "Utils/DebugImageHelper.hpp" #include "Vision/Matcher.h" #include "Vision/RegionOCRer.h" @@ -149,24 +150,7 @@ bool asst::RoguelikeSettlementTaskPlugin::wait_for_whole_page() void asst::RoguelikeSettlementTaskPlugin::save_img( const cv::Mat& image, const std::filesystem::path& relative_dir, - std::string name) + std::string suffix) { - if (image.empty()) { - return; - } - - { - // 第1次或每执行 debug.clean_files_freq(50) 次后执行清理 - // 限制文件数量 debug.max_debug_file_num - if (m_save_file_cnt[relative_dir] == 0) { - filenum_ctrl(relative_dir, Config.get_options().debug.max_debug_file_num); - m_save_file_cnt[relative_dir] = 0; - } - m_save_file_cnt[relative_dir] = - (m_save_file_cnt[relative_dir] + 1) % Config.get_options().debug.clean_files_freq; - } - - auto relative_path = relative_dir / (std::format("{}_{}.png", MAA_NS::format_now_for_filename(), name)); - Log.trace("Save image", relative_path); - MAA_NS::imwrite(relative_path, image); + utils::save_debug_image(image, relative_dir, true, "", suffix); } diff --git a/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.cpp b/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.cpp index 61b7b0e4fc..a7a471aa91 100644 --- a/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.cpp +++ b/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.cpp @@ -7,6 +7,7 @@ #include "MaaUtils/NoWarningCV.hpp" #include "Task/ProcessTask.h" #include "Task/Roguelike/Map/RoguelikeBoskyPassageMap.h" +#include "Utils/DebugImageHelper.hpp" #include "Utils/Logger.hpp" #include "Vision/Matcher.h" #include "Vision/RegionOCRer.h" @@ -593,8 +594,5 @@ std::optional asst::RoguelikeStageEncounterTaskPlugin::next_event(c bool asst::RoguelikeStageEncounterTaskPlugin::save_img(const cv::Mat& image, const std::string_view description) { - const auto relative_dir = utils::path("debug") / utils::path("roguelike") / utils::path("encounter"); - const auto relative_path = relative_dir / (std::format("{}_raw.png", MAA_NS::format_now_for_filename())); - Log.info(std::format("Save {} to {}", description, relative_path.string())); - return MAA_NS::imwrite(relative_path, image); + return utils::save_debug_image(image, utils::path("debug") / "roguelike" / "encounter", true, description); } diff --git a/src/MaaCore/Utils/DebugImageHelper.hpp b/src/MaaCore/Utils/DebugImageHelper.hpp new file mode 100644 index 0000000000..9f59ab035a --- /dev/null +++ b/src/MaaCore/Utils/DebugImageHelper.hpp @@ -0,0 +1,108 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "Config/GeneralConfig.h" +#include "MaaUtils/ImageIo.h" +#include "MaaUtils/NoWarningCV.hpp" +#include "Utils/Logger.hpp" + +namespace asst::utils +{ +inline size_t filenum_ctrl(const std::filesystem::path& absolute_or_relative_dir, size_t max_files) +{ + std::filesystem::path absolute_path; + if (absolute_or_relative_dir.is_relative()) { + absolute_path = UserDir.get() / absolute_or_relative_dir; + } + else { + absolute_path = absolute_or_relative_dir; + } + + if (!std::filesystem::exists(absolute_path)) { + return 0; + } + + size_t file_nums = 0; + std::vector> files; + + for (auto& file : std::filesystem::directory_iterator(absolute_path)) { + if (file.is_regular_file()) { + ++file_nums; + files.emplace_back(std::filesystem::last_write_time(file.path()), file.path()); + } + } + + std::sort(files.begin(), files.end(), [](auto& a, auto& b) { + if (a.first != b.first) { + return a.first < b.first; + } + return a.second < b.second; + }); + + size_t excess = 0; + if (file_nums > max_files) { + excess = file_nums - max_files; + } + else { + return 0; + } + + size_t deleted = 0; + for (size_t i = 0; i < excess; ++i) { + if (std::filesystem::remove(files[i].second)) { + ++deleted; + } + } + + return deleted; +} + +inline bool save_debug_image( + const cv::Mat& image, + const std::filesystem::path& relative_dir, + bool auto_clean, + std::string_view description = "", + std::string_view suffix = "", + const std::string& ext = "png", + const std::vector& params = {}) +{ + if (image.empty()) { + return false; + } + + static std::map s_save_cnt; + static std::mutex s_mutex; + + auto norm_dir = relative_dir.lexically_normal(); + + if (auto_clean) { + std::lock_guard lock(s_mutex); + auto& cnt = s_save_cnt[norm_dir]; + if (cnt == 0) { + filenum_ctrl(norm_dir, Config.get_options().debug.max_debug_file_num); + cnt = 0; + } + cnt = (cnt + 1) % Config.get_options().debug.clean_files_freq; + } + + std::string stem = MAA_NS::format_now_for_filename(); + std::string filename = suffix.empty() ? (stem + "_raw." + ext) : (stem + "_" + std::string(suffix) + "." + ext); + auto relative_path = norm_dir / filename; + + if (description.empty()) { + Log.trace("Save image", relative_path); + } + else { + LogInfo << "Save" << description << "to" << relative_path; + } + + return MAA_NS::imwrite(relative_path, image, params); +} +} // namespace asst::utils diff --git a/src/MaaCore/Vision/Battle/SupportListAnalyzer.cpp b/src/MaaCore/Vision/Battle/SupportListAnalyzer.cpp index bda8965609..0cda2bb5c9 100644 --- a/src/MaaCore/Vision/Battle/SupportListAnalyzer.cpp +++ b/src/MaaCore/Vision/Battle/SupportListAnalyzer.cpp @@ -3,6 +3,7 @@ #include "Config/TaskData.h" #include "MaaUtils/ImageIo.h" #include "MaaUtils/NoWarningCV.hpp" +#include "Utils/DebugImageHelper.hpp" #include "Vision/Miscellaneous/PixelAnalyzer.h" #include "Vision/RegionOCRer.h" @@ -398,8 +399,5 @@ std::optional asst::SupportListAnalyzer::get_suffix_num(const std::string& bool asst::SupportListAnalyzer::save_img(const cv::Mat& image, const std::string_view description) { - const auto relative_dir = utils::path("debug") / utils::path("supportListAnalyzer"); - const auto relative_path = relative_dir / (std::format("{}_raw.png", MAA_NS::format_now_for_filename())); - Log.info(std::format("Save {} to {}", description, relative_path.string())); - return MAA_NS::imwrite(relative_path, image); + return utils::save_debug_image(image, utils::path("debug") / "supportListAnalyzer", true, description); } diff --git a/src/MaaCore/Vision/Matcher.cpp b/src/MaaCore/Vision/Matcher.cpp index 1905fd5a25..930b8134dc 100644 --- a/src/MaaCore/Vision/Matcher.cpp +++ b/src/MaaCore/Vision/Matcher.cpp @@ -5,6 +5,7 @@ #include "Config/TaskData.h" #include "Config/TemplResource.h" #include "MaaUtils/ImageIo.h" +#include "Utils/DebugImageHelper.hpp" #include "Utils/Logger.hpp" #include "Utils/StringMisc.hpp" @@ -57,10 +58,7 @@ Matcher::ResultOpt Matcher::analyze() const 95, cv::IMWRITE_JPEG_OPTIMIZE, 1 }; - MAA_NS::imwrite( - utils::path(std::format("debug/hsv/{}_{}.jpg", text, MAA_NS::format_now_for_filename())), - cropped, - jpeg_params); + utils::save_debug_image(cropped, utils::path("debug") / "hsv", true, text, "", "jpeg", jpeg_params); } #endif } diff --git a/src/MaaCore/Vision/Roguelike/RoguelikeEncounterOptionAnalyzer.cpp b/src/MaaCore/Vision/Roguelike/RoguelikeEncounterOptionAnalyzer.cpp index 39629a57a2..8fffcd471c 100644 --- a/src/MaaCore/Vision/Roguelike/RoguelikeEncounterOptionAnalyzer.cpp +++ b/src/MaaCore/Vision/Roguelike/RoguelikeEncounterOptionAnalyzer.cpp @@ -3,6 +3,7 @@ #include "Config/TaskData.h" #include "MaaUtils/ImageIo.h" #include "Task/Roguelike/RoguelikeConfig.h" +#include "Utils/DebugImageHelper.hpp" #include "Utils/Logger.hpp" #include "Vision/RegionOCRer.h" @@ -304,8 +305,5 @@ cv::Mat asst::RoguelikeEncounterOptionAnalyzer::binarize_for_ocr(const cv::Mat& bool asst::RoguelikeEncounterOptionAnalyzer::save_img(const cv::Mat& image, const std::string_view description) { - const auto relative_dir = utils::path("debug") / utils::path("roguelike") / utils::path("encounter"); - const auto relative_path = relative_dir / (std::format("{}_raw.png", MAA_NS::format_now_for_filename())); - Log.info(std::format("Save {} to {}", description, relative_path.string())); - return MAA_NS::imwrite(relative_path, image); + return utils::save_debug_image(image, utils::path("debug") / "roguelike" / "encounter", true, description); } diff --git a/src/MaaCore/Vision/VisionHelper.cpp b/src/MaaCore/Vision/VisionHelper.cpp index b5192bd85a..ae1301e350 100644 --- a/src/MaaCore/Vision/VisionHelper.cpp +++ b/src/MaaCore/Vision/VisionHelper.cpp @@ -6,6 +6,7 @@ #include "InstHelper.h" #include "MaaUtils/ImageIo.h" #include "MaaUtils/Time.hpp" +#include "Utils/DebugImageHelper.hpp" #include "Utils/Logger.hpp" #include "Utils/StringMisc.hpp" @@ -131,13 +132,10 @@ cv::Mat asst::VisionHelper::create_mask(const cv::Mat& image, const cv::Rect& ro bool VisionHelper::save_img(const std::filesystem::path& relative_dir) { - std::string stem = MAA_NS::format_now_for_filename(); - auto relative_path = relative_dir / (stem + "_raw.png"); - Log.trace("Save image", relative_path); - bool ret = MAA_NS::imwrite(relative_path, m_image); + bool ret = utils::save_debug_image(m_image, relative_dir, true); #ifdef ASST_DEBUG - MAA_NS::imwrite(relative_dir / (stem + "_draw.png"), m_image_draw); + utils::save_debug_image(m_image_draw, relative_dir, true, "", "draw"); #endif return ret;