mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 01:59:33 +08:00
* feat: 作业视频识别,基本功能完成 Squashed commit of the following: commit 3488507ebfb291b21ce9dae2d77536c39fc74840 Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 19:05:19 2023 +0800 chore: rename commit ad3446fd823db3ea5cd657cf216fcfdd7063ce0b Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 19:02:34 2023 +0800 perf: 优化视频识别结构 commit 5e5553e3720aa7c8c81d1667af96ffdc192d4281 Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 18:53:13 2023 +0800 fix: build error commit ffe850ea49008e2c7cef281159ef673ffae735f2 Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 18:40:46 2023 +0800 perf: 识别识别不需要连接模拟器 commit 56711ea3ded5b8832b9399591cb93064740ba23c Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 18:40:20 2023 +0800 perf: 优化视频读取性能 commit 1ce5ea3a61a6f270d834d1f2346832debd83f70f Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 16:19:08 2023 +0800 feat: WPF UI 初步集成视频识别 commit d741d0fbef48829e502d9b641d918969c94a7352 Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 15:18:58 2023 +0800 chore: 一些重命名 commit a14652773989c35788dff0262c70cbc4c8c0cd0d Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 14:35:48 2023 +0800 chore: rename and fix build error commit 5ea7d52fab67d7085aceb3147b6940781f5e4b93 Merge: 89db75e0b8bb725eAuthor: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 14:25:15 2023 +0800 Merge branch 'dev' into feat/video_to_json commit 89db75e05cea969417462dfcffb8e0b68233a199 Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 03:49:41 2023 +0800 chore: 导出json文件名 commit 6e1804b1dd49781dfeffc4a846321f8ebfff8b8c Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 03:47:38 2023 +0800 fix: 修复关卡识别错误 commit cc0dab1c1b0e2ff4ce2d62e3996516b13039be2b Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 03:31:39 2023 +0800 feat: 完成关卡名识别、重命名一些变量 commit bf1ab83bcfdeb64dad06c2cc3ac649c77baf317e Author: MistEO <mistereo@hotmail.com> Date: Sat Apr 1 02:23:24 2023 +0800 feat: 第一份作业导出 commit 76ae6262b64f7e7365cd1e7783b2cd4db61600ca Author: MistEO <mistereo@hotmail.com> Date: Fri Mar 31 21:43:00 2023 +0800 chore: rename commit 493cb9c3ab4718f15316c357080fec6930c89a97 Author: MistEO <mistereo@hotmail.com> Date: Fri Mar 31 20:13:45 2023 +0800 perf: 更新战斗识别相关模型 commit 623c80c76792a24c37d7dad5addb8c00341a5688 Author: MistEO <mistereo@hotmail.com> Date: Thu Mar 30 00:02:47 2023 +0800 refactor: 完成视频切片重构 commit 73bbf7c8727d911effa298ccff0a4ae29376baed Author: MistEO <mistereo@hotmail.com> Date: Tue Mar 28 23:54:39 2023 +0800 perf: 优化tensor转换 commit 13ba7a01e1c46ee1f0b6bea55ffaaf30fcf552c3 Merge: 48a4d765a0964485Author: MistEO <mistereo@hotmail.com> Date: Tue Mar 28 22:28:33 2023 +0800 Merge branch 'dev' into feat/video_to_json commit 48a4d765e2a1f1240e8f31352c21f58b565752d2 Author: MistEO <mistereo@hotmail.com> Date: Sat Mar 25 23:22:35 2023 +0800 fix: build error commit 02c80f4442e520998aff3b14fa4decbbc421b6c0 Author: MistEO <mistereo@hotmail.com> Date: Sat Mar 25 04:03:54 2023 +0800 perf: 优化技能ready识别模型 commit 7c15b54bd4a7c97772f27ac8bebaec97dd59f19c Author: MistEO <mistereo@hotmail.com> Date: Sat Mar 25 03:15:46 2023 +0800 perf: 重新训练干员方向检测模型 commit 450eea50a0601676e731411188a74cfc38f21a42 Author: MistEO <mistereo@hotmail.com> Date: Sat Mar 25 01:39:23 2023 +0800 feat: 画了一堆图 commit bf2bc66c6d52ecdc9f7ce0e7fc3a4891bbe59f7c Author: MistEO <mistereo@hotmail.com> Date: Wed Mar 22 23:33:33 2023 +0800 feat: 完成干员部署方向识别 commit f3a0b4aee8e910d5ebc8e42486c5194bd6ffe51e Author: MistEO <mistereo@hotmail.com> Date: Wed Mar 22 22:43:01 2023 +0800 feat: 输出draw,增加一些回调,修复干员位置检测 commit 772fd2dbeaef59812b563aef36808e15f8d33e08 Author: MistEO <mistereo@hotmail.com> Date: Wed Mar 22 18:16:26 2023 +0800 feat: 初步识别上场干员 commit 4fda687bdcbc598c80576f741b518fae8fc87566 Author: MistEO <mistereo@hotmail.com> Date: Wed Mar 22 17:29:57 2023 +0800 perf: 优化一些细节 commit c72a1d7c8a13c1d22d5e2598ae0db87e74d32c26 Author: MistEO <mistereo@hotmail.com> Date: Wed Mar 22 01:10:29 2023 +0800 fix: 修复偶现误识别问题 commit 3021a7372dbad1f920aad346b49f115d4d2e073c Author: MistEO <mistereo@hotmail.com> Date: Wed Mar 22 01:01:21 2023 +0800 feat: 完成干员检测 commit e74072fbbeffd4c0cd7a4d67208a67797341f1fa Author: MistEO <mistereo@hotmail.com> Date: Tue Mar 21 01:34:20 2023 +0800 feat: 完成yolo干员检测模型集成 commit 27a10f0bd0529c71d09aa2434a1ef1fd0cac2449 Author: MistEO <mistereo@hotmail.com> Date: Mon Mar 20 20:39:44 2023 +0800 chore: rename commit 277a620819c1f368392c10f8d74a7b3e9f633a58 Author: MistEO <mistereo@hotmail.com> Date: Sun Mar 19 23:59:12 2023 +0800 feat: 完成编队->部署区识别 commit 9cfda5d295c34f37b592125898ec70105de77f7c Author: MistEO <mistereo@hotmail.com> Date: Sun Mar 19 02:02:11 2023 +0800 feat: 完成编队识别 MaaDeps 需要给 opencv features 加上 ffmpeg * fix: 调整部分参数适应硬解带来的颜色变化问题 * chore: 删除部分日志 * fix: build error * fix: 修复编队识别错误 * fix: 修复部署区识别错误(阈值问题 * fix: 修复初始部署区识别错误 * fix: 修复切片错误,修复部署区识别 * fix: 修了一些bug又制造了一些bug * fix: 修了一些bug又制造了一些bug * fix: typo * fix: 关键帧错误 * fix: 修复部署区偶现识别错误 * fix: 修复暂停按钮偶现识别错误 * feat: 新增技能识别,修复一些bug * fix: 修复变化判断错误 * chore: draw窗口优化
164 lines
4.4 KiB
C++
164 lines
4.4 KiB
C++
#include "AbstractTask.h"
|
|
|
|
#include <algorithm>
|
|
#include <filesystem>
|
|
#include <regex>
|
|
#include <thread>
|
|
#include <utility>
|
|
|
|
#include "Utils/Demangle.hpp"
|
|
#include "Utils/NoWarningCV.h"
|
|
|
|
#include "AbstractTaskPlugin.h"
|
|
#include "Assistant.h"
|
|
#include "Config/GeneralConfig.h"
|
|
#include "Controller/Controller.h"
|
|
#include "ProcessTask.h"
|
|
#include "Utils/ImageIo.hpp"
|
|
#include "Utils/Logger.hpp"
|
|
#include "Utils/StringMisc.hpp"
|
|
|
|
using namespace asst;
|
|
|
|
AbstractTask::AbstractTask(const AsstCallback& callback, Assistant* inst, std::string_view task_chain)
|
|
: InstHelper(inst), m_callback(callback), m_task_chain(task_chain)
|
|
{}
|
|
|
|
bool asst::AbstractTask::run()
|
|
{
|
|
if (!m_enable) {
|
|
Log.info("task disabled, pass", basic_info().to_string());
|
|
return true;
|
|
}
|
|
callback(AsstMsg::SubTaskStart, basic_info());
|
|
for (m_cur_retry = 0; m_cur_retry <= m_retry_times; ++m_cur_retry) {
|
|
if (_run()) {
|
|
callback(AsstMsg::SubTaskCompleted, basic_info());
|
|
return true;
|
|
}
|
|
if (need_exit()) {
|
|
return false;
|
|
}
|
|
int delay = Config.get_options().task_delay;
|
|
sleep(delay);
|
|
|
|
if (!on_run_fails()) {
|
|
callback(AsstMsg::SubTaskError, basic_info());
|
|
return false;
|
|
}
|
|
}
|
|
callback(AsstMsg::SubTaskError, basic_info());
|
|
return false;
|
|
}
|
|
|
|
AbstractTask& asst::AbstractTask::set_retry_times(int times) noexcept
|
|
{
|
|
m_retry_times = times;
|
|
return *this;
|
|
}
|
|
|
|
AbstractTask& asst::AbstractTask::set_enable(bool enable) noexcept
|
|
{
|
|
m_enable = enable;
|
|
return *this;
|
|
}
|
|
|
|
AbstractTask& asst::AbstractTask::set_ignore_error(bool ignore) noexcept
|
|
{
|
|
m_ignore_error = ignore;
|
|
return *this;
|
|
}
|
|
|
|
AbstractTask& asst::AbstractTask::set_task_id(int task_id) noexcept
|
|
{
|
|
m_task_id = task_id;
|
|
return *this;
|
|
}
|
|
|
|
void asst::AbstractTask::clear_plugin() noexcept
|
|
{
|
|
m_plugins.clear();
|
|
}
|
|
|
|
json::value asst::AbstractTask::basic_info() const
|
|
{
|
|
if (m_basic_info_cache.empty()) {
|
|
std::string class_name = utils::demangle(typeid(*this).name());
|
|
std::string task_name;
|
|
// typeid.name() 结果可能和编译器有关,所以这里使用正则尽可能保证结果正确。
|
|
// 但还是不能完全保证,如果不行的话建议 override
|
|
std::regex regex("[a-zA-Z]+Task");
|
|
std::smatch match_obj;
|
|
if (std::regex_search(class_name, match_obj, regex)) {
|
|
task_name = match_obj[0].str();
|
|
}
|
|
else {
|
|
task_name = class_name;
|
|
}
|
|
|
|
m_basic_info_cache = json::object {
|
|
{ "taskchain", std::string(m_task_chain) },
|
|
{ "taskid", m_task_id },
|
|
{ "class", class_name },
|
|
{ "subtask", task_name },
|
|
{ "details", json::object() }
|
|
//{ "CurRetryTimes", m_cur_retry },
|
|
//{ "MaxRetryTimes", m_retry_times }
|
|
};
|
|
}
|
|
return m_basic_info_cache;
|
|
}
|
|
|
|
json::value asst::AbstractTask::basic_info_with_what(std::string what) const
|
|
{
|
|
json::value info = basic_info();
|
|
info["what"] = std::move(what);
|
|
return info;
|
|
}
|
|
|
|
void asst::AbstractTask::callback(AsstMsg msg, const json::value& detail)
|
|
{
|
|
for (const TaskPluginPtr& plugin : m_plugins) {
|
|
plugin->set_task_id(m_task_id);
|
|
plugin->set_task_ptr(this);
|
|
|
|
if (!plugin->verify(msg, detail)) {
|
|
continue;
|
|
}
|
|
|
|
plugin->run();
|
|
|
|
if (plugin->block()) {
|
|
break;
|
|
}
|
|
}
|
|
if (m_callback) {
|
|
// TODO 屎山: task 字段需要忽略 @ 和前面的字符,否则回调大改
|
|
if (std::string task = detail.get("details", "task", std::string()); !task.empty()) {
|
|
if (size_t pos = task.rfind('@'); pos != std::string::npos) {
|
|
json::value proced_detail = detail;
|
|
proced_detail["details"]["task"] = task.substr(pos + 1);
|
|
m_callback(msg, proced_detail, m_inst);
|
|
return;
|
|
}
|
|
}
|
|
m_callback(msg, detail, m_inst);
|
|
}
|
|
}
|
|
|
|
void asst::AbstractTask::click_return_button()
|
|
{
|
|
ProcessTask(*this, { "Return" }).run();
|
|
}
|
|
|
|
bool asst::AbstractTask::save_img(const std::filesystem::path& relative_dir)
|
|
{
|
|
auto image = ctrler()->get_image();
|
|
if (image.empty()) {
|
|
return false;
|
|
}
|
|
std::string stem = utils::get_time_filestem();
|
|
auto relative_path = relative_dir / (stem + "_raw.png");
|
|
Log.trace("Save image", relative_path);
|
|
return asst::imwrite(relative_path, image);
|
|
} |