Industrial Text Line Recognition Reference Implementation

Published: 04/12/2021

Edge Software Hub   /   Industrial Text Line Recognition  /  Documentation

Overview

This reference implementation provides an AI-enabled approach to recognize characters from a print text line using the deep learning method. Use CNN + LSTM + CTC and computer vision algorithms optimized by the Intel® Distribution of OpenVINO™ toolkit to detect and recognize characters of printed text lines in an industrial scenario, for example, product series number recognition and expired date detection for product tracking and packaging defect detection. 

Select Configure & Download to download the reference implementation and the software listed below.  

Configure & Download



Time to Complete

Programming
Language

Available Software

Approximately 30 minutes

Python* 3.6


Intel® Distribution of OpenVINO™
toolkit 2021.2


Target System Requirements 

  • Ubuntu* 18.04 LTS 
  • Intel® Core™ i5 processor or above with 16 GB of RAM 

How It Works 

The application uses the inference engine included in the Intel® Distribution of OpenVINO™ toolkit. The reference implementation shows an example of how the Industrial Text Line Recognition algorithm can be leveraged in industrial scenarios. 

  • Print text line video: Sample video that is used to simulate a live camera stream. The video includes 300 print text images. 
  • Inference Module: Ingests the frames from the camera stream and performs inference on each frame to recognize characters.
Figure 1: Architecture Diagram

 


Get Started

Industrial Text Line Recognition is a reference implementation for the application using OpenVINO™ inference engine. 

NOTE: This application is a reference implementation, not a production-ready custom commercially deployable industrial text line recognition tool.

Step 1: Install the Reference Implementation 

Select Configure & Download to download the reference implementation and then follow the steps below to install it. 

Configure & Download

 

  1. Open a new terminal, go to the downloaded folder and unzip the downloaded RI package:  
    unzip industrial_text_line_recognition.zip

     

  2.  Go to the industrial_text_line_recognition/ directory:
    cd industrial_text_line_recognition
      
  3. Change permission of the executable edgesoftware file: 
    chmod 755 edgesoftware
     
  4. Run the command below to install the Reference Implementation: 
    ./edgesoftware install

     

  5. During the installation, you will be prompted for the Product Key. The Product Key is contained in the email you received from Intel confirming your download. 
    Product Key Screen
    Figure 2: Product Key

     

  6. When the installation is complete, you see the message “Installation of package complete” and the installation status for each module. 
    Install Success Screen
    Figure 3: Install Success

     

Step 2: Set up a Python* Virtual Environment (Optional, recommended) 

Creating and using a Python virtual environment helps isolate Python dependencies between different projects. This ensures the Python packages installed for this application do not affect the system dependencies. 

1. Update ~/.bashrc to include the following lines at the bottom: 

# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

2. Reload the changes to ~/.bashrc

source ~/.bashrc

3. Create a Python 3.6 virtual environment for the reference implementation: 

mkvirtualenv -p python3.6 tlr

 

Check for Success 

(tlr) before the terminal prompt indicates the virtual environment is active. Make sure the virtual environment is active before executing the application at any time. 

Active Virtual Environment Screen
Figure 4: Active Virtual Environment

 

4. Activate the virtual environment in a new terminal window with the command: 

workon tlr

5. Navigate to the package folder and install the required Python modules. Make sure to activate the virtual environment (refer to step 4 above) every time you run the application to ensure the correct dependencies are utilized: 

cd industrial_text_line_recognition/Industrial_Text_Line_Recognition_<version #>/Industrial_Text_Line_Recognition/Text_Line_Recogniton/
pip install -r requirements.txt

 

Step 3: Check the Reference Implementation 

The reference implementation uses the Inference Engine module for performing inference on test images. 

Inference Engine Module
Figure 5: Inference Engine Module

 

Execute the following command to run inference on a single test image: 

# Set OpenVINO environment variables if not already done
source /opt/intel/openvino_2021/bin/setupvars.sh -pyver 3.6

