User Guide - .Net
Requirements
- Operating systems:
- Windows: 7, 8, 10, 2003, 2008, 2008 R2, 2012.
-
Environment: Visual Studio 2008 and above.
- Framework supported: .NET Framework 2.0, .NET Framework 4.0
Installation
If you don’t have SDK yet, please go to Dynamsoft website to get it. After the sdk is decompressed, the root directory of the DLR installation package is DynamsoftLabelRecognizer
, which is represented by [INSTALLATION FOLDER]
.
Build Your First Application
Let’s start by creating a console application which demonstrates how to use the minimum code to recognize text from an image file.
You can download the similar complete source code from Here.
Create a New Project
- Open Visual Studio. Go to File > New > Project, select
Visual C#
template, create a new Console Application (.NET Framework) namedDLRCSharpSample
.
Include the Label Recognizer library
- Add the Dynamsoft Label Recognizer libraries (
Dynamsoft.LabelRecognizer.dll
andDynamsoft.Core.dll
) to the project references. The lib files can be found in[INSTALLATION FOLDER]\Lib\[dotNetVersion]
.Note: Select the corresponding folder (2.0 or 4.0) based on your project’s .NET Framework version.
-
Import the namespace in the file
Program.cs
using Dynamsoft.DLR;
Initialize the Label Recognizer
-
Initialize the license key
// 1.Initialize license. LabelRecognizer.InitLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInByb2R1Y3RzIjoyfQ==");
Note:
- Network connection is required for the license to work.
- “DLS2***” is a default free public trial license used in the sample.
- You can request a 30-day trial license via the Request a Trial License link.
-
Create an instance of Dynamsoft Label Recognizer
// 2.Create an instance of Label Recognizer. LabelRecognizer dlr = new LabelRecognizer();
Recognition Process and How to Use the Results
-
Recognizing text in an image
DLR_Result[] results = null; try { // 3.Recognize text from an image file. results = dlr.RecognizeByFile("../../SampleImages/dlr-sample-vin.png", ""); } catch (LabelRecognizerException exp) { Console.WriteLine(exp); }
You can download the image dlr-sample-vin.png for testing. In addition, you can replace it with the full path of the image you want to recognize.
For the error handling mechanism, when an error occurs during the recognition process, an exception will be thrown. You should add codes for error handling based on your needs. Check out Error Code for full supported error codes.
-
Get and output the recognition results
if (results != null && results.Length > 0) { for (int i = 0; i < results.Length; ++i) { Console.WriteLine("Result " + i.ToString() + ":"); // Get result of each text area (also called label). DLR_Result result = results[i]; for (int j = 0; j < result.LineResults.Length; ++j) { // Get the result of each text line in the label. DLR_LineResult lineResult = result.LineResults[j]; Console.WriteLine(">>LineResult " + j.ToString() + ": " + lineResult.Text); } } } else { Console.WriteLine("No data detected.\n"); }
The recognition results of SDK are organized into a four-tier structure:
DLR_Result[]
corresponds to the results of animage
DLR_Result
corresponds to the result of aTextArea
(also called Label)DLR_LineResult
corresponds to the result of eachTextLine
in the LabelDLR_CharacterResult
corresponds to the result of eachCharacter
in theTextLine
The structure is shown in the figure below:
Figure 1 – DLR Result Structure
You can download the similar complete source code from Here.
Build and Run the Project
- Build the application through Visual Studio and copy the related folders to the same folder as the EXE file. The related folders includes
[INSTALLATION FOLDER]\Lib\[dotNetVersion]\x86
and[INSTALLATION FOLDER]\Lib\[dotNetVersion]\x64
.Note: Select the corresponding folder (2.0 or 4.0) based on your project’s .NET Framework version.
- Run the program
DLRCSharpSample.exe
.