修复文字变淡:白底阈值从120调到160,避免误伤文字
120太低把浅色文字也推白了。160在文字(0-80)和背景(150-200) 之间,只清理背景灰色不影响文字。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -397,12 +397,10 @@ public static class DocumentScanner
|
|||||||
contrasted.Dispose();
|
contrasted.Dispose();
|
||||||
|
|
||||||
// --- f: 白底清理 ---
|
// --- f: 白底清理 ---
|
||||||
// gamma=2.2 + 输出范围200 后,背景像素大约在 140-200 范围
|
// gamma后文字大约在 0-80,背景大约在 150-200
|
||||||
// 需要把这些灰色背景推到纯白
|
// 阈值 160:>160 的推白(背景),<160 的保留(文字)
|
||||||
// 阈值 120:高于120的像素线性拉伸到255(背景变纯白)
|
Cv2.Threshold(sharpened, sharpened, 160, 255, ThresholdTypes.Trunc);
|
||||||
// 低于120的保持暗(文字不受影响)
|
Cv2.ConvertScaleAbs(sharpened, sharpened, 255.0 / 160.0, 0);
|
||||||
Cv2.Threshold(sharpened, sharpened, 120, 255, ThresholdTypes.Trunc);
|
|
||||||
Cv2.ConvertScaleAbs(sharpened, sharpened, 255.0 / 120.0, 0);
|
|
||||||
|
|
||||||
// 转回3通道
|
// 转回3通道
|
||||||
Mat output = new Mat();
|
Mat output = new Mat();
|
||||||
|
|||||||
Reference in New Issue
Block a user