mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
fix: 血量识别
This commit is contained in:
@@ -801,7 +801,7 @@
|
||||
"baseTask": "NumberOcrReplace",
|
||||
"Doc": "生命值识别,暂时是把整个框进去,估计会把后面的生命值也识别到,后面得改改",
|
||||
"text": [],
|
||||
"roi": [175, 30, 60, 30]
|
||||
"roi": [170, 30, 70, 30]
|
||||
},
|
||||
"Roguelike@InBattleFlag": {
|
||||
"template": "BattleOfficiallyBegin.png",
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#include "Task/ProcessTask.h"
|
||||
#include "Utils/Logger.hpp"
|
||||
#include "Vision/Matcher.h"
|
||||
#include "Vision/RegionOCRer.h"
|
||||
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
bool asst::RoguelikeStageEncounterTaskPlugin::verify(AsstMsg msg, const json::value& details) const
|
||||
{
|
||||
@@ -263,13 +266,30 @@ int asst::RoguelikeStageEncounterTaskPlugin::hp(const cv::Mat& image)
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
int hp_val;
|
||||
asst::OCRer analyzer(image);
|
||||
analyzer.set_task_info("Roguelike@HpRecognition");
|
||||
auto task = Task.get<OcrTaskInfo>("Roguelike@HpRecognition");
|
||||
std::vector<std::pair<std::string, std::string>> merged_map;
|
||||
merged_map.insert(merged_map.end(), task->replace_map.begin(), task->replace_map.end());
|
||||
merged_map.emplace_back("(.*)/.*", "$1");
|
||||
|
||||
auto roi_image = make_roi(image, task->roi).clone();
|
||||
cv::Mat r_channel;
|
||||
cv::extractChannel(roi_image, r_channel, 2);
|
||||
cv::Mat mask;
|
||||
cv::threshold(r_channel, mask, 50, 255, cv::THRESH_BINARY);
|
||||
cv::Mat inv_mask;
|
||||
cv::bitwise_not(mask, inv_mask);
|
||||
roi_image.setTo(cv::Scalar(0, 0, 0), mask);
|
||||
|
||||
RegionOCRer analyzer(roi_image);
|
||||
analyzer.set_replace(merged_map);
|
||||
analyzer.set_use_char_model(true);
|
||||
analyzer.set_bin_threshold(60); // 血量没有红色通道,虽然它看着很明显,但实际上在灰度中只有 2/3
|
||||
|
||||
auto res_vec_opt = analyzer.analyze();
|
||||
if (!res_vec_opt) {
|
||||
return -1;
|
||||
}
|
||||
return utils::chars_to_number(res_vec_opt->front().text, hp_val) ? hp_val : 0;
|
||||
|
||||
int hp_val;
|
||||
return utils::chars_to_number(res_vec_opt->text, hp_val) ? hp_val : 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user