文档半岛外围网上直营>>LEADTOOLS使用教程>>LEADTOOLS使用教程:图像清理
LEADTOOLS使用教程:图像清理
LEADTOOLS Document Imaging Developer Toolkit的其中一个基本功能就是图像清理(也称为预处理)。当纸文档扫描成数字形式时,总有不完善之处。扫描文件中可能包含一个角、打孔机留下的黑点,折叠后的线条以及灰尘等斑点,对OCR、条形码和压缩算法等不利。
大部分文档影像库都要求文档图像必须是黑色和白色。然而LEADTOOLS打破了该限制。LEADTOOLS的文档清理函数会返回它所执行的动作的相关信息。例如,你可以获取纠偏角度、矩形裁剪、填补区域,并且你可以在彩色图像中使用这些操作。
// First make a copy of the image
using (RasterImage image = viewer.Image.Clone())
{
// If the image is not 1bpp black and white, convert it
if (image.BitsPerPixel != 1)
{
AutoBinarizeCommand autoBin = new AutoBinarizeCommand();
autoBin.Flags = AutoBinarizeCommandFlags.DontUsePreProcessing;
autoBin.Run(image);
ColorResolutionCommand colorRes = new ColorResolutionCommand();
colorRes.BitsPerPixel = 1;
colorRes.Run(image);
}
// Process the 1bpp copy
DeskewCommand deskewCom = new DeskewCommand();
deskewCom.Flags = DeskewCommandFlags.ReturnAngleOnly;
deskewCom.Run(image);
// Apply the same transformation on the original color image using
// the data from the 1bpp cleanup function
RotateCommand rotateCom = new RotateCommand();
rotateCom.Flags = RotateCommandFlags.Resample;
rotateCom.FillColor = viewer.Image.GetPixelColor(0, 0);
rotateCom.Angle = deskewCom.Angle;
rotateCom.Run(viewer.Image);
}

QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线