Skip to content

Commit

Permalink
feat: pipeline OCR 新增 threshold 字段
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Mar 5, 2025
1 parent 943139a commit 307b51d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/en_us/3.1-PipelineProtocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ This algorithm property requires additional fields:
- `expected`: *string* | *list<string, >*
The expected results, supports regular expressions. Required.

- `threshold`: *double*
Model confidence threshold. Optional, default is 0.3.

- `replace`: *array<string, 2>* | *list<array<string, 2>>*
Some text recognition results may not be accurate, so replacements are performed. Optional.

Expand Down
3 changes: 3 additions & 0 deletions docs/zh_cn/3.1-任务流水线协议.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ Orange 的 next 中,
- `expected`: *string* | *list<string, >*
期望的结果,支持正则。必选。
- `threshold`: *double*
模型置信度阈值。可选,默认 0.3 。
- `replace`: *array<string, 2>* | *list<array<string, 2>>*
部分文字识别结果不准确,进行替换。可选。
Expand Down
5 changes: 5 additions & 0 deletions source/MaaFramework/Resource/PipelineResMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,11 @@ bool PipelineResMgr::parse_ocrer_param(
}
std::ranges::transform(u8_text, std::back_inserter(output.expected), to_u16);

if (!get_and_check_value(input, "threshold", output.threshold, default_value.threshold)) {
LogError << "failed to get_and_check_value threshold" << VAR(input);
return false;
}

if (auto replace_opt = input.find("replace")) {
auto append_repalce = [&](const json::value& in) {
auto pair = in.as<std::array<std::string, 2>>();
Expand Down
4 changes: 4 additions & 0 deletions source/MaaFramework/Vision/OCRer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ void OCRer::add_results(ResultsVec results, const std::vector<std::wstring>& exp
{
auto copied = results;
for (auto& res : copied) {
if (res.score < param_.threshold) {
continue;
}

postproc_trim_(res);
postproc_replace_(res);

Expand Down
3 changes: 3 additions & 0 deletions source/MaaFramework/Vision/VisionTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ struct TemplateMatcherParam

struct OCRerParam
{
inline static constexpr double kDefaultThreshold = 0.3;

std::string model;
bool only_rec = false;
Target roi_target;
std::vector<std::wstring> expected;
double threshold = kDefaultThreshold;
std::vector<std::pair<std::wstring, std::wstring>> replace;

ResultOrderBy order_by = ResultOrderBy::Horizontal;
Expand Down

0 comments on commit 307b51d

Please sign in to comment.