This tutorial shows how to configure the LEAD OCR Engine to use the Mixed Zone Recognition module in a C# WinForms application.
Overview | |
---|---|
Summary | This tutorial covers how to use LEADTOOLS OCR SDK technology in a C# WinForms application |
Completion Time | 30 minutes |
Visual Studio Project | Download tutorial project (4 KB) |
Platform | C# Windows WinForms Application |
IDE | Visual Studio 2022 |
Development License | Download LEADTOOLS |
Try it in another language |
|
Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License and the Convert Images to Searchable PDF with OCR tutorials, before working on the Mixed Zone Recognition with LEADEngine - WinForms C# tutorial.
Start with a copy of the project created in the Convert Images to Searchable PDF with OCR tutorial. If the project is not available, follow the steps in that tutorial to create it.
Note
Be sure to configure your
Platform
to x64, asGetEnumValue("Recognition.RecognitionModuleType")
is only supported in 64-bit applications.
Needed references for this project can be added by one or the other of the following two methods (but not both). For this project, the following references are needed:
NuGet references requires the following NuGet packages and their dependencies:
Leadtools.Ocr
Leadtools.Viewer.Controls.WinForms
If local DLL references are used, the following DLLs are located at <INSTALL_DIR>\LEADTOOLS22\Bin\net
Leadtools.dll
Leadtools.Codecs.dll
Leadtools.Codecs.Cmp.dll
Leadtools.Codecs.Tif.dll
Leadtools.Codecs.Fax.dll
Leadtools.Controls.WinForms.dll
Leadtools.Document.Writer.dll
Leadtools.Ocr.dll
Leadtools.Ocr.LEADEngine.dll
For a complete list of which DLL files are required for your application, refer to Files to be Included in your Application.
The License unlocks needed features, and must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.
There are two types of runtime licenses:
Note
Adding LEADTOOLS NuGet and local references and setting a license are covered in more detail in the Add References and Set a License tutorial.
With the project created, references added, license set, and code from the Convert Images to Searchable PDF with OCR tutorial added, coding can begin.
In the Solution Explorer, open Form1.cs
. Add a new drop-down menu titled &OCR Engine. Add a new menu item to the drop-down menu titled Recognition &Module. Then, add three items to the Recognition Module item, titled &OCR, &ICR, and &Mixed, respectively.
In the designer right-click
and select View Code
or press F7, to bring up the code behind the form.
Add the following global variable:
private IOcrSettingManager _ocrSettingsManager;
Add the following code inside the Form1_Load
event handler, after _ocrEngine.Startup()
is called, to initialize the IOcrSettingManager
and update the menu items.
_ocrSettingsManager = _ocrEngine.SettingManager;
switch (_ocrSettingsManager.GetEnumValue("Recognition.RecognitionModuleType"))
{
case 0: //OCR
oCRToolStripMenuItem.Checked = true;
break;
case 1: //ICR
iCRToolStripMenuItem.Checked = true;
break;
case 2: //Mixed
mixedToolStripMenuItem.Checked = true;
break;
default:
oCRToolStripMenuItem.Checked = true;
break;
}
Create a click event handler called RecognitionModeMenuClick
and add the code below:
private void RecognitionModeMenuClick(Object sender, EventArgs e)
{
// Uncheck all menu options
foreach (ToolStripMenuItem item in recognitionModuleToolStripMenuItem.DropDownItems)
{
item.Checked = false;
}
if (sender == oCRToolStripMenuItem)
{
oCRToolStripMenuItem.Checked = true;
_ocrSettingsManager.SetEnumValue("Recognition.RecognitionModuleType", "OCR");
}
if (sender == iCRToolStripMenuItem)
{
iCRToolStripMenuItem.Checked = true;
_ocrSettingsManager.SetEnumValue("Recognition.RecognitionModuleType", "ICR");
}
if (sender == mixedToolStripMenuItem)
{
mixedToolStripMenuItem.Checked = true;
_ocrSettingsManager.SetEnumValue("Recognition.RecognitionModuleType", "Mixed");
}
// If already created, recreate IOcrPage from loaded image using new OCR engine settings
if (_ocrPage != null)
_ocrPage = _ocrEngine.CreatePage(_viewer.Image, OcrImageSharingMode.AutoDispose);
}
Hook the click event of all three of the Recognition Module menu items to the RecognitionModeMenuClick
handler.
Run the project by pressing F5, or by selecting Debug -> Start Debugging.
If the steps were followed correctly, the application will be able to set the recognition module used by the LEAD OCR engine. This allows using the Mixed Zone Recognition module for the automatic recognition of handwritten and typed text in an image during OCR.
To illustrate this, use this Mixed Zone Recognition Sample image in the application.
This tutorial shows how to use the IOcrSettingManager
interface to configure the LEAD OCR Engine to use the Mixed Zone Recognition Module.