Documentation
Table of contents

Thanks for downloading Dynamsoft Label Recognizer Package!

Your download will start shortly. If your download does not begin, click here to retry.

User Guide - Java

Requirements

  • Operating systems:
    • Windows 7, 8, 10
    • Windows Server 2003, 2008, 2008 R2, 2012
    • Linux x64 (Ubuntu 14.04.4+ LTS, Debian 8+, etc.)
    • JDK 1.7 and above
  • Environment: Eclipse 3.7 and above.

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

  1. Open Eclipse. Go to File > New > Project, create a new Java project DLRJavaSample.

  2. Add a new Class named DLRJavaSample into the project.

Include the Label Recognizer library

  1. Add the Dynamsoft Label Recognizer JAR file to your project. Click File > Properties > Java Build Path > Libraries > Add external JARs, add dynamsoft-labelrecognizer-{version number}.jar and dynamsoft-core-{version number}.jar click Apply.

    Note: The JAR file can be found at [INSTALLATION FOLDER]\lib.

  2. Import the package in the file DLRJavaSample.java
     import com.dynamsoft.dlr.*;
    

Initialize the Label Recognizer

  1. 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.
    • If the license has expired, please request a trial license through the customer portal.
  2. 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

  1. Recognizing text in an image

     DLRResult[] results = null;
    
     try {
         results = dlr.recognizeByFile("../../SampleImages/dlr-sample-vin.png", "");
     } catch (LabelRecognizerException ex) {
         ex.printStackTrace();
     }
    

    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.

  2. Get and output the recognition results

     if (results != null && results.length > 0) {
         for (int i = 0; i < results.length; i++) {
                
             // Get result of each text area (also called label).
             DLRResult result = results[i];
             System.out.println("Result " + i + ":");
             for (int j = 0; j < result.lineResults.length; j++) {
                    
                 // Get the result of each text line in the label.
                 DLRLineResult lineResult = result.lineResults[j];
                 System.out.println(">>Line Result " + j + ": " + lineResult.text);
             }
         }
     } else {
         System.out.println("No data detected.");
     }
    

    The recognition results of SDK are organized into a four-tier structure:

    • DLRResult[] corresponds to the results of an image
    • DLRResult corresponds to the result of a TextArea (also called Label)
    • DLRLineResult corresponds to the result of each TextLine in the Label
    • DLRCharacterResult corresponds to the result of each Character in the TextLine

    The structure is shown in the figure below:

    DLR Result Structure

    Figure 1 – DLR Result Structure

You can download the similar complete source code from Here.

Build and Run the Project

  1. Right click the project, click Run As > Java Application.

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

In this article:

latest version

  • Latest version(3.2.20)
  • Version 3.x
    • Version 3.2.10
    • Version 3.2.0
    • Version 3.0.30
    • Version 3.0.20
    • Version 3.0.10
    • Version 3.0.0
  • Version 2.x
    • Version 2.2.20
    • Version 2.2.11
    • Version 2.2.10
    • Version 2.2.0
    • Version 2.0.0
    • Version 2.2.20
    • Version 2.2.11
    • Version 2.2.10
    • Version 2.2.0
    • Version 2.0.0
    • Version 2.0.0
    • Version 2.0.0
  • Version 1.x
    • Version 1.2.1
    • Version 1.2
    • Version 1.0
    • Version 1.2.1
    • Version 1.2
    • Version 1.0
    • Version 1.2.1
    • Version 1.2
    • Version 1.0
    • Version 1.2.1
Change +
© 2003–2024 Dynamsoft. All rights reserved.
Privacy Statement / Site Map / Home / Purchase / Support