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 : Friday, May 5, 2017 4:04:08 PM(UTC)

Roberto  
Roberto

Groups: Registered, Tech Support, Administrators
Posts: 39

Thanks: 2 times
Was thanked: 3 time(s) in 3 post(s)

There had been a request for a method similar to our IOcrZoneCharacters.GetWords method but to retrieve entire lines of text. Every character recognized by the OCR engine has a position. We can access this position through the position property of the OcrCharacter structure. This returns one or more OcrCharacterPosition enumerations members:

memebers

I wrote a quick little example that uses OcrCharacterPosition to write entire lines of recognized text at a time.

Code:
using (RasterCodecs codecs = new RasterCodecs())
{
   codecs.Options.RasterizeDocument.Load.XResolution = 300;
   codecs.Options.RasterizeDocument.Load.YResolution = 300;
   RasterImage image = codecs.Load(inputFile);
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(ENGINE_TYPE, false))
   {
      ocrEngine.Startup(codecs, null, null, ENGINE_RUNTIME_DIRECTORY);
      ocrEngine.SettingManager.SetBooleanValue("Recognition.SpaceIsValidCharacter", true);
      using (IOcrDocument document = ocrEngine.DocumentManager.CreateDocument())
      {
         document.Pages.AddPage(image, null);
         document.Pages[0].Recognize(null);
         IOcrPageCharacters pageCharacters = document.Pages[0].GetRecognizedCharacters();
         for (int i = 0; i < document.Pages[0].Zones.Count; i++)
         {
            IOcrZoneCharacters zoneCharacters = pageCharacters.FindZoneCharacters(i);
            if (zoneCharacters != null)
            {
               foreach (var ocrCharacter in zoneCharacters)
               {
                  OcrCharacterPosition position;
                  position = ocrCharacter.Position;
                  if ((position & OcrCharacterPosition.EndOfLine) == OcrCharacterPosition.EndOfLine)
                  {
                     Console.Write(ocrCharacter.Code + "\n");
                  }
                  else
                  {
                     Console.Write(ocrCharacter.Code);
                  }
               }
            }
         }
      }
   }
}

Update:
Here is a runable project updated to use either LEADTOOLS 19 or LEADTOOLS 20 binaries.
File Attachment(s):
CS_GetTextLine.zip (5kb) downloaded 98 time(s).

Edited by moderator Friday, May 4, 2018 7:04:30 AM(UTC)  | Reason: Updated to include project

Roberto Rodriguez
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 

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.