From 0ddef2fc7c62b6e112906ec03034a47ee92dfd26 Mon Sep 17 00:00:00 2001 From: sinvo Date: Fri, 20 Mar 2026 08:39:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E5=AD=97=E5=8F=98?= =?UTF-8?q?=E6=B7=A1=EF=BC=9A=E7=99=BD=E5=BA=95=E9=98=88=E5=80=BC=E4=BB=8E?= =?UTF-8?q?120=E8=B0=83=E5=88=B0160=EF=BC=8C=E9=81=BF=E5=85=8D=E8=AF=AF?= =?UTF-8?q?=E4=BC=A4=E6=96=87=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 120太低把浅色文字也推白了。160在文字(0-80)和背景(150-200) 之间,只清理背景灰色不影响文字。 Co-Authored-By: Claude Opus 4.6 --- CamScanner.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CamScanner.cs b/CamScanner.cs index ce2b2bf..47202b9 100644 --- a/CamScanner.cs +++ b/CamScanner.cs @@ -397,12 +397,10 @@ public static class DocumentScanner contrasted.Dispose(); // --- f: 白底清理 --- - // 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); + // gamma后文字大约在 0-80,背景大约在 150-200 + // 阈值 160:>160 的推白(背景),<160 的保留(文字) + Cv2.Threshold(sharpened, sharpened, 160, 255, ThresholdTypes.Trunc); + Cv2.ConvertScaleAbs(sharpened, sharpened, 255.0 / 160.0, 0); // 转回3通道 Mat output = new Mat();