python inference.py \
       --model <path/to/OpenVINO/XML/file> \
       --label <path/to/label/file> \
       --input <path/to/single/test/image> \
       --device <target device for inference 'CPU, MYRIAD, HDDL' - CPU is default>

# Example command using default values :
python inference.py \
       --model ./models/model.xml \
       --label ./models/labels.txt \
       --input ./data//2020081707\:39\:59E_217.jpg

Check for Success 

If it was successful, the results will be as follows: 

Single Image Inference Success Screen
Figure 6: Inference on Single Test Image Success

 

Execute the following command to run inference on a directory of images: 

# Set OpenVINO environment variables if not already done
source /opt/intel/openvino_2021/bin/setupvars.sh -pyver 3.6

python inference.py \
       --model <path/to/OpenVINO/XML/file> \
       --label <path/to/label/file> \
       --input <path/to/directory/of/images> \
       --device <target device for inference 'CPU, MYRIAD, HDDL' - CPU is default>


# Example command using default values :
python inference.py \
       --model ./models/model.xml \
       --label ./models/labels.txt \
       --input ./data/

Check for Success 

If it was successful, the results will be as follows: 

Directory of Images Inference Success
Figure 7: Inference on Directory of Images Success

 

Execute the following command to run inference on a directory of images and calculate the accuracy: 

# Set OpenVINO environment variables if not already done
source /opt/intel/openvino_2021/bin/setupvars.sh -pyver 3.6

python inference.py \
       --model <path/to/OpenVINO/XML/file> \
       --label <path/to/label/file> \
       --input <path/to/directory/of/images> \
       --calc_accuracy \
       --device <target device for inference 'CPU, MYRIAD, HDDL' - CPU is default>


# Example command to calculate the accuracy :
python inference.py \
       --model ./models/model.xml \
       --label ./models/labels.txt \
       --input ./data/ \
       --calc_accuracy 

Check for Success 

If it was successful, the results will be as follows: 

Inference on Directory of Images Accuracy Screen
Figure 8: Inference on Directory of Images Accuracy

 

How to Uninstall Dependencies Installed by this Documentation 

The Python modules installed from the requirements.txt file are limited to the virtualenv (tlr). To uninstall these dependencies completely, simply deactivate the virtual environment and remove it. 

deactivate
rmvirtualenv tlr

Check for Success 

If it was successful, the terminal output will be as follows: 

Uninstall Dependencies Screen
Figure 9: Uninstall Dependencies Success

 

To uninstall all packages installed by the edgesoftware script, use the command below:

cd industrial_text_line_recognition/
./edgesoftware uninstall -a


Check for Success

If the package uninstall was successful, the terminal output will be as follows:

Package Uninstall Success Screen
Figure 10: Package Uninstall Success Screen

Summary and Next Steps 

You successfully ran the Industrial Text Line Recognition application and displayed the result using the OpenVINO™ Inference Engine. 

To get access to the deep learning training algorithm that was used to generate the Industrial Text Line Recognition model, please contact your Intel account manager. 

This application can be deployed on the factory floor using the Edge Insights for Industrial software package. A sample implementation can be downloaded by selecting the Industrial Text Line Recognition Application under Video Ingestion & Analytics (Step 3 of 6) tab from the Customize & Download section on the bottom-right. 


Learn More 

To continue learning, see the following guides and software resources: 


Troubleshooting 

ModuleNotFoundError: No module named ‘openvino’ error 

No module named 'openvino' error screen
Figure 11: No Module Named 'openvino' Error 

 

Source the OpenVINO environment variables and run the application again. 

source /opt/intel/openvino_2021/bin/setupvars.sh -pyver 3.6

ModuleNotFoundError: No module named ‘cv2’ 

No Module Named 'cv2' Error Screen
Figure 12: No Module Named 'cv2' Error

 

Activate the virtual environment by executing the command below and run the application again. 

workon tlr

Support Forum 

If you're unable to resolve your issues, contact the Support Forum.  

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.