diff --git a/resource/config.json b/resource/config.json index 2d260abdd8..059aed8ad7 100644 --- a/resource/config.json +++ b/resource/config.json @@ -284,6 +284,12 @@ "action": "clickSelf", "cache": false, "rearDelay": 3000, + "identifyArea": [ + 1080, + 570, + 195, + 130 + ], "exceededNext": [ "ReturnToMall" ], @@ -298,7 +304,13 @@ "algorithm": "OcrDetect", "text": [ "访问下位" ], "action": "clickSelf", - "rearDelay": 3000, + "rearDelay": 3000, + "identifyArea": [ + 1080, + 570, + 195, + 130 + ], "exceededNext": [ "ReturnToMall" ], @@ -366,6 +378,12 @@ "algorithm": "OcrDetect", "text": [ "今日参与", "已达上限" ], "action": "doNothing", + "identifyArea": [ + 900, + 50, + 375, + 140 + ], "next": [ "ReturnToMall" ] @@ -373,6 +391,12 @@ "VisitNextBlack": { "template": "VisitNextBlack.png", "action": "doNothing", + "identifyArea": [ + 1080, + 570, + 195, + 130 + ], "next": [ "ReturnToMall" ] @@ -557,6 +581,12 @@ "text": [ "可收获", "订单交付", "信赖" ], "rearDelay": 1000, "action": "clickSelf", + "identifyArea": [ + 0, + 600, + 800, + 118 + ], "next": [ "InfrastReward", "InfrastExitReward" diff --git a/resource/operators/Elite1.png b/resource/operators/Elite1.png deleted file mode 100644 index 5a9012c1ea..0000000000 Binary files a/resource/operators/Elite1.png and /dev/null differ diff --git a/resource/operators/Elite2.png b/resource/operators/Elite2.png deleted file mode 100644 index 5a05862ea2..0000000000 Binary files a/resource/operators/Elite2.png and /dev/null differ diff --git a/src/MeoAssistance/AsstAux.h b/src/MeoAssistance/AsstAux.h index 1987402b86..3b7c792752 100644 --- a/src/MeoAssistance/AsstAux.h +++ b/src/MeoAssistance/AsstAux.h @@ -79,6 +79,12 @@ namespace asst { return strTemp; } + template + constexpr inline RetTy make_rect(const ArgType& rect) + { + return RetTy{ rect.x, rect.y, rect.width, rect.height }; + } + //template::value>::type> // std::string VectorToString(const std::vector& vector, bool to_gbk = false) { diff --git a/src/MeoAssistance/AsstDef.h b/src/MeoAssistance/AsstDef.h index f5eb4ce2aa..afb96c5fa0 100644 --- a/src/MeoAssistance/AsstDef.h +++ b/src/MeoAssistance/AsstDef.h @@ -134,6 +134,7 @@ namespace asst { int pre_delay = 0; // 执行该任务前的延时 int rear_delay = 0; // 执行该任务后的延时 int retry_times = INT_MAX; // 未找到图像时的重试次数 + Rect identify_area; // 要识别的区域,若为0则全图识别 }; // 文字识别任务的信息 diff --git a/src/MeoAssistance/Configer.cpp b/src/MeoAssistance/Configer.cpp index 673ab60e12..9796032d84 100644 --- a/src/MeoAssistance/Configer.cpp +++ b/src/MeoAssistance/Configer.cpp @@ -182,6 +182,14 @@ bool asst::Configer::parse(json::value&& json) task_info_ptr->reduce_other_times.emplace_back(reduce.as_string()); } } + if (task_json.exist("identifyArea")) { + json::array& area_arr = task_json["identifyArea"].as_array(); + task_info_ptr->identify_area = Rect( + area_arr[0].as_integer(), + area_arr[1].as_integer(), + area_arr[2].as_integer(), + area_arr[3].as_integer()); + } json::array& next_arr = task_json["next"].as_array(); for (const json::value& next : next_arr) { diff --git a/src/MeoAssistance/Identify.cpp b/src/MeoAssistance/Identify.cpp index 3e206c7d9b..961d0c7a39 100644 --- a/src/MeoAssistance/Identify.cpp +++ b/src/MeoAssistance/Identify.cpp @@ -17,22 +17,22 @@ using namespace cv::xfeatures2d; bool Identify::add_image(const std::string& name, const std::string& path) { - Mat mat = imread(path); - if (mat.empty()) { + Mat image = imread(path); + if (image.empty()) { return false; } - m_mat_map.emplace(name, mat); + m_mat_map.emplace(name, image); return true; } bool asst::Identify::add_text_image(const std::string& text, const std::string& path) { - Mat mat = imread(path); - if (mat.empty()) { + Mat image = imread(path); + if (image.empty()) { return false; } - m_feature_map.emplace(text, surf_detect(mat)); + m_feature_map.emplace(text, surf_detect(image)); return true; } @@ -73,21 +73,11 @@ double Identify::image_hist_comp(const cv::Mat& src, const cv::MatND& hist) return 1 - compareHist(image_2_hist(src), hist, CV_COMP_BHATTACHARYYA); } -asst::Rect asst::Identify::cvrect_2_rect(const cv::Rect& cvRect) -{ - return asst::Rect(cvRect.x, cvRect.y, cvRect.width, cvRect.height); -} - -cv::Rect asst::Identify::rect_2_cvrect(const asst::Rect& rect) -{ - return cv::Rect(rect.x, rect.y, rect.width, rect.height); -} - -std::pair, cv::Mat> asst::Identify::surf_detect(const cv::Mat& mat) +std::pair, cv::Mat> asst::Identify::surf_detect(const cv::Mat& image) { // 灰度图转换 cv::Mat mat_gray; - cv::cvtColor(mat, mat_gray, cv::COLOR_RGB2GRAY); + cv::cvtColor(image, mat_gray, cv::COLOR_RGB2GRAY); constexpr int min_hessian = 400; // SURF特征点检测 @@ -243,9 +233,9 @@ std::optional asst::Identify::feature_match( return std::nullopt; } -std::vector