Custom C++ implementation of EasyOCR
This C++ project implements the pre/post processing to run a OCR pipeline consisting of a text detector CRAFT, and a CRNN based text recognizer. Unlike the EasyOCR python which is API based, this repo provides a set of classes to show how you can integrate OCR in any C++ program for maximum flexibility. The torchExample.cpp main program highlights how to utilize all elements of the EasyOCR-cpp pipeline. Because a test program is only provided, make sure to configure your input image within torchExample.cpp if you only plan to utilize the test program.
thrown together quickly within a week so many debug comments :)
Libtorch is being utilized with an in-house class I ussually use for C++ inference TorchModel, and OpenCV for the pre/post processing steps. The TorchModel class can easily adapted to run inference on most Pytorch models converted to TorchScript. Provides some handy functions to pre process opencv::Mat and handle device usage (GPU,CPU). Great starting point for C++ based inference for Pytorch Models.
Some features that have yet to be implemented:
- beam search, only implemented greedy decoding
- .txt/.pdf output
- exact bounding box merge alg from EasyOCR, opted for custom one which is less complex
- support for other languages, atm only english is supported.
Click to Download libtorch - > download
Use OpenCV Windows installer and unzip (v4.6) - > OpenCV libs
Make sure to change the location in the Makefile for OpenCV to point to your OpenCV build dir
Create a build directory within the repo, cd to it and run
cmake -DCMAKE_PREFIX_PATH=<absolute-path-to-libtorch-folder> ..
This will generate a solution within the build folder you can open up in Visual Studio. Make sure to use the Release config when building
Configure your input image here. Currently the test program is using the test.jpg which comes in the repo.
Launch from command-line, or within Visual Studio after building.
Since its designed to be used in a C++ program, text is not being written to disk at the moment An output image will be generated in the main repo dir containing an annotated version of the input image with detection bounding boxes