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 ...

Get Building Computer Vision Projects with OpenCV 4 and C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.