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 to use Tesseract OCR to recognize and process Korean text?
- How can I use Tesseract OCR with Xamarin Forms?
- How can I use Tesseract to perform zonal OCR?
- How can I use Python to get the coordinates of words detected by Tesseract OCR?
- How do I add Tesseract OCR to my environment variables?
- How can I use Tesseract OCR with Xamarin?
- How do I set the Windows path for Tesseract OCR?
- How do I install Tesseract OCR on Windows?
- How can I use Tesseract OCR on Windows via the command line?
- How do I use tesseract OCR on Windows 64-bit?
See more codes...