### Install PyTesseract from Source Source: https://pypi.org/project/pytesseract Install pytesseract from source by cloning the repository and then running the pip install command. This method allows for local modifications or development. ```bash git clone https://github.com/madmaze/pytesseract.git cd pytesseract && pip install -U . ``` -------------------------------- ### Install PyTesseract from GitHub Source: https://pypi.org/project/pytesseract Install or upgrade pytesseract directly from its GitHub repository using pip. This is useful for installing the latest development version. ```bash pip install -U git+https://github.com/madmaze/pytesseract.git ``` -------------------------------- ### Install pytesseract-api Source: https://pypi.org/project/pytesseract-api Install the package using pip. This is the standard method for adding Python packages to your project. ```bash pip install pytesseract-api ``` -------------------------------- ### Install PyTesseract via Pip Source: https://pypi.org/project/pytesseract Install the pytesseract package using pip. This is the standard method for installing Python packages. ```bash pip install pytesseract ``` -------------------------------- ### Get Available Languages Source: https://pypi.org/project/pytesseract Retrieves a list of languages supported by the Tesseract installation. ```python # List of available languages print(pytesseract.get_languages(config='')) ``` -------------------------------- ### Run PyTesseract Tests with Tox Source: https://pypi.org/project/pytesseract Install and run the project's test suite using tox. Ensure that Tesseract OCR is installed and accessible in your system's PATH. ```bash pip install tox tox ``` -------------------------------- ### Install pytesseract-cli Source: https://pypi.org/project/pytesseract-cli Use this command to install the latest version of pytesseract-cli using pip. ```bash pip install pytesseract-cli ``` -------------------------------- ### Install PyTesseract with Conda Source: https://pypi.org/project/pytesseract Install pytesseract using the conda package manager from the conda-forge channel. This is an alternative installation method for users managing environments with conda. ```bash conda install -c conda-forge pytesseract ``` -------------------------------- ### get_tesseract_version Source: https://pypi.org/project/pytesseract Returns the Tesseract version installed in the system. ```APIDOC ## get_tesseract_version ### Description Returns the Tesseract version installed in the system. ### Method `get_tesseract_version()` ### Parameters None ### Response - **version** (str) - The installed Tesseract version string. ``` -------------------------------- ### Get Orientation and Script Detection Source: https://pypi.org/project/pytesseract Analyzes the image to detect text orientation and script. ```python # Get information about orientation and script detection print(pytesseract.image_to_osd(Image.open('test.png'))) ``` -------------------------------- ### Get Bounding Boxes Source: https://pypi.org/project/pytesseract Extracts bounding box coordinates for each character in the image. ```python # Get bounding box estimates print(pytesseract.image_to_boxes(Image.open('test.png'))) ``` -------------------------------- ### Get Detailed OCR Data Source: https://pypi.org/project/pytesseract Retrieves verbose OCR data, including bounding boxes, confidences, and line/page numbers. ```python # Get verbose data including boxes, confidences, line and page numbers print(pytesseract.image_to_data(Image.open('test.png'))) ``` -------------------------------- ### pytesseract-cli Usage Help Source: https://pypi.org/project/pytesseract-cli This command displays the help message for pytesseract-cli, outlining all available options and arguments. ```bash pytesseract-cli usage: pytesseract-cli [-h] [-f [FILES ...]] [-d [DIRECTORIES ...]] [-r] [-t {pdf,txt}] [-l LANG] [--list-languages] optional arguments: -h, --help show this help message and exit -f [FILES ...] name(s) of file(s) to process -d [DIRECTORIES ...] directory(s) to process -r recurse on all directories listed -t {pdf,txt} desired output filetype -l LANG language of the text in any image(s) --list-languages list all languages available ``` -------------------------------- ### Run Tesseract OCR with Custom Config File Source: https://pypi.org/project/pytesseract Use a pre-defined configuration file for Tesseract OCR. Ensure the config file exists and is accessible. ```python cfg_filename = 'words' pytesseract.run_and_get_output(image, extension='txt', config=cfg_filename) ``` -------------------------------- ### Basic OCR Usage with pytesseract-api Source: https://pypi.org/project/pytesseract-api Demonstrates how to perform OCR on an image using pytesseract-api. Requires OpenCV for image loading. Ensure you have 'sample.png' in your working directory. ```python import cv2 from pytesseract_api import image_to_string img = cv2.imread("sample.png") text = image_to_string(img) print(text) ``` -------------------------------- ### run_and_get_multiple_output Source: https://pypi.org/project/pytesseract Returns raw output for multiple extensions from a single Tesseract call. ```APIDOC ## run_and_get_multiple_output ### Description Returns raw output for multiple extensions from a single Tesseract call. This function replaces the `extension: str` kwarg with `extension: List[str]` where a list of extensions can be specified and the corresponding data is returned after only one tesseract call. This function reduces the number of calls to tesseract when multiple output formats, like both text and bounding boxes, are needed. ### Method `run_and_get_multiple_output(image, extension: List[str], config='', nice=0, timeout=0)` ### Parameters - **image** (Object or String) - either PIL Image, NumPy array or file path of the image to be processed by Tesseract. If you pass object instead of file path, pytesseract will implicitly convert the image to RGB mode. - **extension** (List[str]) - A list of file extensions for the desired output formats. - **config** (String, optional) - Any additional custom configuration flags that are not available via the pytesseract function. For example: config='--psm 6' - **nice** (Integer, optional) - Modifies the processor priority for the Tesseract run. Not supported on Windows. Nice adjusts the niceness of unix-like processes. - **timeout** (Integer or Float, optional) - Duration in seconds for the OCR processing, after which, pytesseract will terminate and raise RuntimeError. ### Response - **multiple_outputs** (Dict[str, str]) - A dictionary where keys are the requested extensions and values are the corresponding raw outputs. ``` -------------------------------- ### Generate Searchable PDF Source: https://pypi.org/project/pytesseract Creates a searchable PDF file from an image. The output is in bytes and needs to be written to a file. ```python # Get a searchable PDF pdf = pytesseract.image_to_pdf_or_hocr('test.png', extension='pdf') with open('test.pdf', 'w+b') as f: f.write(pdf) # pdf type is bytes by default ``` -------------------------------- ### Configure Tesseract Tessdata Directory Source: https://pypi.org/project/pytesseract Add custom configuration to specify the Tesseract tessdata directory, useful for resolving 'Error opening data file' issues. Replace the placeholder with your actual tessdata directory path and ensure it is enclosed in double quotes. ```python # Example config: r'--tessdata-dir "C:\Program Files (x86)\Tesseract-OCR\tessdata"' tessdata_dir_config = r'--tessdata-dir ""' pytesseract.image_to_string(image, lang='chi_sim', config=tessdata_dir_config) ``` -------------------------------- ### Multiple Output Formats Source: https://pypi.org/project/pytesseract Retrieves multiple output formats (e.g., text, bounding boxes) in a single call to optimize performance. ```python # getting multiple types of output with one call to save compute time # currently supports mix and match of the following: txt, pdf, hocr, box, tsv text, boxes = pytesseract.run_and_get_multiple_output('test.png', extensions=['txt', 'box']) ``` -------------------------------- ### run_and_get_output Source: https://pypi.org/project/pytesseract Returns the raw output from Tesseract OCR. Gives a bit more control over the parameters that are sent to tesseract. ```APIDOC ## run_and_get_output ### Description Returns the raw output from Tesseract OCR. Gives a bit more control over the parameters that are sent to tesseract. ### Method `run_and_get_output(image, extension='txt', config='', nice=0, timeout=0)` ### Parameters - **image** (Object or String) - either PIL Image, NumPy array or file path of the image to be processed by Tesseract. If you pass object instead of file path, pytesseract will implicitly convert the image to RGB mode. - **extension** (String, optional) - The file extension for the output format. Defaults to 'txt'. - **config** (String, optional) - Any additional custom configuration flags that are not available via the pytesseract function. For example: config='--psm 6' - **nice** (Integer, optional) - Modifies the processor priority for the Tesseract run. Not supported on Windows. Nice adjusts the niceness of unix-like processes. - **timeout** (Integer or Float, optional) - Duration in seconds for the OCR processing, after which, pytesseract will terminate and raise RuntimeError. ### Response - **raw_output** (str) - The raw output from Tesseract OCR. ``` -------------------------------- ### image_to_osd Source: https://pypi.org/project/pytesseract Returns result containing information about orientation and script detection. ```APIDOC ## image_to_osd ### Description Returns result containing information about orientation and script detection. ### Method `image_to_osd(image, lang='eng', config='', nice=0, output_type=Output.STRING, timeout=0)` ### Parameters - **image** (Object or String) - either PIL Image, NumPy array or file path of the image to be processed by Tesseract. If you pass object instead of file path, pytesseract will implicitly convert the image to RGB mode. - **lang** (String, optional) - Tesseract language code string. Defaults to eng if not specified. Example for multiple languages: lang='eng+fra' - **config** (String, optional) - Any additional custom configuration flags that are not available via the pytesseract function. For example: config='--psm 6' - **nice** (Integer, optional) - Modifies the processor priority for the Tesseract run. Not supported on Windows. Nice adjusts the niceness of unix-like processes. - **output_type** (Class attribute, optional) - Specifies the type of the output, defaults to string. For the full list of all supported types, please check the definition of pytesseract.Output class. - **timeout** (Integer or Float, optional) - Duration in seconds for the OCR processing, after which, pytesseract will terminate and raise RuntimeError. ### Response - **osd_info** (str or other types based on output_type) - Information about orientation and script detection. ``` -------------------------------- ### image_to_alto_xml Source: https://pypi.org/project/pytesseract Returns result in the form of Tesseract’s ALTO XML format. ```APIDOC ## image_to_alto_xml ### Description Returns result in the form of Tesseract’s ALTO XML format. ### Method `image_to_alto_xml(image, lang='eng', config='', nice=0, output_type=Output.STRING, timeout=0)` ### Parameters - **image** (Object or String) - either PIL Image, NumPy array or file path of the image to be processed by Tesseract. If you pass object instead of file path, pytesseract will implicitly convert the image to RGB mode. - **lang** (String, optional) - Tesseract language code string. Defaults to eng if not specified. Example for multiple languages: lang='eng+fra' - **config** (String, optional) - Any additional custom configuration flags that are not available via the pytesseract function. For example: config='--psm 6' - **nice** (Integer, optional) - Modifies the processor priority for the Tesseract run. Not supported on Windows. Nice adjusts the niceness of unix-like processes. - **output_type** (Class attribute, optional) - Specifies the type of the output, defaults to string. For the full list of all supported types, please check the definition of pytesseract.Output class. - **timeout** (Integer or Float, optional) - Duration in seconds for the OCR processing, after which, pytesseract will terminate and raise RuntimeError. ### Response - **alto_xml** (str or other types based on output_type) - The ALTO XML representation of the OCR result. ``` -------------------------------- ### Basic Image to String Conversion Source: https://pypi.org/project/pytesseract Converts an image file to a string using Tesseract OCR. Ensure the tesseract executable is in your PATH or specify its location. ```python from PIL import Image import pytesseract # If you don't have tesseract executable in your PATH, include the following: pytesseract.pytesseract.tesseract_cmd = r'' # Example tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract' # Simple image to string print(pytesseract.image_to_string(Image.open('test.png'))) ``` ```python # In order to bypass the image conversions of pytesseract, just use relative or absolute image path # NOTE: In this case you should provide tesseract supported images or tesseract will return error print(pytesseract.image_to_string('test.png')) ``` -------------------------------- ### OCR with Character Whitelist Source: https://pypi.org/project/pytesseract-api Shows how to use pytesseract-api to extract only digits from an image by setting a character whitelist. Remember to reset the whitelist after use. Requires OpenCV for image loading and 'digits.png' in your working directory. ```python import cv2 from pytesseract_api.api import set_variable from pytesseract_api import image_to_string img = cv2.imread("digits.png") set_variable("tessedit_char_whitelist", "0123456789") text = image_to_string(img) set_variable("tessedit_char_whitelist", "") # reset ``` -------------------------------- ### OpenCV Image Support Source: https://pypi.org/project/pytesseract Processes images loaded with OpenCV. Requires conversion from BGR to RGB format as pytesseract assumes RGB. ```python import cv2 img_cv = cv2.imread(r'//digits.png') # By default OpenCV stores images in BGR format and since pytesseract assumes RGB format, # we need to convert from BGR to RGB format/mode: img_rgb = cv2.cvtColor(img_cv, cv2.COLOR_BGR2RGB) print(pytesseract.image_to_string(img_rgb)) # OR img_rgb = Image.frombytes('RGB', img_cv.shape[:2], img_cv, 'raw', 'BGR', 0, 0) print(pytesseract.image_to_string(img_rgb)) ``` -------------------------------- ### Custom Tesseract Configuration Source: https://pypi.org/project/pytesseract Applies custom Tesseract configurations, such as OCR Engine Mode (OEM) and Page Segmentation Mode (PSM), using the `config` keyword. ```python # Example of adding any additional options custom_oem_psm_config = r'--oem 3 --psm 6' pytesseract.image_to_string(image, config=custom_oem_psm_config) ``` -------------------------------- ### Upgrade pytesseract-cli Source: https://pypi.org/project/pytesseract-cli Use this command to upgrade to the latest version of pytesseract-cli using pip. ```bash pip install -U pytesseract-cli ``` -------------------------------- ### Generate ALTO XML Output Source: https://pypi.org/project/pytesseract Generates ALTO XML output from an image. ```python # Get ALTO XML output xml = pytesseract.image_to_alto_xml('test.png') ``` -------------------------------- ### image_to_boxes Source: https://pypi.org/project/pytesseract Returns result containing recognized characters and their box boundaries. ```APIDOC ## image_to_boxes ### Description Returns result containing recognized characters and their box boundaries. ### Method `image_to_boxes(image, lang=None, config='', nice=0, output_type=Output.STRING, timeout=0)` ### Parameters - **image** (Object or String) - either PIL Image, NumPy array or file path of the image to be processed by Tesseract. If you pass object instead of file path, pytesseract will implicitly convert the image to RGB mode. - **lang** (String, optional) - Tesseract language code string. Defaults to eng if not specified. Example for multiple languages: lang='eng+fra' - **config** (String, optional) - Any additional custom configuration flags that are not available via the pytesseract function. For example: config='--psm 6' - **nice** (Integer, optional) - Modifies the processor priority for the Tesseract run. Not supported on Windows. Nice adjusts the niceness of unix-like processes. - **output_type** (Class attribute, optional) - Specifies the type of the output, defaults to string. For the full list of all supported types, please check the definition of pytesseract.Output class. - **timeout** (Integer or Float, optional) - Duration in seconds for the OCR processing, after which, pytesseract will terminate and raise RuntimeError. ### Response - **boxes** (str or other types based on output_type) - The recognized characters and their box boundaries. ``` -------------------------------- ### image_to_string Source: https://pypi.org/project/pytesseract Returns unmodified output as string from Tesseract OCR processing. ```APIDOC ## image_to_string ### Description Returns unmodified output as string from Tesseract OCR processing. ### Method `image_to_string(image, lang=None, config='', nice=0, output_type=Output.STRING, timeout=0)` ### Parameters - **image** (Object or String) - either PIL Image, NumPy array or file path of the image to be processed by Tesseract. If you pass object instead of file path, pytesseract will implicitly convert the image to RGB mode. - **lang** (String, optional) - Tesseract language code string. Defaults to eng if not specified. Example for multiple languages: lang='eng+fra' - **config** (String, optional) - Any additional custom configuration flags that are not available via the pytesseract function. For example: config='--psm 6' - **nice** (Integer, optional) - Modifies the processor priority for the Tesseract run. Not supported on Windows. Nice adjusts the niceness of unix-like processes. - **output_type** (Class attribute, optional) - Specifies the type of the output, defaults to string. For the full list of all supported types, please check the definition of pytesseract.Output class. - **timeout** (Integer or Float, optional) - Duration in seconds for the OCR processing, after which, pytesseract will terminate and raise RuntimeError. ### Response - **text** (str) - The OCR'd text from the image. ``` -------------------------------- ### OCR with Timeout Source: https://pypi.org/project/pytesseract Sets a timeout for the Tesseract OCR process to prevent indefinite execution. Catches `RuntimeError` if the timeout is reached. ```python # Timeout/terminate the tesseract job after a period of time try: print(pytesseract.image_to_string('test.jpg', timeout=2)) # Timeout after 2 seconds print(pytesseract.image_to_string('test.jpg', timeout=0.5)) # Timeout after half a second except RuntimeError as timeout_error: # Tesseract processing is terminated pass ``` -------------------------------- ### image_to_data Source: https://pypi.org/project/pytesseract Returns result containing box boundaries, confidences, and other information. Requires Tesseract 3.05+. ```APIDOC ## image_to_data ### Description Returns result containing box boundaries, confidences, and other information. Requires Tesseract 3.05+. For more information, please check the Tesseract TSV documentation. ### Method `image_to_data(image, lang=None, config='', nice=0, output_type=Output.STRING, timeout=0, pandas_config=None)` ### Parameters - **image** (Object or String) - either PIL Image, NumPy array or file path of the image to be processed by Tesseract. If you pass object instead of file path, pytesseract will implicitly convert the image to RGB mode. - **lang** (String, optional) - Tesseract language code string. Defaults to eng if not specified. Example for multiple languages: lang='eng+fra' - **config** (String, optional) - Any additional custom configuration flags that are not available via the pytesseract function. For example: config='--psm 6' - **nice** (Integer, optional) - Modifies the processor priority for the Tesseract run. Not supported on Windows. Nice adjusts the niceness of unix-like processes. - **output_type** (Class attribute, optional) - Specifies the type of the output, defaults to string. For the full list of all supported types, please check the definition of pytesseract.Output class. - **timeout** (Integer or Float, optional) - Duration in seconds for the OCR processing, after which, pytesseract will terminate and raise RuntimeError. - **pandas_config** (Dict, optional) - Only for the Output.DATAFRAME type. Dictionary with custom arguments for pandas.read_csv. Allows you to customize the output of image_to_data. ### Response - **data** (str or pandas.DataFrame) - The result containing box boundaries, confidences, and other information. ``` -------------------------------- ### get_languages Source: https://pypi.org/project/pytesseract Returns all currently supported languages by Tesseract OCR. ```APIDOC ## get_languages ### Description Returns all currently supported languages by Tesseract OCR. ### Method `get_languages()` ### Parameters None ### Response - **languages** (List[str]) - A list of supported language codes. ``` -------------------------------- ### Batch Processing Images Source: https://pypi.org/project/pytesseract Processes multiple images listed in a text file for OCR. ```python # Batch processing with a single file containing the list of multiple image file paths print(pytesseract.image_to_string('images.txt')) ``` -------------------------------- ### Generate HOCR Output Source: https://pypi.org/project/pytesseract Generates HOCR (HTML Object Recognition) output from an image. ```python # Get HOCR output hocr = pytesseract.image_to_pdf_or_hocr('test.png', extension='hocr') ``` -------------------------------- ### OCR with Specific Language Source: https://pypi.org/project/pytesseract Performs OCR on an image, specifying the language for recognition (e.g., French). ```python # French text image to string print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra')) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.