### Run library examples Source: https://github.com/houqp/leptess/blob/master/README.md Execute provided example code from the repository. ```bash cargo run --example low_level_ocr_full_page ``` -------------------------------- ### Install dependencies on Windows Source: https://github.com/houqp/leptess/blob/master/README.md Install Tesseract using vcpkg on Windows. ```cmd REM from the vcpkg directory REM 32 bit .\vcpkg install tesseract:x86-windows REM 64 bit .\vcpkg install tesseract:x64-windows ``` -------------------------------- ### Install dependencies on Ubuntu Source: https://github.com/houqp/leptess/blob/master/README.md Install required system libraries for Leptonica and Tesseract on Ubuntu. ```bash sudo apt-get install libleptonica-dev libtesseract-dev clang ``` ```bash sudo apt-get install tesseract-ocr-eng ``` -------------------------------- ### Install dependencies on Mac Source: https://github.com/houqp/leptess/blob/master/README.md Install required system libraries for Tesseract and Leptonica on macOS using Homebrew. ```bash brew install tesseract leptonica pkg-config ``` -------------------------------- ### Get Word Bounding Boxes with LepTess Source: https://context7.com/houqp/leptess/llms.txt Retrieves word-level bounding boxes from an image. Ensure the tessdata directory and image file are accessible. ```rust use leptess::LepTess; use leptess::capi::TessPageIteratorLevel_RIL_WORD; fn main() -> Result<(), Box> { let mut lt = LepTess::new(Some("./tests/tessdata"), "eng")?; lt.set_image("./tests/di.png")?; // Get word-level bounding boxes (text_only=true) let boxes = lt.get_component_boxes(TessPageIteratorLevel_RIL_WORD, true) .expect("Failed to get component boxes"); println!("Found {} words", boxes.get_n()); for b in &boxes { let geometry = b.get_geometry(); println!("Word at x={}, y={}, w={}, h={}", geometry.x, geometry.y, geometry.w, geometry.h); } Ok(()) } ``` -------------------------------- ### Configure Tesseract Parameters with LepTess::set_variable Source: https://context7.com/houqp/leptess/llms.txt Customizes Tesseract's OCR behavior by setting internal parameters using the `Variable` enum. Examples include character blacklisting/whitelisting and page segmentation modes. ```rust use leptess::{LepTess, Variable}; fn main() -> Result<(), Box> { let mut lt = LepTess::new(Some("./tests/tessdata"), "eng")?; // Blacklist certain characters from recognition lt.set_variable(Variable::TesseditCharBlacklist, "xyz")?; // Whitelist only digits for number recognition lt.set_variable(Variable::TesseditCharWhitelist, "0123456789")?; // Set page segmentation mode (6 = assume single uniform block of text) lt.set_variable(Variable::TesseditPagesegMode, "6")?; lt.set_image("./tests/di.png")?; println!("{}", lt.get_utf8_text()?); Ok(()) } ``` -------------------------------- ### Configure and test on Windows Source: https://github.com/houqp/leptess/blob/master/README.md Set environment variables and run tests for the vcpkg-managed library. ```cmd SET VCPKGRS_DYNAMIC=true cargo test ``` -------------------------------- ### Execute Complete OCR Pipeline Source: https://context7.com/houqp/leptess/llms.txt Demonstrates the full workflow including initialization, image loading, resolution handling, and word-level analysis. ```rust use leptess::LepTess; use leptess::capi::TessPageIteratorLevel_RIL_WORD; fn main() -> Result<(), Box> { // Initialize Tesseract with English language let mut lt = LepTess::new(Some("./tests/tessdata"), "eng")?; // Load image lt.set_image("./tests/di.png")?; // Set fallback resolution to avoid warnings lt.set_fallback_source_resolution(70); // Get image dimensions if let Some((w, h)) = lt.get_image_dimensions() { println!("Processing image: {}x{} pixels", w, h); } // Extract full page text println!("\n=== Full Page Text ==="); println!("{}", lt.get_utf8_text()?); // Get word-level boxes and process each word println!("\n=== Word-by-Word Analysis ==="); if let Some(boxes) = lt.get_component_boxes(TessPageIteratorLevel_RIL_WORD, true) { for (i, b) in boxes.into_iter().enumerate() { lt.set_rectangle_from_box(&b); let word = lt.get_utf8_text()?.trim().to_string(); let conf = lt.mean_text_conf(); if !word.is_empty() { println!("Word {}: '{}' (confidence: {}%)", i + 1, word, conf); } } } Ok(()) } ``` -------------------------------- ### Configuration Parameters Source: https://github.com/houqp/leptess/blob/master/variables_list.txt A list of available configuration parameters for the Leptess engine. ```APIDOC ## Configuration Parameters ### Description This list contains various parameters that can be used to configure the behavior of the OCR engine, including dictionary loading, segmentation, and debugging settings. ### Parameters - **load_system_dawg** (int) - Load system word dawg. - **load_freq_dawg** (int) - Load frequent word dawg. - **load_unambig_dawg** (int) - Load unambiguous word dawg. - **load_punc_dawg** (int) - Load dawg with punctuation patterns. - **load_number_dawg** (int) - Load dawg with number patterns. - **load_bigram_dawg** (int) - Load dawg with special word bigrams. - **use_only_first_uft8_step** (int) - Use only the first UTF8 step of the given string when computing log probabilities. - **stopper_no_acceptable_choices** (int) - Make AcceptableChoice() always return false. - **segment_nonalphabetic_script** (int) - Don't use any alphabetic-specific tricks. - **save_doc_words** (int) - Save Document Words. - **merge_fragments_in_matrix** (int) - Merge the fragments in the ratings matrix and delete them after merging. - **wordrec_enable_assoc** (int) - Associator Enable. - **force_word_assoc** (int) - Force associator to run regardless of what enable_assoc is. - **chop_enable** (int) - Chop enable. - **chop_vertical_creep** (int) - Vertical creep. - **chop_new_seam_pile** (int) - Use new seam_pile. - **assume_fixed_pitch_char_segment** (int) - Include fixed-pitch heuristics in char segmentation. - **wordrec_skip_no_truth_words** (int) - Only run OCR for words that had truth recorded in BlamerBundle. - **wordrec_debug_blamer** (int) - Print blamer debug messages. - **wordrec_run_blamer** (int) - Try to set the blame for errors. - **save_alt_choices** (int) - Save alternative paths found during chopping and segmentation search. - **language_model_ngram_on** (int) - Turn on/off the use of character ngram model. - **language_model_ngram_use_only_first_uft8_step** (int) - Use only the first UTF8 step of the given string when computing log probabilities. - **language_model_ngram_space_delimited_language** (int) - Words are delimited by space. - **language_model_use_sigmoidal_certainty** (int) - Use sigmoidal score for certainty. - **tessedit_resegment_from_boxes** (int) - Take segmentation and labeling from box file. - **tessedit_resegment_from_line_boxes** (int) - Conversion of word/line box file to char box file. - **tessedit_train_from_boxes** (int) - Generate training data from boxed chars. - **tessedit_make_boxes_from_boxes** (int) - Generate more boxes from boxed chars. - **tessedit_train_line_recognizer** (int) - Break input into lines and remap boxes if present. - **tessedit_dump_pageseg_images** (int) - Dump intermediate images made during page segmentation. - **tessedit_do_invert** (int) - Try inverting the image in LSTMRecognizeWord. - **tessedit_ambigs_training** (int) - Perform training for ambiguities. - **tessedit_adaption_debug** (int) - Generate and print debug information for adaption. - **applybox_learn_chars_and_char_frags_mode** (int) - Learn both character fragments and unfragmented characters. - **applybox_learn_ngrams_mode** (int) - Each bounding box is assumed to contain ngrams. - **tessedit_display_outwords** (int) - Draw output words. - **tessedit_dump_choices** (int) - Dump char choices. - **tessedit_timing_debug** (int) - Print timing stats. - **tessedit_fix_fuzzy_spaces** (int) - Try to improve fuzzy spaces. - **tessedit_unrej_any_wd** (int) - Don't bother with word plausibility. - **tessedit_fix_hyphens** (int) - Crunch double hyphens. - **tessedit_enable_doc_dict** (int) - Add words to the document dictionary. - **tessedit_debug_fonts** (int) - Output font info per char. - **tessedit_debug_block_rejection** (int) - Block and Row stats. - **tessedit_enable_bigram_correction** (int) - Enable correction based on the word bigram dictionary. - **tessedit_enable_dict_correction** (int) - Enable single word correction based on the dictionary. - **enable_noise_removal** (int) - Remove and conditionally reassign small outlines. - **tessedit_minimal_rej_pass1** (int) - Do minimal rejection on pass 1 output. - **tessedit_test_adaption** (int) - Test adaption criteria. - **test_pt** (int) - Test for point. - **paragraph_text_based** (int) - Run paragraph detection on the post-text-recognition. - **lstm_use_matrix** (int) - Use ratings matrix/beam search with lstm. - **tessedit_good_quality_unrej** (int) - Reduce rejection on good docs. - **tessedit_use_reject_spaces** (int) - Reject spaces. - **tessedit_preserve_blk_rej_perfect_wds** (int) - Only rej partially rejected words in block rejection. - **tessedit_preserve_row_rej_perfect_wds** (int) - Only rej partially rejected words in row rejection. - **tessedit_dont_blkrej_good_wds** (int) - Use word segmentation quality metric. - **tessedit_dont_rowrej_good_wds** (int) - Use word segmentation quality metric. - **tessedit_row_rej_good_docs** (int) - Apply row rejection to good docs. - **tessedit_reject_bad_qual_wds** (int) - Reject all bad quality wds. - **tessedit_debug_doc_rejection** (int) - Page stats. - **tessedit_debug_quality_metrics** (int) - Output data to debug file. - **bland_unrej** (int) - Unrej potential with no checks. - **unlv_tilde_crunching** (int) - Mark v.bad words for tilde crunch. - **hocr_font_info** (int) - Add font info to hocr output. - **hocr_char_boxes** (int) - Add coordinates for each character to hocr output. - **crunch_early_merge_tess_fails** (int) - Before word crunch. - **crunch_early_convert_bad_unlv_chs** (int) - Take out ~^ early. - **crunch_terrible_garbage** (int) - As it says. - **crunch_leave_ok_strings** (int) - Don't touch sensible strings. - **crunch_accept_ok** (int) - Use acceptability in okstring. ``` -------------------------------- ### Initialize LepTess OCR Engine Source: https://context7.com/houqp/leptess/llms.txt Creates a new instance with a specified language data path and language code. Use None for the data path to utilize system defaults. ```rust use leptess::LepTess; fn main() -> Result<(), Box> { // Initialize with custom tessdata path let mut lt = LepTess::new(Some("./tests/tessdata"), "eng")?; // Or use system default tessdata location let mut lt_default = LepTess::new(None, "eng")?; Ok(()) } ``` -------------------------------- ### Perform basic OCR with Leptess Source: https://github.com/houqp/leptess/blob/master/README.md Initialize the OCR engine and extract text from an image file. ```rust let mut lt = leptess::LepTess::new(None, "eng").unwrap(); lt.set_image("path/to/page.bmp"); println!("{}", lt.get_utf8_text().unwrap()); ``` -------------------------------- ### LepTess::new - Initialize OCR Engine Source: https://context7.com/houqp/leptess/llms.txt Initializes a new LepTess instance with a specified language data path and language code. ```APIDOC ## LepTess::new ### Description Creates a new high-level LepTess instance with specified language data path and language code. ### Parameters #### Request Body - **tessdata_path** (Option) - Optional - Path to the directory containing language data files. - **lang** (String) - Required - Language code (e.g., "eng"). ``` -------------------------------- ### Configure Image Resolution with TessApi Source: https://context7.com/houqp/leptess/llms.txt Use set_source_resolution to manually define DPI or set_fallback_source_resolution to handle cases where resolution is not detected. ```rust use leptess::{leptonica, tesseract}; use std::path::Path; fn main() -> Result<(), Box> { let mut api = tesseract::TessApi::new(None, "eng")?; let pix = leptonica::pix_read(Path::new("./tests/di.png"))?; api.set_image(&pix); // Check current resolution let resolution = api.get_source_y_resolution(); println!("Detected resolution: {} dpi", resolution); // Set resolution if not valid (suppresses warnings) if resolution <= 0 { api.set_source_resolution(70); } // Get image dimensions if let Some((width, height)) = api.get_image_dimensions() { println!("Image size: {}x{} pixels", width, height); } Ok(()) } ``` -------------------------------- ### LepTess::set_image - Load Image from File Source: https://context7.com/houqp/leptess/llms.txt Sets the image to be processed for OCR from a file path. ```APIDOC ## LepTess::set_image ### Description Sets the image to be processed for OCR from a file path. Supports PNG, JPEG, TIFF, and BMP. ### Parameters #### Request Body - **path** (String) - Required - File path to the image. ``` -------------------------------- ### Load Image from File Source: https://context7.com/houqp/leptess/llms.txt Sets the image source from a file path, clearing previous results and resetting the processing rectangle to the full image. ```rust use leptess::LepTess; fn main() -> Result<(), Box> { let mut lt = LepTess::new(Some("./tests/tessdata"), "eng")?; // Load image from file path lt.set_image("./tests/di.png")?; // Extract text from the entire image let text = lt.get_utf8_text()?; println!("Recognized text: {}", text); Ok(()) } ``` -------------------------------- ### LepTess::set_image_from_mem - Load Image from Memory Source: https://context7.com/houqp/leptess/llms.txt Sets the image to be processed from an in-memory buffer. ```APIDOC ## LepTess::set_image_from_mem ### Description Sets the image to be processed from an in-memory buffer. TIFF format is supported on all platforms. ### Parameters #### Request Body - **buffer** (&[u8]) - Required - Byte slice containing image data. ``` -------------------------------- ### Access Low-Level TessApi Source: https://context7.com/houqp/leptess/llms.txt Directly interact with Tesseract and Leptonica for fine-grained control over the OCR process and component iteration. ```rust use leptess::{leptonica, tesseract}; use std::path::Path; fn main() -> Result<(), Box> { // Create low-level API instance let mut api = tesseract::TessApi::new(Some("./tests/tessdata"), "eng")?; // Read image using Leptonica let pix = leptonica::pix_read(Path::new("./tests/di.png"))?; // Get image dimensions from Pix println!("Image dimensions: {}x{}", pix.get_w(), pix.get_h()); // Set image for recognition api.set_image(&pix); // Trigger recognition explicitly let result = api.recognize(); if result == 0 { println!("Recognition successful"); } // Get recognized text let text = api.get_utf8_text()?; println!("{}", text); // Get confidence score (0-100) let confidence = api.mean_text_conf(); println!("Mean confidence: {}%", confidence); Ok(()) } ``` -------------------------------- ### Tesseract Parameters Source: https://github.com/houqp/leptess/blob/master/variables_list.txt A comprehensive list of Tesseract parameters with their descriptions and default values. ```APIDOC ## Tesseract Parameters ### Description This section lists various parameters used to configure Tesseract OCR behavior. Each parameter includes its name, default value, and a brief explanation. ### Parameters #### Tesseract Configuration Parameters - **classify_num_cp_levels** (3) - Number of Class Pruner Levels - **textord_dotmatrix_gap** (3) - Max pixel gap for broken pixed pitch - **textord_debug_block** (0) - Block to do debug on - **textord_pitch_range** (2) - Max range test on pitch - **textord_words_veto_power** (5) - Rows required to outvote a veto - **textord_tabfind_show_strokewidths** (0) - Show stroke widths - **pitsync_linear_version** (6) - Use new fast algorithm - **pitsync_fake_depth** (1) - Max advance fake generation - **oldbl_holed_losscount** (10) - Max lost before fallback line used - **textord_skewsmooth_offset** (4) - For smooth factor - **textord_skewsmooth_offset2** (1) - For smooth factor - **textord_test_x** (-2147483647) - coord of test pt - **textord_test_y** (-2147483647) - coord of test pt - **textord_min_blobs_in_row** (4) - Min blobs before gradient counted - **textord_spline_minblobs** (8) - Min blobs in each spline segment - **textord_spline_medianwin** (6) - Size of window for spline segmentation - **textord_max_blob_overlaps** (4) - Max number of blobs a big blob can overlap - **textord_min_xheight** (10) - Min credible pixel xheight - **textord_lms_line_trials** (12) - Number of linew fits to do - **textord_tabfind_show_images** (0) - Show image blobs - **textord_fp_chop_error** (2) - Max allowed bending of chop cells - **edges_max_children_per_outline** (10) - Max number of children inside a character outline - **edges_max_children_layers** (5) - Max layers of nested children inside a character outline - **edges_children_per_grandchild** (10) - Importance ratio for chucking outlines - **edges_children_count_limit** (45) - Max holes allowed in blob - **edges_min_nonhole** (12) - Min pixels for potential char in box - **edges_patharea_ratio** (40) - Max lensq/area for acceptable child outline - **devanagari_split_debuglevel** (0) - Debug level for split shiro-rekha process. - **textord_tabfind_show_partitions** (0) - Show partition bounds, waiting if >1 - **textord_debug_tabfind** (0) - Debug tab finding - **textord_debug_bugs** (0) - Turn on output related to bugs in tab finding - **textord_testregion_left** (-1) - Left edge of debug reporting rectangle - **textord_testregion_top** (-1) - Top edge of debug reporting rectangle - **textord_testregion_right** (2147483647) - Right edge of debug rectangle - **textord_testregion_bottom** (2147483647) - Bottom edge of debug rectangle #### Editor Parameters - **editor_image_xpos** (590) - Editor image X Pos - **editor_image_ypos** (10) - Editor image Y Pos - **editor_image_menuheight** (50) - Add to image height for menu bar - **editor_image_word_bb_color** (7) - Word bounding box colour - **editor_image_blob_bb_color** (4) - Blob bounding box colour - **editor_image_text_color** (2) - Correct text colour - **editor_dbwin_xpos** (50) - Editor debug window X Pos - **editor_dbwin_ypos** (500) - Editor debug window Y Pos - **editor_dbwin_height** (24) - Editor debug window height - **editor_dbwin_width** (80) - Editor debug window width - **editor_word_xpos** (60) - Word window X Pos - **editor_word_ypos** (510) - Word window Y Pos - **editor_word_height** (240) - Word window height - **editor_word_width** (655) - Word window width #### Word Recognition Parameters - **wordrec_display_splits** (0) - Display splits - **poly_debug** (0) - Debug old poly - **poly_wide_objects_better** (1) - More accurate approx on wide things - **wordrec_display_all_blobs** (0) - Display Blobs - **wordrec_blob_pause** (0) - Blob pause #### Text Ordering and Pitch Detection Parameters - **textord_fp_chopping** (1) - Do fixed pitch chopping - **textord_force_make_prop_words** (0) - Force proportional word segmentation on all rows - **textord_chopper_test** (0) - Chopper is being tested. - **textord_restore_underlines** (1) - Chop underlines & put back - **textord_show_initial_words** (0) - Display separate words - **textord_show_new_words** (0) - Display separate words - **textord_show_fixed_words** (0) - Display forced fixed pitch words - **textord_blocksall_fixed** (0) - Moan about prop blocks - **textord_blocksall_prop** (0) - Moan about fixed pitch blocks - **textord_blocksall_testing** (0) - Dump stats when moaning - **textord_test_mode** (0) - Do current test - **textord_pitch_scalebigwords** (0) - Scale scores on big words - **textord_all_prop** (0) - All doc is proportial text - **textord_debug_pitch_test** (0) - Debug on fixed pitch test - **textord_disable_pitch_test** (0) - Turn off dp fixed pitch algorithm - **textord_fast_pitch_test** (0) - Do even faster pitch algorithm - **textord_debug_pitch_metric** (0) - Write full metric stuff - **textord_show_row_cuts** (0) - Draw row-level cuts - **textord_show_page_cuts** (0) - Draw page-level cuts - **textord_pitch_cheat** (0) - Use correct answer for fixed/prop - **textord_blockndoc_fixed** (0) - Attempt whole doc/block fixed pitch - **textord_show_tables** (0) - Show table regions - **textord_tablefind_show_mark** (0) - Debug table marking steps in detail - **textord_tablefind_show_stats** (0) - Show page stats used in table finding - **textord_tablefind_recognize_tables** (0) - Enables the table recognizer for table layout and filtering. - **textord_tabfind_show_initialtabs** (0) - Show tab candidates - **textord_tabfind_show_finaltabs** (0) - Show tab vectors - **textord_tabfind_only_strokewidths** (0) - Only run stroke widths - **textord_really_old_xheight** (0) - Use original wiseowl xheight - **textord_oldbl_debug** (0) - Debug old baseline generation - **textord_debug_baselines** (0) - Debug baseline generation - **textord_oldbl_paradef** (1) - Use para default mechanism - **textord_oldbl_split_splines** (1) - Split stepped splines - **textord_oldbl_merge_parts** (1) - Merge suspect partitions - **oldbl_corrfix** (1) - Improve correlation of heights - **oldbl_xhfix** (0) - Fix bug in modes threshold for xheights - **textord_ocropus_mode** (0) - Make baselines for ocropus ``` -------------------------------- ### LepTess::get_component_boxes Source: https://context7.com/houqp/leptess/llms.txt Retrieves bounding boxes for text components such as blocks, paragraphs, lines, words, or symbols in reading order. ```APIDOC ## GET LepTess::get_component_boxes ### Description Retrieves bounding boxes for text components (blocks, paragraphs, lines, words, or symbols) in reading order. Returns a Boxa collection. ### Parameters #### Request Body - **level** (TessPageIteratorLevel) - Required - The granularity level (e.g., RIL_WORD). - **text_only** (bool) - Required - Whether to filter for text-only components. ``` -------------------------------- ### Read Images with Leptonica Source: https://context7.com/houqp/leptess/llms.txt Load image files from disk or memory buffers for processing. ```rust use leptess::leptonica; use std::path::Path; fn main() -> Result<(), Box> { // Read image from file let pix = leptonica::pix_read(Path::new("./tests/di.png"))?; // Access image dimensions let width = pix.get_w(); let height = pix.get_h(); println!("Loaded image: {}x{} pixels", width, height); Ok(()) } ``` ```rust use leptess::leptonica; fn main() -> Result<(), Box> { // Simulate image data loaded from network or other source let image_bytes = std::fs::read("./tests/di.png")?; // Read image from memory let pix = leptonica::pix_read_mem(&image_bytes)?; println!("Image loaded from memory: {}x{}", pix.get_w(), pix.get_h()); Ok(()) } ``` -------------------------------- ### Word-by-Word OCR with Confidence Scores using TessApi Source: https://context7.com/houqp/leptess/llms.txt Processes each detected word individually, extracting text and confidence scores. Requires leptonica and tesseract crates. Ensure image path is correct. ```rust use leptess::{leptonica, tesseract}; use leptess::capi::TessPageIteratorLevel_RIL_WORD; use std::path::Path; fn main() -> Result<(), Box> { let mut api = tesseract::TessApi::new(None, "eng")?; let pix = leptonica::pix_read(Path::new("./tests/di.png"))?; api.set_image(&pix); // Get word bounding boxes let boxes = api.get_component_images(TessPageIteratorLevel_RIL_WORD, true) .expect("Failed to get components"); println!("Found {} word components", boxes.get_n()); // Process each word individually for b in &boxes { api.set_rectangle_from_box(&b); let text = api.get_utf8_text()?; let confidence = api.mean_text_conf(); println!("{:?}, confidence: {}%, text: {}", b, confidence, text.trim()); } Ok(()) } ``` -------------------------------- ### Load Image from Memory Source: https://context7.com/houqp/leptess/llms.txt Processes images from an in-memory buffer, which is useful for dynamic or network-sourced images. TIFF format is universally supported, while other formats depend on the platform. ```rust use leptess::LepTess; use std::io::Cursor; fn main() -> Result<(), Box> { // Load image using the image crate and convert to TIFF let img = image::open("./tests/di.png")?; let mut tiff_buffer = Vec::new(); img.write_to( &mut Cursor::new(&mut tiff_buffer), image::ImageOutputFormat::Tiff, )?; let mut lt = LepTess::new(Some("./tests/tessdata"), "eng")?; // Set image from memory buffer lt.set_image_from_mem(&tiff_buffer)?; println!("{}", lt.get_utf8_text()?); Ok(()) } ``` -------------------------------- ### LepTess::get_utf8_text - Extract Recognized Text Source: https://context7.com/houqp/leptess/llms.txt Extracts the recognized text from the currently selected region of the image. ```APIDOC ## LepTess::get_utf8_text ### Description Extracts the recognized text from the currently selected region of the image. ### Response #### Success Response (200) - **text** (String) - The recognized text. ``` -------------------------------- ### Export OCR Results as ALTO XML with LepTess Source: https://context7.com/houqp/leptess/llms.txt Extracts OCR results in ALTO XML format, suitable for digitized documents. Specify the page number for extraction. ```rust use leptess::LepTess; fn main() -> Result<(), Box> { let mut lt = LepTess::new(Some("./tests/tessdata"), "eng")?; lt.set_image("./tests/di.png")?; // Get ALTO XML output for page 0 let alto = lt.get_alto_text(0)?; println!("{}", alto); Ok(()) } ``` -------------------------------- ### LepTess::set_variable Source: https://context7.com/houqp/leptess/llms.txt Configures internal Tesseract parameters for custom OCR behavior. ```APIDOC ## POST LepTess::set_variable ### Description Sets internal Tesseract parameters to customize OCR behavior, such as character whitelists/blacklists or page segmentation modes. ### Parameters #### Request Body - **variable** (Variable) - Required - The configuration key to set. - **value** (string) - Required - The value to assign to the variable. ``` -------------------------------- ### Export OCR Results as TSV with LepTess Source: https://context7.com/houqp/leptess/llms.txt Extracts OCR results in Tab-Separated Values (TSV) format, providing detailed information including position and confidence. Specify the page number for extraction. ```rust use leptess::LepTess; fn main() -> Result<(), Box> { let mut lt = LepTess::new(Some("./tests/tessdata"), "eng")?; lt.set_image("./tests/di.png")?; // Get TSV output for page 0 let tsv = lt.get_tsv_text(0)?; println!("{}", tsv); Ok(()) } ``` -------------------------------- ### LepTess::get_alto_text Source: https://context7.com/houqp/leptess/llms.txt Extracts text in ALTO XML format for digitized documents. ```APIDOC ## GET LepTess::get_alto_text ### Description Extracts text in ALTO (Analyzed Layout and Text Object) XML format, commonly used for digitized documents and library archives. ### Parameters #### Request Body - **page_number** (int) - Required - The page index to export. ``` -------------------------------- ### LepTess::get_tsv_text Source: https://context7.com/houqp/leptess/llms.txt Extracts text in Tab-Separated Values format. ```APIDOC ## GET LepTess::get_tsv_text ### Description Extracts text in Tab-Separated Values format with detailed information about each recognized element including position, confidence, and text. ### Parameters #### Request Body - **page_number** (int) - Required - The page index to export. ``` -------------------------------- ### LepTess::get_hocr_text Source: https://context7.com/houqp/leptess/llms.txt Extracts text with bounding box information in hOCR HTML format. ```APIDOC ## GET LepTess::get_hocr_text ### Description Extracts text with bounding box information in hOCR format, an HTML-based standard for representing OCR output with positional data. ### Parameters #### Request Body - **page_number** (int) - Required - The page index to export. ``` -------------------------------- ### Extract Recognized Text Source: https://context7.com/houqp/leptess/llms.txt Retrieves text from the current image or defined region. By default, it processes the entire image unless a rectangle is set. ```rust use leptess::LepTess; fn main() -> Result<(), Box> { let mut lt = LepTess::new(Some("./tests/tessdata"), "eng")?; lt.set_image("./tests/di.png")?; // Get full page text let full_text = lt.get_utf8_text()?; println!("Full page:\n{}", full_text); // Restrict to specific region and get text lt.set_rectangle(10, 10, 200, 60); let region_text = lt.get_utf8_text()?; println!("Region text:\n{}", region_text); Ok(()) } ``` -------------------------------- ### Export OCR Results as hOCR HTML with LepTess Source: https://context7.com/houqp/leptess/llms.txt Extracts OCR results in hOCR format, which includes text and bounding box information in an HTML structure. Specify the page number for extraction. ```rust use leptess::LepTess; fn main() -> Result<(), Box> { let mut lt = LepTess::new(Some("./tests/tessdata"), "eng")?; lt.set_image("./tests/di.png")?; // Get hOCR output for page 0 let hocr = lt.get_hocr_text(0)?; println!("{}", hocr); Ok(()) } ``` -------------------------------- ### LepTess::set_rectangle - Restrict OCR Region Source: https://context7.com/houqp/leptess/llms.txt Restricts OCR to a specific rectangular region of the image. ```APIDOC ## LepTess::set_rectangle ### Description Restricts OCR to a specific rectangular region of the image defined by left, top, width, and height in pixels. ### Parameters #### Request Body - **left** (i32) - Required - Left coordinate. - **top** (i32) - Required - Top coordinate. - **width** (i32) - Required - Width of the rectangle. - **height** (i32) - Required - Height of the rectangle. ``` -------------------------------- ### Restrict OCR to a Rectangle Source: https://context7.com/houqp/leptess/llms.txt Limits the OCR processing area to a specific pixel-defined rectangle. This affects all subsequent calls to text extraction methods. ```rust use leptess::LepTess; fn main() -> Result<(), Box> { let mut lt = LepTess::new(Some("./tests/tessdata"), "eng")?; lt.set_image("./tests/di.png")?; // Define region: left=10, top=10, width=200, height=60 lt.set_rectangle(10, 10, 200, 60); let text = lt.get_utf8_text()?; println!("Text in region: {}", text); Ok(()) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.