Build Tesseract using CMake (Linux)
mainYou can use CMake as an alternative build system on Linux.
mkdir build
cd build && cmake .. && make
sudo make installrepository·main·Indexed 24 days ago
https://github.com/ub-mannheim/tesseractAn open-source OCR engine providing a command-line tool and the libtesseract library for extracting text from images. It supports over 100 languages and features both a modern LSTM-based neural net engine and a legacy engine. Documentation covers installation via binary packages or source, CLI usage, C/C++ API integration (capi.h and baseapi.h), supported image formats (PNG, JPEG, TIFF), and output formats including PDF, hOCR, and ALTO.
You can use CMake as an alternative build system on Linux.
mkdir build
cd build && cmake .. && make
sudo make installThe unit tests require specific font files to function correctly. Ensure the following fonts are installed in the test environment:
arialbi.ttf, times.ttf, verdana.ttfae_Arab.ttfDejaVuSans-ExtraLight.ttfLohit-Hindi.ttfUnBatang.ttfTo compile ScrollView.jar, you must have an internet connection and curl installed. The build process will automatically download the following dependencies and place them in tesseract/java:
piccolo2d-core-3.0.1.jarpiccolo2d-extras-3.0.1.jarjaxb-api-2.3.1.jarmake ScrollView.jarYou can install Tesseract using one of two methods:
To execute the unit tests for Tesseract, you must first prepare the environment by regenerating build files, initializing submodules, and fetching the required test data and fonts. You must also set the TESSDATA_PREFIX environment variable to point to your tessdata directory before running the check command.
autoreconf -fiv
git submodule update --init
git clone https://github.com/egorpugin/tessdata tessdata_unittest --depth 1
cp tessdata_unittest/fonts/* test/testing/
mv tessdata_unittest/* ../
export TESSDATA_PREFIX=/prefix/to/path/to/tessdata
make checkTesseract requires traineddata files (at minimum English and OSD) to be installed in the directory specified by the TESSDATA_PREFIX environment variable.
You can download individual files using wget, curl, or a browser. To clone the entire language repository (note: this is >1.2 GB), use:
git clone https://github.com/tesseract-ocr/tessdata.git tesseract-ocr.tessdataIf you have cloned Tesseract from GitHub, you must generate the configure script using autogen.sh.
Prerequisites:
automakepkg-configpango-develcairo-develicu-develBuild Steps:
./autogen.sh./configuremakesudo make install and sudo ldconfigmake trainingsudo make training-install./autogen.sh
./configure
make
sudo make install
sudo ldconfig
make training
sudo make training-installDevelopers can integrate Tesseract into their own applications using the provided C or C++ APIs.
capi.h.baseapi.h.For other programming languages, check the Tesseract Wrappers documentation in the AddOns section.
Tesseract uses a wide range of configuration variables (often prefixed with tessedit_, thresholding_, quality_, etc.) to control OCR behavior. These can be set via the API or CLI. Key categories include:
tessedit_ocr_engine_mode, tessedit_pageseg_mode.tessedit_char_blacklist, tessedit_char_whitelist.tessedit_create_pdf, tessedit_create_hocr, tessedit_create_tsv, tessedit_create_page_xml, tessedit_create_alto.thresholding_method, thresholding_window_size, invert_threshold, enable_noise_removal.tessedit_reject_mode, quality_char_pc, quality_blob_pc, tessedit_reject_block_percent.lstm_use_matrix, lstm_choice_mode, lstm_choice_iterations.pageseg_devanagari_split_strategy, ocr_devanagari_split_strategy.The tesseract::Classify class provides several configuration variables (control knobs) to tune the behavior of the adaptive matcher and normalization processes. These are typically set during training or via configuration files.
classify_enable_adaptive_matcher (BOOL): Enables/disables the adaptive matcher.classify_use_pre_adapted_templates (BOOL): Use templates that were previously adapted.classify_save_adapted_templates (BOOL): Save templates after adaptation.matcher_good_threshold (double): Threshold for a good match.matcher_perfect_threshold (double): Threshold for a perfect match.matcher_rating_margin (double): Margin for ratings.classify_norm_method (INT): Method used for outline normalization.classify_char_norm_range (double): Range for character normalization.classify_nonlinear_norm (BOOL): Enables non-linear normalization to distribute edges.classify_enable_learning (BOOL): Enables/disables the learning mechanism.classify_debug_level (INT): Sets the level of debug output for classification.Tesseract supports a wide range of input and output formats:
Supported Input Image Formats:
Supported Output Formats:
Use the tesseract command to perform OCR on images. The basic syntax requires an input image name and a base name for the output file.
Syntax:
tesseract imagename outputbase [-l lang] [--oem ocrenginemode] [--psm pagesegmode] [configfiles...]
Key Options:
-l lang: Specify the language (e.g., eng).--oem ocrenginemode: Select the OCR engine mode. Use --oem 0 to enable the Legacy OCR Engine mode (Tesseract 3 compatibility).--psm pagesegmode: Set the page segmentation mode.For a full list of options, run tesseract --help or man tesseract.
tesseract imagename outputbase [-l lang] [--oem ocrenginemode] [--psm pagesegmode] [configfiles...]