top of page
Jon Zhao

Develop an open source Raspberry Pi OCR solution using Edge AI camera

Optical character recognition or optical character reader (OCR) is the electronic or mechanical conversion of images of typed, handwritten or printed text into machine-encoded text, whether from a scanned document, a photo of a document, a scene-photo (for example the text on signs and billboards in a landscape photo) or from subtitle text superimposed on an image (for example: from a television broadcast).

It is a common method of digitizing printed texts so that they can be electronically edited, searched, stored more compactly, displayed on-line, and used in machine processes such as cognitive computing, machine translation, (extracted) text-to-speech, key data and text mining. OCR is a field of research in pattern recognition, artificial intelligence and computer vision.

A good OCR system requires the following:

  1. Capable of agile iterative algorithm models, including model training for new scenarios and online deployment of models. Reduce the cost of continuous deployment

  2. The lens can be changed to suit the needs of various scenes

  3. Complete camera system, supporting global exposure, different resolution and frame rate, to facilitate deployment

  4. Open source system, easy to develop and integrate their own applications

The combination of OpenNCC and Raspberry PI is selected to realize the OCR system, which has the above advantages.The OpenNCC OCR solution is using PaddleOCR and Intel OpenVINO. PaddleOCR aims to create multilingual, awesome, leading, and practical OCR tools that help users train better models and apply them into practice.

We designed the load reasonably, deployed some inference models on OpenNCC and Raspberry PI respectively, and converted the PaddleOCR model into OpenVINO support model through ONNX, which was deployed to run on OpenNCC. Of course, considering the good support of Raspberry Pi with OpenCV, we deployed part of image preprocessing and model inference on Raspberry PI to achieve best practices.

Now, let's start develop the OCR solution.

Prepare the hardwares

  • Openncc NCC Edge AI camera

  • Raspberry PI 4B

  • USB cable

  • 5v Power adapter

  • Ethernet cable

Connecting OpenNCC and Raspberry Pi

  • Connect raspberry PI 4 Model B and OpenNCC with USB3.0

Configuring the raspberry PI

The following commands are operated on the board of Raspberry PI. Need to connect raspberry with a monitor, mouse and keyboard.

  • Install libusb, opencv and ffmpeg on Raspberry Pi

$ sudo apt-get install libopencv-dev -y

$ sudo apt-get install libusb-dev -y

$ sudo apt-get install libusb-1.0.0-dev -y

$ sudo apt-get install ffmpeg -y

  • If you want to use python

$ sudo apt-get install python3-opencv -y

  • Clone OpenNCC OCR repo onto Raspberry Pi, it used PaddleOCR based on Paddle-Lite platform

$ git clone https://gitee.com/eyecloud/openncc_hub.git

  • Build the demo

$ cd openncc_hub/ncc_ocr/mainApp

$ sudo make clean

$ sudo make



Run the main application to deploy the first AI-model to the OpenNCC camera,and capture streaming to Raspberry Pi.

$ cd openncc_hub/ncc_ocr/mainApp/bin

$ sudo ./mainApp

  • Enter inference_lite_lib.armlinux.armv7hf/demo/cxx/ocr,to build the PaddleOCR thread application.

$ cd openncc_hub/ncc_ocr/ inference_lite_lib.armlinux.armv7hf/demo/cxx/ocr

$ sudo make clean

$ sudo make


  • After successful built it, type:

$ cd openncc_hub/ncc_ocr/ inference_lite_lib.armlinux.armv7hf/demo/cxx/ocr/debug

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib: ‘your_debug_dir

$ ./ocr_db_crnn

We point the camera at the target's text,could see the recognition results with the corresponding location in the video stream.



You can also just run the compiled program directly. Enter path Bin run the script:

$ cd openncc_hub/ncc_ocr/Bin

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib: ‘your_bin_dir’

$ ./run.sh

If the opencv library version mismatch occurs, you need to go to debug path /inference_lite_lib.armlinux.armv7hf/demo/cxx/ocr/debug, then copy ‘ocr_db_crnn’ file to the Bin directory, and run ‘./run.sh ‘again.


352 views0 comments

Comments


bottom of page