修复文字变淡:白底阈值从120调到160,避免误伤文字

120太低把浅色文字也推白了。160在文字(0-80)和背景(150-200)
之间,只清理背景灰色不影响文字。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-20 08:39:21 +08:00
parent 82902e1a30
commit 0ddef2fc7c

View File

@@ -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();