修复灰底色:白底清理阈值从230降到120

gamma+线性拉伸后背景像素在140-200范围,之前阈值230根本
触发不到。降到120后,所有>120的像素被线性拉伸到255,
背景变纯白,文字(<120)不受影响。

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

View File

@@ -397,8 +397,12 @@ public static class DocumentScanner
contrasted.Dispose();
// --- f: 白底清理 ---
Cv2.Threshold(sharpened, sharpened, 230, 255, ThresholdTypes.Trunc);
Cv2.ConvertScaleAbs(sharpened, sharpened, 255.0 / 230.0, 0);
// gamma=2.2 + 输出范围200 后,背景像素大约在 140-200 范围
// 需要把这些灰色背景推到纯白
// 阈值 120高于120的像素线性拉伸到255背景变纯白
// 低于120的保持暗文字不受影响
Cv2.Threshold(sharpened, sharpened, 120, 255, ThresholdTypes.Trunc);
Cv2.ConvertScaleAbs(sharpened, sharpened, 255.0 / 120.0, 0);
// 转回3通道
Mat output = new Mat();