Recognize Handwritten Text From Images With ICR - Windows C DLL

This tutorial shows how to set up OCR processing and ICR to convert images with handwritten text to searchable PDF in a Windows C DLL application using the LEADTOOLS SDK.

Summary This tutorial covers how to recognize handwritten text from images in a Windows C DLL Application.
Completion Time 30 minutes
Visual Studio Project Download tutorial project (19 KB)
Platform Windows C DLL Application
IDE Visual Studio 2017, 2019
Development License Download LEADTOOLS
Try it in another language

Required Knowledge

Get familiar with the basic steps of creating a project and working with LEADTOOLS OCR technologies by reviewing the Add References and Set a License and Convert Images to Searchable PDF with OCR tutorials, before working on the Recognize Handwritten Text From Images With ICR - Windows C DLL tutorial.



Abbreviation for Optical Character Recognition; alternatively, defined as Optical Character Reader. For further details on LEADTOOLS support for this technology, refer to OCR.


Abbreviation for Intelligent Character Recognition. ICR is advanced OCR used to recognize handwritten text (e.g., handwritten text recognition in color and bitonal images).

Create the Project and Add LEADTOOLS References

Start with a copy of the project created in the Convert Images to Searchable PDF with OCR tutorial. If the project is not available, create it by following the steps in that tutorial.

To utilize LEADTOOLS OCR functionality, add the required header and library files. Open the pre-compiled header file (either pch.h or stdafx.h, depending on the version of Visual Studio used) and ensure the below lines are added.

#include "c:\LEADTOOLS21\Include\ltocr.h" 
#pragma comment (lib, "C:\\LEADTOOLS21\\Lib\\CDLL\\x64\\Ltocr_x.lib") // OCR support 


For a complete list of DLLs that are required for specific application features, refer to Files to be Included with your Application - C API.

Set the License File

The License unlocks the features needed for the project. It must be set before any toolkit functionality is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.

There are two types of runtime licenses:


Adding LEADTOOLS references and setting a license are covered in more detail in the Add References and Set a License tutorial.

Add the ICR Code

With the project created, the references added, the license set, and the load image code added, coding can begin.

The project already implements OCR but needs to be modified to support ICR . The main modification is to specify the type for OCR zones as ICR before recognizing the text.

In the Solution Explorer, open the project's CPP file. Navigate to the OcrAndSaveResult function and add the following line of code before the L_OcrPage_Recognize function call.

SetIcrZone(ocrPage); // Add this line 
nRet = L_OcrPage_Recognize(ocrPage, NULL, NULL); 

Create a new function named SetIcrZone(L_OcrPage handwrittenPage), which can be placed above the OcrAndSaveResult function. Add the code below to set the L_OcrZoneType to ICR .

void SetIcrZone(L_OcrPage handwrittenPage) 
   L_OcrZone ocrZone = { 0 }; 
   ocrZone.StructSize = sizeof ocrZone; 
   ocrZone.Bounds = r; 
   ocrZone.ZoneType = L_OcrZoneType_Icr; 
   ocrZone.BackColor = RGB(255, 255, 255); 
   L_OcrPage_InsertZone(handwrittenPage, 0, &ocrZone); 


If the page already has zones, the following code can be used to change their type to ICR

// Optionally use this function instead of SetIcrZone() if page already has zones 
void ModifyExistingZonesToIcr(L_OcrPage handwrittenPage) 
   L_UINT uZones = 0; 
   L_OcrPage_GetZoneCount(handwrittenPage, &uZones); 
   for (int nZone = 0; nZone < uZones; nZone++) 
      L_OcrZone ocrZone = { 0 }; 
      ocrZone.StructSize = sizeof ocrZone; 
      L_OcrPage_GetZoneAt(handwrittenPage, nZone, &ocrZone); 
      ocrZone.ZoneType = L_OcrZoneType_Icr; 
      L_OcrPage_SetZoneAt(handwrittenPage, nZone, &ocrZone); 

Run the Project

Run the project by pressing F5, or by selecting Debug -> Start Debugging.

If the steps were followed correctly, the application should run and enable the user to select File > Open to load the file on which ICR recognition will be performed.

To test the project, this scanned image can be used. Select Ocr > Recognize and Export Results to have the application run ICR on the input file and output to a searchable PDF file here: C:\Temp\output.pdf

Here is the output from the original scanned document: Output PDF


This tutorial covered how to recognize hand written text by setting the L_OcrZoneType to ICR .

See Also

Help Version 21.0.2021.6.17
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.