refactor: 合并ocrBinThreshold (#13635)

This commit is contained in:
Status102
2025-08-11 18:12:41 +08:00
committed by GitHub
parent 08dd08ff46
commit 24a92b4a01
11 changed files with 48 additions and 70 deletions

View File

@@ -154,11 +154,8 @@ Please note that JSON files do not support comments. The comments in this docume
"useRaw": true, // Optional, whether to use original image for matching
// Default true, false for grayscale matching
"binThresholdLower": 140, // Optional, lower threshold for grayscale binarization (default 140)
// Pixels with grayscale below this value considered background, excluded from text area
"binThresholdUpper": 255, // Optional, upper threshold for grayscale binarization (default 255)
// Pixels with grayscale above this value considered background, excluded from text area
"binThreshold": [140, 255], // Optional, threshold for grayscale binarization (default [140, 255])
// Pixels with grayscale out of range are considered background, excluded from text area
// Final text foreground includes pixels in [lower, upper] range
/* Fields below only valid when algorithm is JustReturn and action is Input */

View File

@@ -152,10 +152,7 @@ JSONファイルはコメントをサポートしていません。テキスト
"useRaw": true, // オプション、原画像でマッチングを行うかどうか
// 指定されていない場合、デフォルトは true、false の場合はグレースケールでマッチング
"binThresholdLower": 140, // オプション項目。グレースケールの二値化デフォルトは140
// この値より低い画素は背景とみなされ、文字領域から除外されます
"binThresholdUpper": 255, // オプション項目。グレースケールの二値化上限デフォルトは255
"binThreshold": [140, 255], // オプション項目。グレースケールの二値化限(デフォルトは[140, 255]
// この値より高い画素は背景とみなされ、文字領域から除外されます
// [lower, upper] 範囲内の画素のみが文字の前景として残ります

View File

@@ -153,10 +153,7 @@ icon: material-symbols:task
"useRaw": true, // 선택 사항, 원본 이미지를 사용하여 매칭할지 여부
// 기본값은 true이며, false이면 그레이스케일 매칭
"binThresholdLower": 140, // 선택 사항. 그레이스케일 이진화의 한 임계값 (기본값: 140)
// 이 값보다 낮은 픽셀은 배경으로 간주되어 문자 영역에서 제외됩니다
"binThresholdUpper": 255, // 선택 사항. 그레이스케일 이진화의 상한 임계값 (기본값: 255)
"binThreshold": [140, 255], // 선택 사항. 그레이스케일 이진화의 한 임계값 (기본값: [140, 255])
// 이 값보다 높은 픽셀은 배경으로 간주되어 문자 영역에서 제외됩니다
// 최종적으로 [lower, upper] 범위의 픽셀만 문자 전경으로 유지됩니다

View File

@@ -315,15 +315,15 @@
"default": true,
"description": "可选项,是否使用原图匹配\n不填写默认 truefalse 时为灰度匹配\n仅当 algorithm 为 OcrDetect 且 withoutDet 为 false 时生效。"
},
"binThresholdLower": {
"type": "integer",
"default": 140,
"description": "可选项,二值化灰度下阈值(默认 140\n灰度值小于该值的像素将被视为背景排除在文字区域之外\n仅当 algorithm 为 OcrDetect 且 withoutDet 为 false 时生效。"
},
"binThresholdUpper": {
"type": "integer",
"default": 255,
"description": "可选项,二值化灰度阈值(默认 255\n灰度值大于该值的像素将被视为背景,排除在文字区域之外\n最终保留 [lower, upper] 区间的像素作为文字前景\n仅当 algorithm 为 OcrDetect 且 withoutDet 为 false 时生效。"
"binThreshold": {
"type": "array",
"maxItems": 2,
"minItems": 2,
"items": {
"type": "integer"
},
"default": [140, 255],
"description": "可选项,二值化灰度阈值(默认 [140, 255]\n灰度值不处于范围内的像素将被视为背景,排除在文字区域之外\n仅当 algorithm 为 OcrDetect 且 withoutDet 为 false 时生效。"
}
},
"required": ["algorithm", "text"],

View File

