LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Get each line of text from OCR recognition
#1
Posted
:
Friday, May 5, 2017 4:04:08 PM(UTC)
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:
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.
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.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Get each line of text from OCR recognition
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.