I'm currently working with an OCR program. I'm using tesseract and i need to deskew images to improve the quality of the detected characters. The problem is that the deskew property given by tesseract doesn't produce enough attractive results. So i tried to deskew the image with AForge and Atalasoft, but every time, no matter what, the image is not in the format they require. What am i doing wrong? Or there is a better solution?
This is AForge implementation
System.Drawing.Bitmap imageToBitmap = AForge.Imaging.Image.FromFile(imagePath);
Console.WriteLine("before " + imageToBitmap.PixelFormat);
System.Drawing.Bitmap NewPicture = imageToBitmap.Clone(new System.Drawing.Rectangle(0, 0, imageToBitmap.Width, imageToBitmap.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
var dop = AForge.Imaging.Image.Clone(imageToBitmap, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Console.WriteLine("after " + dop.PixelFormat);
AForge.Imaging.DocumentSkewChecker skewChecker = new AForge.Imaging.DocumentSkewChecker();
// get documents skew angle
double angle = skewChecker.GetSkewAngle(dop);
// create rotation filter
AForge.Imaging.Filters.RotateBilinear rotationFilter = new AForge.Imaging.Filters.RotateBilinear(-angle);
rotationFilter.FillColor = System.Drawing.Color.White;
// rotate image applying the filter
System.Drawing.Bitmap rotatedImage = rotationFilter.Apply(imageToBitmap);
rotatedImage.Save("deskewedImage");
This is Atalasoft implementation
AtalaImage img = new AtalaImage(imagePath);
AutoDeskewCommand cmd = new AutoDeskewCommand();
AtalaImage resultImage = cmd.Apply(img).Image;
resultImage.Save("result.tif", new TiffEncoder(), null);