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