@@ -315,15 +315,15 @@
"default": true,
"description": "Optional, whether to use the original image for matching.\nDefault is true. If false, grayscale image matching will be used.\nThis is only effective when algorithm is OcrDetect and withoutDet is false."
},
"binThresholdLower": {
"type": "integer",
"default": 140,
"description": "Optional, lower threshold for grayscale binarisation (default 140).\nPixels with a grayscale value lower than this will be considered background and excluded from the text region.\nThis is only effective when algorithm is OcrDetect and withoutDet is false."
},
"binThresholdUpper": {
"type": "integer",
"default": 255,
"description": "Optional, upper threshold for grayscale binarisation (default 255).\nPixels with a grayscale value higher than this will be considered background and excluded from the text region.\nOnly pixels within the [lower, upper] range will be kept as text foreground.\nThis is only effective when algorithm is OcrDetect and withoutDet is false."
"binThreshold": {
"type": "array",
"maxItems": 2,
"minItems": 2,
"items": {
"type": "integer"
},
"default": [140, 255],
"description": "Optional, threshold for grayscale binarisation (default [140, 255]).\nPixels with a grayscale value out of range will be considered background and excluded from the text region.\nThis is only effective when algorithm is OcrDetect and withoutDet is false."
}
},
"required": ["algorithm", "text"],

View File

@@ -153,11 +153,8 @@ icon: material-symbols:task
"useRaw": true, // 可选项,是否使用原图匹配
// 不填写默认 truefalse 时为灰度匹配
"binThresholdLower": 140, // 可选项,二值化灰度阈值(默认 140
// 灰度值小于该值的像素将被视为背景,排除在文字区域之外
"binThresholdUpper": 255, // 可选项,二值化灰度上阈值(默认 255
// 灰度值大于该值的像素将被视为背景,排除在文字区域之外
"binThreshold": [140, 255], // 可选项,二值化灰度阈值(默认 [140, 255]
// 灰度值不处于范围的像素将被视为背景,排除在文字区域之外
// 最终保留 [lower, upper] 区间的像素作为文字前景
/* algorithm JustReturnaction Input */

View File

@@ -151,11 +151,8 @@ icon: material-symbols:task
"useRaw": true, // 可選項,是否使用原圖匹配
// 不填寫預設 truefalse 時為灰階匹配
"binThresholdLower": 140, // 可選項,灰階二值化下限閾值(預設為 140
// 灰階值小於此值的像素會被視為背景,排除在文字區域之外
"binThresholdUpper": 255, // 可選項,灰階二值化上限閾值(預設為 255
// 灰階值大於此值的像素會被視為背景,排除在文字區域之外
"binThreshold": [140, 255], // 可選項,灰階二值化閾值(預設為 [140, 255]
// 灰階值不在範圍的像素會被視為背景,排除在文字區域之外
// 最終僅保留 [lower, upper] 區間的像素作為文字前景
/* algorithm JustReturn action Input */

View File

@@ -998,7 +998,7 @@
],
"roi": [627, 14, 71, 28],
"withoutDet": true,
"binThresholdLower": 200,
"binThreshold": [200, 255],
"useRaw": false
},
"JieGarden@Roguelike@StrategyChange_mode0": {
@@ -1014,7 +1014,7 @@
],
"roi": [627, 14, 71, 28],
"withoutDet": true,
"binThresholdLower": 200,
"binThreshold": [200, 255],
"useRaw": false
},
"JieGarden@Roguelike@StrategyChange_mode0_NOT_IN_USE": {
@@ -1031,7 +1031,7 @@
],
"roi": [627, 14, 71, 28],
"withoutDet": true,
"binThresholdLower": 210,
"binThreshold": [210, 255],
"useRaw": false
},
"JieGarden@Roguelike@StrategyChange_mode1": {
@@ -1047,7 +1047,7 @@
],
"roi": [627, 14, 71, 28],
"withoutDet": true,
"binThresholdLower": 200,
"binThreshold": [200, 255],
"useRaw": false
},
"JieGarden@Roguelike@StrategyChange_mode10001": {
@@ -1063,7 +1063,7 @@
],
"roi": [627, 14, 71, 28],
"withoutDet": true,
"binThresholdLower": 200,
"binThreshold": [200, 255],
"useRaw": false
},
"JieGarden@Roguelike@StrategyChange_mode4": {
@@ -1079,7 +1079,7 @@
],
"roi": [627, 14, 71, 28],
"withoutDet": true,
"binThresholdLower": 200,
"binThreshold": [200, 255],
"useRaw": false
},
"JieGarden@Roguelike@StrategyChange_mode6": {
@@ -1095,7 +1095,7 @@
],
"roi": [627, 14, 71, 28],
"withoutDet": true,
"binThresholdLower": 200,
"binThreshold": [200, 255],
"useRaw": false
},
"JieGarden@Roguelike@StrategyChange_mode7": {
@@ -1111,7 +1111,7 @@
],
"roi": [627, 14, 71, 28],
"withoutDet": true,
"binThresholdLower": 200,
"binThreshold": [200, 255],
"useRaw": false
},
"JieGarden@Roguelike@TodoEnter": {},

