O'Reilly logo

Learn OpenCV 4 by Building Projects - Second Edition by Prateek Joshi, Vinicius G. Mendonca, David Millan Escriva

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating an OCR function

We'll change the previous example to work with Tesseract. Start by adding tesseract/baseapi.h and fstream to the include list:

#include opencv2/opencv.hpp; 
#include tesseract/baseapi.h; 
 
#include vector; 
#include fstream; 

Then, we'll create a global TessBaseAPI object that represents our Tesseract OCR engine:

tesseract::TessBaseAPI ocr; 
The ocr engine is completely self-contained. If you want to create a multi-threaded piece of OCR software, just add a different TessBaseAPI object in each thread, and the execution will be fairly thread-safe. You just need to guarantee that file writing is not done over the same file, otherwise you'll need to guarantee safety for this operation.

Next, we will create a function called ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required