tesseract-ocrHow do I use the Tesseract OCR engine in different modes?
The Tesseract OCR engine can be used in three different modes:
-
Command Line Mode: This mode allows users to run Tesseract from the command prompt. An example command to run Tesseract is
tesseract input.jpg output
. This command will take the image fileinput.jpg
and create a text fileoutput.txt
containing the OCR result. -
C++ API Mode: This mode allows users to call Tesseract from their own C++ programs. An example of this is shown below:
#include <tesseract/baseapi.h>
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
api->Init(NULL, "eng");
api->SetImage(imagedata);
api->Recognize(0);
tesseract::ResultIterator* ri = api->GetIterator();
if (ri != 0) {
do {
const char* word = ri->GetUTF8Text(tesseract::RIL_WORD);
float conf = ri->Confidence(tesseract::RIL_WORD);
printf("word: '%s'; \tconf: %.2f\n", word, conf);
delete[] word;
} while (ri->Next(tesseract::RIL_WORD));
}
api->End();
The code above will take an image as input, run Tesseract on it, and output each word found along with its confidence score.
- Python API Mode: This mode allows users to call Tesseract from their own Python programs. An example of this is shown below:
import tesseract
api = tesseract.TessBaseAPI()
api.Init(".","eng",tesseract.OEM_DEFAULT)
api.SetImage(imagedata)
text=api.GetUTF8Text()
conf=api.MeanTextConf()
print("Text: " + text)
print("Confidence: " + str(conf))
The code above will take an image as input, run Tesseract on it, and output the text found along with its confidence score.
Helpful links
More of Tesseract Ocr
- How can I use Tesseract OCR with VBA?
- How can I use tesseract ocr portable to recognize text in images?
- How can I use Tesseract OCR with Xamarin?
- How can I use Python to get the coordinates of words detected by Tesseract OCR?
- How can I integrate Tesseract OCR into a Unity project?
- How do I add a language to Tesseract OCR on Windows?
- How do I add Tesseract OCR to my environment variables?
- How can I use Tesseract to perform zonal OCR?
- How do I set the Windows path for Tesseract OCR?
- How do I install Tesseract OCR on Windows?
See more codes...