View File

@@ -598,16 +598,15 @@ struct OcrTaskInfo : public TaskInfo
constexpr OcrTaskInfo(OcrTaskInfo&&) noexcept = default;
constexpr OcrTaskInfo& operator=(const OcrTaskInfo&) = default;
constexpr OcrTaskInfo& operator=(OcrTaskInfo&&) noexcept = default;
std::vector<std::string> text; // 文字的容器,匹配到这里面任一个,就算匹配上了
bool full_match = false; // 是否需要全匹配,否则搜索到子串就算匹配上了
bool is_ascii = false; // 是否启用字符数字模型
bool without_det = false; // 是否不使用检测模型
bool replace_full = false; // 匹配之后是否将整个字符串replacefalse是只替换match的部分
bool use_raw = true; // 是否使用原始图片进行识别false则使用灰度图
std::vector<std::string> text; // 文字的容器,匹配到这里面任一个,就算匹配上了
bool full_match = false; // 是否需要全匹配,否则搜索到子串就算匹配上了
bool is_ascii = false; // 是否启用字符数字模型
bool without_det = false; // 是否不使用检测模型
bool replace_full = false; // 匹配之后是否将整个字符串replacefalse是只替换match的部分
bool use_raw = true; // 是否使用原始图片进行识别false则使用灰度图
std::vector<std::pair<std::string, std::string>>
replace_map; // 部分文字容易识别错字符串强制replace之后再进行匹配
int bin_threshold_lower = 140;
int bin_threshold_upper = 255;
replace_map; // 部分文字容易识别错字符串强制replace之后再进行匹配
std::array<int, 2> bin_threshold = { 140, 255 }; // 二值化灰度上阈值
};
using OcrTaskPtr = std::shared_ptr<OcrTaskInfo>;

View File

@@ -792,15 +792,9 @@ asst::TaskPtr asst::TaskData::generate_ocr_task_info(
utils::get_and_check_value_or(
name,
task_json,
"binThresholdLower",
ocr_task_info_ptr->bin_threshold_lower,
default_ptr->bin_threshold_lower);
utils::get_and_check_value_or(
name,
task_json,
"binThresholdUpper",
ocr_task_info_ptr->bin_threshold_upper,
default_ptr->bin_threshold_upper);
"binThreshold",
ocr_task_info_ptr->bin_threshold,
default_ptr->bin_threshold);
utils::get_and_check_value_or(name, task_json, "useRaw", ocr_task_info_ptr->use_raw, default_ptr->use_raw);
return ocr_task_info_ptr;
}
@@ -1072,7 +1066,7 @@ bool asst::TaskData::syntax_check(std::string_view task_name, const json::value&
// specific
"cache", "fullMatch", "isAscii", "ocrReplace", "rectMove",
"replaceFull", "roi", "text", "withoutDet", "useRaw",
"binThresholdLower", "binThresholdUpper",
"binThreshold",
} },
{ AlgorithmType::FeatureMatch,
{

View File

@@ -98,8 +98,8 @@ void OCRerConfig::_set_task_info(OcrTaskInfo task_info)
set_replace(task_info.replace_map, task_info.replace_full);
m_params.use_char_model = task_info.is_ascii;
m_params.without_det = task_info.without_det;
m_params.bin_threshold_lower = task_info.bin_threshold_lower;
m_params.bin_threshold_upper = task_info.bin_threshold_upper;
m_params.bin_threshold_lower = task_info.bin_threshold[0];
m_params.bin_threshold_upper = task_info.bin_threshold[1];
m_params.use_raw = task_info.use_raw;
_set_roi(task_info.roi);