From 0d081cd4c3f3739fe40f0fcf8a8440ee46251535 Mon Sep 17 00:00:00 2001 From: MistEO Date: Tue, 4 Jan 2022 15:15:49 +0800 Subject: [PATCH] =?UTF-8?q?chore.=E4=BC=98=E5=8C=96=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=92=8C=E8=B0=83=E8=AF=95=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAssistant/AbstractImageAnalyzer.cpp | 6 +- src/MeoAssistant/AbstractImageAnalyzer.h | 2 +- src/MeoAssistant/Assistant.cpp | 2 +- src/MeoAssistant/Assistant.h | 2 +- src/MeoAssistant/AsstCaller.cpp | 8 +- src/MeoAssistant/CreditShopImageAnalyzer.cpp | 6 +- .../InfrastClueVacancyImageAnalyzer.cpp | 2 +- .../InfrastFacilityImageAnalyzer.cpp | 2 +- src/MeoAssistant/InfrastOperImageAnalyzer.cpp | 14 +- src/MeoAssistant/InfrastProductionTask.cpp | 16 +- src/MeoAssistant/InfrastProductionTask.h | 2 +- .../InfrastSmileyImageAnalyzer.cpp | 2 +- src/MeoAssistant/Logger.hpp | 13 +- src/MeoAssistant/MeoAssistant.vcxproj | 514 +++++++++--------- src/MeoAssistant/TaskData.cpp | 4 +- 15 files changed, 298 insertions(+), 297 deletions(-) diff --git a/src/MeoAssistant/AbstractImageAnalyzer.cpp b/src/MeoAssistant/AbstractImageAnalyzer.cpp index c297691e51..27aedc783f 100644 --- a/src/MeoAssistant/AbstractImageAnalyzer.cpp +++ b/src/MeoAssistant/AbstractImageAnalyzer.cpp @@ -5,7 +5,7 @@ asst::AbstractImageAnalyzer::AbstractImageAnalyzer(const cv::Mat image) : m_image(image), m_roi(empty_rect_to_full(Rect(), image)) -#ifdef LOG_TRACE +#ifdef ASST_DEBUG , m_image_draw(image.clone()) #endif @@ -15,7 +15,7 @@ asst::AbstractImageAnalyzer::AbstractImageAnalyzer(const cv::Mat image) asst::AbstractImageAnalyzer::AbstractImageAnalyzer(const cv::Mat image, const Rect& roi) : m_image(image), m_roi(empty_rect_to_full(roi, image)) -#ifdef LOG_TRACE +#ifdef ASST_DEBUG , m_image_draw(image.clone()) #endif @@ -26,7 +26,7 @@ asst::AbstractImageAnalyzer::AbstractImageAnalyzer(const cv::Mat image, const Re void asst::AbstractImageAnalyzer::set_image(const cv::Mat image) { m_image = image; -#ifdef LOG_TRACE +#ifdef ASST_DEBUG m_image_draw = image.clone(); #endif } diff --git a/src/MeoAssistant/AbstractImageAnalyzer.h b/src/MeoAssistant/AbstractImageAnalyzer.h index f29a80738c..d8e93d3ad7 100644 --- a/src/MeoAssistant/AbstractImageAnalyzer.h +++ b/src/MeoAssistant/AbstractImageAnalyzer.h @@ -34,7 +34,7 @@ namespace asst cv::Mat m_image; Rect m_roi; -#ifdef LOG_TRACE +#ifdef ASST_DEBUG cv::Mat m_image_draw; #endif }; diff --git a/src/MeoAssistant/Assistant.cpp b/src/MeoAssistant/Assistant.cpp index 58e06241d1..8c3d5780d1 100644 --- a/src/MeoAssistant/Assistant.cpp +++ b/src/MeoAssistant/Assistant.cpp @@ -328,7 +328,7 @@ bool asst::Assistant::append_recruit(unsigned max_times, const std::vector& return true; } -#ifdef LOG_TRACE +#ifdef ASST_DEBUG bool Assistant::append_debug() { LogTraceFunction; diff --git a/src/MeoAssistant/Assistant.h b/src/MeoAssistant/Assistant.h index fd05f18465..9720371194 100644 --- a/src/MeoAssistant/Assistant.h +++ b/src/MeoAssistant/Assistant.h @@ -60,7 +60,7 @@ namespace asst // 参数 use_expedited: 是否使用加急券 bool append_recruit(unsigned max_times, const std::vector& select_level, const std::vector& confirm_level, bool need_refresh, bool use_expedited); -#ifdef LOG_TRACE +#ifdef ASST_DEBUG // 调试用 bool append_debug(); #endif diff --git a/src/MeoAssistant/AsstCaller.cpp b/src/MeoAssistant/AsstCaller.cpp index 984999f03e..62386a4fe4 100644 --- a/src/MeoAssistant/AsstCaller.cpp +++ b/src/MeoAssistant/AsstCaller.cpp @@ -106,7 +106,7 @@ bool AsstCatchCustom(asst::Assistant* p_asst, const char* address) bool AsstCatchFake(asst::Assistant* p_asst) { -#ifdef LOG_TRACE +#ifdef ASST_DEBUG if (p_asst == nullptr) { return false; } @@ -115,7 +115,7 @@ bool AsstCatchFake(asst::Assistant* p_asst) #else (void*)p_asst; return false; -#endif // LOG_TRACE +#endif // ASST_DEBUG } bool ASSTAPI AsstAppendStartUp(asst::Assistant* p_asst) @@ -257,9 +257,9 @@ bool AsstAppendDebug(asst::Assistant* p_asst) if (p_asst == nullptr) { return false; } -#if LOG_TRACE +#if ASST_DEBUG return p_asst->append_debug(); #else return false; -#endif // LOG_TRACE +#endif // ASST_DEBUG } diff --git a/src/MeoAssistant/CreditShopImageAnalyzer.cpp b/src/MeoAssistant/CreditShopImageAnalyzer.cpp index 02ee00c654..bcba465f17 100644 --- a/src/MeoAssistant/CreditShopImageAnalyzer.cpp +++ b/src/MeoAssistant/CreditShopImageAnalyzer.cpp @@ -65,7 +65,7 @@ bool asst::CreditShopImageAnalyzer::whether_to_buy_analyze() continue; } -#ifdef LOG_TRACE +#ifdef ASST_DEBUG cv::rectangle(m_image_draw, utils::make_rect(commodity), cv::Scalar(0, 0, 255), 2); #endif m_need_to_buy.emplace_back(commodity); @@ -85,10 +85,10 @@ bool asst::CreditShopImageAnalyzer::sold_out_analyze() for (const Rect& commodity : m_need_to_buy) { sold_out_analyzer.set_roi(commodity); if (sold_out_analyzer.analyze()) { -#ifdef LOG_TRACE +#ifdef ASST_DEBUG cv::rectangle(m_image_draw, utils::make_rect(commodity), cv::Scalar(0, 0, 255)); cv::putText(m_image_draw, "Sold Out", cv::Point(commodity.x, commodity.y), 1, 2, cv::Scalar(255, 0, 0)); -#endif // LOG_TRACE +#endif // ASST_DEBUG // 如果识别到了售罄,那这个商品就不用买了,跳过 continue; diff --git a/src/MeoAssistant/InfrastClueVacancyImageAnalyzer.cpp b/src/MeoAssistant/InfrastClueVacancyImageAnalyzer.cpp index 11ab2663ad..351f849554 100644 --- a/src/MeoAssistant/InfrastClueVacancyImageAnalyzer.cpp +++ b/src/MeoAssistant/InfrastClueVacancyImageAnalyzer.cpp @@ -20,7 +20,7 @@ bool asst::InfrastClueVacancyImageAnalyzer::analyze() } Rect rect = analyzer.get_result().rect; Log.trace("has", clue_vacancy, suffix); -#ifdef LOG_TRACE +#ifdef ASST_DEBUG cv::rectangle(m_image_draw, utils::make_rect(rect), cv::Scalar(0, 0, 255), 2); cv::putText(m_image_draw, suffix, cv::Point(rect.x, rect.y + 1), 0, 1, cv::Scalar(0, 0, 255), 2); #endif diff --git a/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp b/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp index ec3d3c5a03..015e58df83 100644 --- a/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp +++ b/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp @@ -79,7 +79,7 @@ bool asst::InfrastFacilityImageAnalyzer::analyze() continue; } -#ifdef LOG_TRACE +#ifdef ASST_DEBUG cv::RNG rng(time(0)); cv::Scalar rand_color(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)); int index = 0; diff --git a/src/MeoAssistant/InfrastOperImageAnalyzer.cpp b/src/MeoAssistant/InfrastOperImageAnalyzer.cpp index 9c819ed3bd..94785275e4 100644 --- a/src/MeoAssistant/InfrastOperImageAnalyzer.cpp +++ b/src/MeoAssistant/InfrastOperImageAnalyzer.cpp @@ -114,9 +114,9 @@ void asst::InfrastOperImageAnalyzer::oper_detect() continue; } -#ifdef LOG_TRACE +#ifdef ASST_DEBUG cv::rectangle(m_image_draw, utils::make_rect(smiley_rect), cv::Scalar(0, 0, 255), 2); -#endif // LOG_TRACE +#endif // ASST_DEBUG infrast::Oper oper; oper.smiley = smiley; @@ -193,12 +193,12 @@ void asst::InfrastOperImageAnalyzer::mood_analyze() // TODO:这里的进度条长度算的并不是特别准,属于能跑就行。有空再优化下 double ratio = static_cast(max_white_length) / roi.width; oper.mood_ratio = ratio; -#ifdef LOG_TRACE +#ifdef ASST_DEBUG cv::Point p1(roi.x, roi.y); cv::Point p2(roi.x + max_white_length, roi.y); cv::line(m_image_draw, p1, p2, cv::Scalar(0, 255, 0), 1); cv::putText(m_image_draw, std::to_string(ratio), p1, 1, 1.0, cv::Scalar(0, 255, 0)); -#endif // LOG_TRACE +#endif // ASST_DEBUG } } @@ -307,7 +307,7 @@ void asst::InfrastOperImageAnalyzer::skill_analyze() skill_rect.x += roi.x; skill_rect.y += roi.y; -#ifdef LOG_TRACE +#ifdef ASST_DEBUG cv::rectangle(m_image_draw, utils::make_rect(skill_rect), cv::Scalar(0, 255, 0), 2); #endif @@ -370,7 +370,7 @@ void asst::InfrastOperImageAnalyzer::skill_analyze() Log.trace(most_confident_skills.id, most_confident_skills.names.front()); std::string skill_id = most_confident_skills.id; log_str += skill_id + " - " + most_confident_skills.names.front() + "; "; -#ifdef LOG_TRACE +#ifdef ASST_DEBUG cv::Mat skill_mat = m_image(utils::make_rect(skill_rect)); #endif oper.skills.emplace(std::move(most_confident_skills)); @@ -437,7 +437,7 @@ void asst::InfrastOperImageAnalyzer::doing_analyze() working_analyzer.set_roi(working_rect); if (working_analyzer.analyze()) { oper.doing = infrast::Doing::Working; -#ifdef LOG_TRACE +#ifdef ASST_DEBUG cv::putText(m_image_draw, "Working", cv::Point(working_rect.x, working_rect.y), 1, 1, cv::Scalar(0, 0, 255), 2); #endif } diff --git a/src/MeoAssistant/InfrastProductionTask.cpp b/src/MeoAssistant/InfrastProductionTask.cpp index bb770a7273..5108607de1 100644 --- a/src/MeoAssistant/InfrastProductionTask.cpp +++ b/src/MeoAssistant/InfrastProductionTask.cpp @@ -202,9 +202,7 @@ size_t asst::InfrastProductionTask::opers_detect() [&cur_oper](const infrast::Oper& oper) -> bool { // 有可能是同一个干员,比一下hash int dist = utils::hamming(cur_oper.face_hash, oper.face_hash); -#ifdef LOG_TRACE - Log.trace("opers_detect hash dist |", dist); -#endif + Log.debug("opers_detect hash dist |", dist); return dist < m_face_hash_thres; }); // 如果两个的hash距离过小,则认为是同一个干员,不进行插入 @@ -370,9 +368,7 @@ bool asst::InfrastProductionTask::optimal_calc() if (!opt.possible_hashs.empty()) { for (const auto& [key, hash] : opt.possible_hashs) { int dist = utils::hamming(find_iter->name_hash, hash); -#ifdef LOG_TRACE - Log.trace("optimal_calc | name hash dist", dist, hash, find_iter->name_hash); -#endif + Log.debug("optimal_calc | name hash dist", dist, hash, find_iter->name_hash); if (dist < m_name_hash_thres) { hash_matched = true; break; @@ -498,9 +494,7 @@ bool asst::InfrastProductionTask::opers_choose() // 既要技能相同,也要hash相同,双重校验 for (const auto& [_, hash] : opt_iter->possible_hashs) { int dist = utils::hamming(lhs.name_hash, hash); -#ifdef LOG_TRACE - Log.trace("opers_choose | name hash dist", dist); -#endif + Log.debug("opers_choose | name hash dist", dist); if (dist < m_name_hash_thres) { return true; } @@ -529,9 +523,7 @@ bool asst::InfrastProductionTask::opers_choose() m_all_available_opers.cbegin(), m_all_available_opers.cend(), [&](const infrast::Oper& lhs) -> bool { int dist = utils::hamming(lhs.face_hash, find_iter->face_hash); -#ifdef LOG_TRACE - Log.trace("opers_choose | face hash dist", dist); -#endif + Log.debug("opers_choose | face hash dist", dist); if (dist < m_face_hash_thres) { return true; } diff --git a/src/MeoAssistant/InfrastProductionTask.h b/src/MeoAssistant/InfrastProductionTask.h index 949112b0e2..9d6dd17fbf 100644 --- a/src/MeoAssistant/InfrastProductionTask.h +++ b/src/MeoAssistant/InfrastProductionTask.h @@ -17,7 +17,7 @@ namespace asst { m_uses_of_drones = std::move(uses_of_drones); } -#ifdef LOG_TRACE +#ifdef ASST_DEBUG public: #else // 为了方便调试,把这两个个接口拿到public来了 diff --git a/src/MeoAssistant/InfrastSmileyImageAnalyzer.cpp b/src/MeoAssistant/InfrastSmileyImageAnalyzer.cpp index 6a8b504c01..5f05abcf94 100644 --- a/src/MeoAssistant/InfrastSmileyImageAnalyzer.cpp +++ b/src/MeoAssistant/InfrastSmileyImageAnalyzer.cpp @@ -27,7 +27,7 @@ bool asst::InfrastSmileyImageAnalyzer::analyze() auto& res = mm_analyzer.get_result(); for (const MatchRect& mr : res) { temp_result.emplace_back(infrast::Smiley{ type, mr.rect }); -#ifdef LOG_TRACE +#ifdef ASST_DEBUG cv::rectangle(m_image_draw, utils::make_rect(mr.rect), cv::Scalar(0, 0, 255), 2); #endif } diff --git a/src/MeoAssistant/Logger.hpp b/src/MeoAssistant/Logger.hpp index dbfab5e057..e1bc83cd63 100644 --- a/src/MeoAssistant/Logger.hpp +++ b/src/MeoAssistant/Logger.hpp @@ -34,6 +34,15 @@ namespace asst m_dirname = std::move(dirname); } + template + inline void debug([[maybe_unused]] Args&&... args) + { +#ifdef ASST_DEBUG + std::string_view level = "DEB"; + log(level, std::forward(args)...); +#endif + } + template inline void trace(Args&&... args) { @@ -122,13 +131,13 @@ namespace asst if (!m_ofs.is_open()) { m_ofs = std::ofstream(m_log_filename, std::ios::out | std::ios::app); } -#ifdef LOG_TRACE +#ifdef ASST_DEBUG stream_args(m_ofs, buff, args...); #else stream_args(m_ofs, buff, std::forward(args)...); #endif -#ifdef LOG_TRACE +#ifdef ASST_DEBUG stream_args(std::cout, buff, std::forward(args)...); #endif } diff --git a/src/MeoAssistant/MeoAssistant.vcxproj b/src/MeoAssistant/MeoAssistant.vcxproj index eabc213e5a..95d5305716 100644 --- a/src/MeoAssistant/MeoAssistant.vcxproj +++ b/src/MeoAssistant/MeoAssistant.vcxproj @@ -1,260 +1,260 @@ - - - - - Release - x64 - - - RelWithDebInfo - x64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 16.0 - Win32Proj - {362d1e30-f5ae-4279-9985-65c27b3ba300} - MeoAssistant - 10.0 - - - - DynamicLibrary - false - v142 - true - Unicode - - - DynamicLibrary - false - v142 - true - Unicode - - - - - - - - - - - - - - - false - $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath) - $(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath) - - - false - $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath) - $(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath) - - - - Level4 - true - true - true - NDEBUG;_CONSOLE;ASST_DLL_EXPORTS;%(PreprocessorDefinitions) - true - stdcpp17 - stdc11 - MultiThreaded - MaxSpeed - /utf-8 /MP %(AdditionalOptions) - - - Console - true - true - true - meojson.lib;ppocr.lib;opencv_world453.lib;penguin-stats-recognize.lib;zlibstatic.lib;%(AdditionalDependencies) - RequireAdministrator - - - true - - - - - - + + + + + Release + x64 + + + RelWithDebInfo + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 16.0 + Win32Proj + {362d1e30-f5ae-4279-9985-65c27b3ba300} + MeoAssistant + 10.0 + + + + DynamicLibrary + false + v142 + true + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + false + $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath) + $(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath) + + + false + $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath) + $(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath) + + + + Level4 + true + true + true + NDEBUG;_CONSOLE;ASST_DLL_EXPORTS;%(PreprocessorDefinitions) + true + stdcpp17 + stdc11 + MultiThreaded + MaxSpeed + /utf-8 /MP %(AdditionalOptions) + + + Console + true + true + true + meojson.lib;ppocr.lib;opencv_world453.lib;penguin-stats-recognize.lib;zlibstatic.lib;%(AdditionalDependencies) + RequireAdministrator + + + true + + + + + + xcopy /e /y /i /c $(SolutionDir)resource $(TargetDir)resource -xcopy /e /y /i /c $(SolutionDir)3rdparty\resource $(TargetDir)resource - - - copy resource - - - xcopy /e /y /i /c $(SolutionDir)3rdparty\bin $(TargetDir) - - - copy 3rd party dll - - - - - Level4 - - - false - true - NDEBUG;_CONSOLE;ASST_DLL_EXPORTS;LOG_TRACE;DEBUG_API;%(PreprocessorDefinitions) - true - stdcpp17 - stdc11 - MultiThreaded - Disabled - true - EnableFastChecks - /utf-8 /MP %(AdditionalOptions) - - - Console - true - true - true - meojson.lib;ppocr.lib;opencv_world453.lib;penguin-stats-recognize.lib;zlibstatic.lib;%(AdditionalDependencies) - RequireAdministrator - - - true - - - - - - +xcopy /e /y /i /c $(SolutionDir)3rdparty\resource $(TargetDir)resource + + + copy resource + + + xcopy /e /y /i /c $(SolutionDir)3rdparty\bin $(TargetDir) + + + copy 3rd party dll + + + + + Level4 + + + false + true + NDEBUG;_CONSOLE;ASST_DLL_EXPORTS;ASST_DEBUG;%(PreprocessorDefinitions) + true + stdcpp17 + stdc11 + MultiThreaded + Disabled + true + EnableFastChecks + /utf-8 /MP %(AdditionalOptions) + + + Console + true + true + true + meojson.lib;ppocr.lib;opencv_world453.lib;penguin-stats-recognize.lib;zlibstatic.lib;%(AdditionalDependencies) + RequireAdministrator + + + true + + + + + + xcopy /e /y /i /c $(SolutionDir)resource $(TargetDir)resource -xcopy /e /y /i /c $(SolutionDir)3rdparty\resource $(TargetDir)resource - - - copy resource - - - xcopy /e /y /i /c $(SolutionDir)3rdparty\bin $(TargetDir) - - - copy 3rd party dll - - - - - - - - - - +xcopy /e /y /i /c $(SolutionDir)3rdparty\resource $(TargetDir)resource + + + copy resource + + + xcopy /e /y /i /c $(SolutionDir)3rdparty\bin $(TargetDir) + + + copy 3rd party dll + + + + + + + + + + \ No newline at end of file diff --git a/src/MeoAssistant/TaskData.cpp b/src/MeoAssistant/TaskData.cpp index 4b013fffcc..a0f3c6e3b4 100644 --- a/src/MeoAssistant/TaskData.cpp +++ b/src/MeoAssistant/TaskData.cpp @@ -161,7 +161,7 @@ bool asst::TaskData::parse(const json::value& json) int y = area_arr[1].as_integer(); int width = area_arr[2].as_integer(); int height = area_arr[3].as_integer(); -#ifdef LOG_TRACE +#ifdef ASST_DEBUG if (x + width > WindowWidthDefault || y + height > WindowHeightDefault) { m_last_error = name + " roi is out of bounds"; return false; @@ -192,7 +192,7 @@ bool asst::TaskData::parse(const json::value& json) m_all_tasks_info.emplace(name, task_info_ptr); } -#ifdef LOG_TRACE +#ifdef ASST_DEBUG for (const auto& [name, task] : m_all_tasks_info) { for (const auto& next : task->next) { if (m_all_tasks_info.find(next) == m_all_tasks_info.cend()) {