整理头文件,task消息等

This commit is contained in:
MistEO
2021-08-05 19:37:41 +08:00
parent 919bf0ab53
commit 345bcfec21
9 changed files with 36 additions and 51 deletions

View File

@@ -8,10 +8,7 @@
#include <unordered_map>
#include <queue>
#include "AsstPort.h"
#include "AsstDef.h"
#include "Configer.h"
#include "OpenRecruitConfiger.h"
#include "Task.h"
namespace cv {
@@ -21,8 +18,6 @@ namespace cv {
namespace asst {
class WinMacro;
class Identify;
class AbstractTask;
enum class TaskMsg;
class Assistance
{

View File

@@ -36,42 +36,13 @@ namespace asst {
PrintWindow = 0x800, // 截图功能
OpenRecruit = 0x1000 // 公开招募功能
};
//static MatchTaskType operator&(const MatchTaskType& lhs, const MatchTaskType& rhs)
//{
// return static_cast<MatchTaskType>(
// static_cast<std::underlying_type<MatchTaskType>::type>(lhs)
// & static_cast<std::underlying_type<MatchTaskType>::type>(rhs));
//}
static std::ostream& operator<<(std::ostream& os, const MatchTaskType& task)
{
static std::unordered_map<MatchTaskType, std::string> _type_name = {
{MatchTaskType::Invalid, "Invalid"},
{MatchTaskType::BasicClick, "BasicClick"},
{MatchTaskType::ClickSelf, "ClickSelf"},
{MatchTaskType::ClickRect, "ClickRect"},
{MatchTaskType::ClickRand, "ClickRand"},
{MatchTaskType::DoNothing, "DoNothing"},
{MatchTaskType::Stop, "Stop"},
{MatchTaskType::PrintWindow, "PrintWindow"},
{MatchTaskType::OpenRecruit, "OpenRecruit"}
};
return os << _type_name.at(task);
}
enum class AlgorithmType {
JustReturn,
MatchTemplate,
CompareHist
CompareHist,
OcrDetect
};
static std::ostream& operator<<(std::ostream& os, const AlgorithmType& type)
{
static std::unordered_map<AlgorithmType, std::string> _type_name = {
{AlgorithmType::JustReturn, "JustReturn"},
{AlgorithmType::MatchTemplate, "MatchTemplate"},
{AlgorithmType::CompareHist, "CompareHist"}
};
return os << _type_name.at(type);
}
struct Point
{

View File

@@ -6,7 +6,6 @@
#include <optional>
#include <functional>
#include <unordered_map>
#include <ostream>
#include "AsstDef.h"
#include "AsstAux.h"
@@ -40,6 +39,7 @@ namespace asst {
ImageIsEmpty,
WindowMinimized,
/* Info Msg */
ImageMatched,
TaskMatched,
ReachedLimit,
ReadyToSleep,
@@ -62,6 +62,7 @@ namespace asst {
{TaskMsg::PtrIsNull, "PtrIsNull"},
{TaskMsg::ImageIsEmpty, "ImageIsEmpty"},
{TaskMsg::WindowMinimized, "WindowMinimized"},
{TaskMsg::ImageMatched, "ImageMatched"},
{TaskMsg::TaskMatched, "TaskMatched"},
{TaskMsg::ReachedLimit, "ReachedLimit"},
{TaskMsg::ReadyToSleep, "ReadyToSleep"},

View File

@@ -6,8 +6,9 @@
#include "Logger.hpp"
#include "AsstAux.h"
#include "Task.h"
#include "json.h"
#include "OpenRecruitConfiger.h"
#include <json.h>
#include <opencv2/opencv.hpp>
#include <time.h>

View File

@@ -2,8 +2,8 @@
#include "Updater.h"
#include "AsstAux.h"
#include "Assistance.h"
#include "json_value.h"
#include <json_value.h>
#include <string.h>
#if 0

View File

@@ -4,7 +4,7 @@
#include <sstream>
#include <algorithm>
#include "json.h"
#include <json.h>
#include "Logger.hpp"
using namespace asst;

View File

@@ -4,7 +4,7 @@
#include <sstream>
#include <algorithm>
#include "json.h"
#include <json.h>
#include "Logger.hpp"
using namespace asst;

View File

@@ -4,7 +4,7 @@
#include "Identify.h"
#include "Configer.h"
#include "OpenRecruitConfiger.h"
#include "json.h"
#include <json.h>
#include "AsstAux.h"
#include <chrono>
@@ -236,15 +236,32 @@ std::optional<std::string> MatchTask::match_image(Rect* matched_rect)
auto&& [algorithm, value, rect] = m_identify_ptr->find_image(cur_image, task_name, templ_threshold);
if (algorithm == AlgorithmType::JustReturn
|| (algorithm == AlgorithmType::MatchTemplate && value >= templ_threshold)
|| (algorithm == AlgorithmType::CompareHist && value >= hist_threshold)) {
if (matched_rect != NULL) {
*matched_rect = std::move(rect);
}
return task_name;
json::value callback_json;
if (algorithm == AlgorithmType::JustReturn) {
callback_json["threshold"] = 0.0;
callback_json["algorithm"] = "JustReturn";
}
else if (algorithm == AlgorithmType::MatchTemplate && value >= templ_threshold) {
callback_json["threshold"] = templ_threshold;
callback_json["algorithm"] = "MatchTemplate";
}
else if (algorithm == AlgorithmType::CompareHist && value >= hist_threshold) {
callback_json["threshold"] = hist_threshold;
callback_json["algorithm"] = "CompareHist";
}
else {
continue;
}
if (matched_rect != NULL) {
callback_json["rect"] = json::array({rect.x, rect.y, rect.width, rect.height});
*matched_rect = std::move(rect);
}
callback_json["algorithm_id"] = static_cast<std::underlying_type<MatchTaskType>::type>(algorithm);
callback_json["value"] = value;
m_callback(TaskMsg::ImageMatched, callback_json, m_callback_arg);
return task_name;
}
return std::nullopt;
}

View File

@@ -4,7 +4,7 @@
#include <Windows.h>
#include <WinInet.h>
#include "json.h"
#include <json.h>
#include "AsstDef.h"
#include "Logger.hpp"
#include "Version.h"