Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, February 12, 2020 1:16:31 PM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

Was thanked: 3 time(s) in 3 post(s)

Sometimes certain documents could contain lighter color text or documents may be scanned in color. This may effect expected OCR results. You can find the light gray text DOCX file and the processed JPEG file in the ZIP file attached at the bottom of this post. The below C# console application code will showcase how to convert lighter text (in this case light gray) to black text using the LEADTOOLS v20 SDK.

Code:

using System;
using System.IO;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing.Core;

namespace ConvertLightGrayTextToBlack
{
   class Program
   {
      static void Main(string[] args)
      {
         SetLicense();
         ConvertLightGrayText();
      }
      private static void SetLicense()
      {
         string licenseFilePath = @"C:\LEADTOOLS 20\Support\Common\License\LEADTOOLS.lic";
         string developerKey = File.ReadAllText(@"C:\LEADTOOLS 20\Support\Common\License\LEADTOOLS.lic.key");
         RasterSupport.SetLicense(licenseFilePath, developerKey);
      }
      private static void ConvertLightGrayText()
      {
         string filePath = @"C:\Users\Public\Documents\LEADTOOLS Images\ConvertLightGrayTexttoBlackforOCR.docx";
         string destPath = @"C:\Users\Public\Documents\LEADTOOLS Images\ConvertLightGrayTexttoBlackforOCR.jpg";

         using (RasterCodecs codecs = new RasterCodecs())
         {
            RasterImage image = codecs.Load(filePath, 0, CodecsLoadByteOrder.Bgr, 1 ,-1);

            AutoBinarizeCommand command = new AutoBinarizeCommand();
            command.Flags = AutoBinarizeCommandFlags.UseUserThreshold;
            command.Factor = 250;
            command.Run(image);

            codecs.Save(image, destPath, RasterImageFormat.Jpeg, image.BitsPerPixel);
         }
      }
   }
}

Relevant LEADTOOLS v20 links:


File Attachment(s):
ConvertLightGrayTexttoBlackforOCR.zip (391kb) downloaded 35 time(s).
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.042 seconds.