### Install Dependencies Source: https://github.com/jaidedai/easyocr/blob/master/trainer/craft/README.md Installs all necessary packages for training CRAFT models. Ensure you have a requirements.txt file in your current directory. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install EasyOCR (Development) Source: https://github.com/jaidedai/easyocr/blob/master/README.md Install the latest development release of EasyOCR directly from its GitHub repository. ```bash pip install git+https://github.com/JaidedAI/EasyOCR.git ``` -------------------------------- ### Install EasyOCR (Stable) Source: https://github.com/jaidedai/easyocr/blob/master/README.md Install the latest stable release of EasyOCR using pip. ```bash pip install easyocr ``` -------------------------------- ### Get EasyOCR Installation Path Source: https://github.com/jaidedai/easyocr/blob/master/easyocr/DBNet/README.md Determine the installation directory of the EasyOCR library in Python. ```python > import os > import easyocr > print(os.dirname(easyocr.__file__)) ``` -------------------------------- ### Initialize Training with Configuration Source: https://github.com/jaidedai/easyocr/blob/master/trainer/trainer.ipynb Loads the specified configuration file and starts the EasyOCR training process with automatic mixed precision disabled. ```python opt = get_config("config_files/en_filtered_config.yaml") train(opt, amp=False) ``` -------------------------------- ### EasyOCR Command-Line Interface Examples Source: https://context7.com/jaidedai/easyocr/llms.txt Provides examples of using the EasyOCR command-line interface for various OCR tasks, including language selection, detail modes, and specific configurations. ```bash # Basic usage: English + Simplified Chinese, detail mode easyocr -l en ch_sim -f street_sign.jpg --detail=1 --gpu=True ``` ```bash # CPU-only, simple output (text only) easyocr -l en -f receipt.jpg --detail=0 --gpu=False ``` ```bash # Beam search decoder, batch size 4 easyocr -l en de fr -f document.jpg --decoder=beamsearch --beamWidth=5 --batch_size=4 ``` ```bash # Restrict to digits only easyocr -l en -f invoice.jpg --allowlist=0123456789 ``` ```bash # Paragraph mode with output format JSON easyocr -l en -f article.jpg --paragraph=True --output_format=json ``` ```bash # DBNet18 detector, custom model directory easyocr \ -l en \ -f photo.jpg \ --detect_network=dbnet18 \ --model_storage_directory=/opt/models \ --recog_network=standard \ --gpu=True \ --detail=1 ``` -------------------------------- ### Check Conda Installation Source: https://github.com/jaidedai/easyocr/blob/master/easyocr/DBNet/README.md Verify if conda is installed on your system by checking its version. ```bash > conda --version ``` -------------------------------- ### Train CRAFT with Custom Dataset (Multi-GPU) Source: https://github.com/jaidedai/easyocr/blob/master/trainer/craft/README.md Starts training the CRAFT model using a custom dataset or a combination of SynthText and IC15. This command is for multi-GPU usage. ```bash CUDA_VISIBLE_DEVICES=0,1 python3 train_distributed.py --yaml=custom_data_train ``` -------------------------------- ### Install GCC Compiler (Debian/Ubuntu) Source: https://github.com/jaidedai/easyocr/blob/master/easyocr/DBNet/README.md Install the build-essential package, which includes GCC, on Debian/Ubuntu-based systems. This is a prerequisite for compiling DCN operators. ```bash > apt-get install build-essential ``` ```bash > sudo apt-get install build-essential ``` -------------------------------- ### Train CRAFT with Custom Dataset (Single GPU) Source: https://github.com/jaidedai/easyocr/blob/master/trainer/craft/README.md Starts training the CRAFT model using a custom dataset or a combination of SynthText and IC15. This command is for single GPU usage. ```bash CUDA_VISIBLE_DEVICES=0 python3 train.py --yaml=custom_data_train ``` -------------------------------- ### Verify Docker Prerequisites Source: https://github.com/jaidedai/easyocr/blob/master/easyocr/DBNet/README.md Check if GCC and NVCC (for CUDA) are installed within a Docker image. ```bash gcc --version ``` ```bash nvcc --version ``` -------------------------------- ### Install NVCC and CUDA Toolkit with Conda Source: https://github.com/jaidedai/easyocr/blob/master/easyocr/DBNet/README.md Install NVCC and the CUDA developer toolkit using the conda package manager. This is an alternative method for setting up CUDA prerequisites. ```bash > conda install -c conda-forge cudatoolkit-dev ``` -------------------------------- ### Check GCC Version Source: https://github.com/jaidedai/easyocr/blob/master/easyocr/DBNet/README.md Verify if GCC compiler is installed on your system. This is a prerequisite for compiling DCN operators. ```bash > gcc --version ``` -------------------------------- ### Navigate to DCN Directory Source: https://github.com/jaidedai/easyocr/blob/master/easyocr/DBNet/README.md Change the current directory to the DCN operator source files within the EasyOCR installation. ```bash > cd /home/username/anaconda3/lib/python3.8/site-packages/easyocr/DBNet/assets/ops/dcn ``` -------------------------------- ### OCR Output Format Source: https://github.com/jaidedai/easyocr/blob/master/README.md Example of the detailed output format from EasyOCR, including bounding box coordinates, detected text, and confidence level. ```bash [([[189, 75], [469, 75], [469, 165], [189, 165]], '愚园路', 0.3754989504814148), ([[86, 80], [134, 80], [134, 128], [86, 128]], '西', 0.40452659130096436), ([[517, 81], [565, 81], [565, 123], [517, 123]], '东', 0.9989598989486694), ([[78, 126], [136, 126], [136, 156], [78, 156]], '315', 0.8125889301300049), ([[514, 126], [574, 126], [574, 156], [514, 156]], '309', 0.4971577227115631), ([[226, 170], [414, 170], [414, 220], [226, 220]], 'Yuyuan Rd.', 0.8261902332305908), ([[79, 173], [125, 173], [125, 213], [79, 213]], 'W', 0.9848111271858215), ([[529, 173], [569, 173], [569, 213], [529, 213]], 'E', 0.8405593633651733)] ``` -------------------------------- ### Run EasyOCR Unit Tests with Python Script Source: https://github.com/jaidedai/easyocr/blob/master/unit_test/README.md Execute unit tests for EasyOCR using the provided Python script. Specify the EasyOCR package directory, verbosity level, test data path, and example data directory as arguments. ```bash python ./unit_test/run_unit_test.py --easyocr ./easyocr --verbose 2 --test ./unit_test/EasyOcrUnitTestPackage.pickle --data_dir ./examples ``` -------------------------------- ### Train CRAFT with SynthText Dataset Source: https://github.com/jaidedai/easyocr/blob/master/trainer/craft/README.md Initiates training for the CRAFT model using the SynthText dataset from scratch. This command is for single GPU usage. ```bash CUDA_VISIBLE_DEVICES=0 python3 trainSynth.py --yaml=syn_train ``` -------------------------------- ### Initialize Reader with DBNet Detector Source: https://github.com/jaidedai/easyocr/blob/master/releasenotes.md Use this to initialize the EasyOCR Reader with the DBNet text detector. Currently requires GPU. ```python reader = easyocr.Reader(['en'], detect_network = 'dbnet18') ``` -------------------------------- ### Switch Detection Network at Runtime Source: https://context7.com/jaidedai/easyocr/llms.txt Demonstrates how to switch the detection network (e.g., from 'craft' to 'dbnet18') after a Reader object has been initialized, without needing to re-create the object. ```python import easyocr reader = easyocr.Reader(['en'], detect_network='craft') # Run with CRAFT detector results_craft = reader.readtext('image.jpg') # Switch to DBNet18 detector reader.setDetector('dbnet18') # Run with DBNet18 detector results_db = reader.readtext('image.jpg') ``` -------------------------------- ### Simplified OCR Result Source: https://github.com/jaidedai/easyocr/blob/master/README.md Example of the simplified output format from EasyOCR when `detail=0` is used. ```bash ['愚园路', '西', '东', '315', '309', 'Yuyuan Rd.', 'W', 'E'] ``` -------------------------------- ### Configure test parameters Source: https://github.com/jaidedai/easyocr/blob/master/unit_test/demo.ipynb Sets up paths and variables for the unit test configuration. ```python easyocr_module = "../easyocr" verbose = 2 test_data = "./data/EasyOcrUnitTestPackage.pickle" image_data_dir = "../examples" ``` -------------------------------- ### Load and Process Configuration from YAML Source: https://github.com/jaidedai/easyocr/blob/master/trainer/trainer.ipynb Loads training configuration from a YAML file, processes custom character sets if specified, and creates the experiment directory. ```python def get_config(file_path): with open(file_path, 'r', encoding="utf8") as stream: opt = yaml.safe_load(stream) opt = AttrDict(opt) if opt.lang_char == 'None': characters = '' for data in opt['select_data'].split('-'): csv_path = os.path.join(opt['train_data'], data, 'labels.csv') df = pd.read_csv(csv_path, sep='^([^,]+),', engine='python', usecols=['filename', 'words'], keep_default_na=False) all_char = ''.join(df['words']) characters += ''.join(set(all_char)) characters = sorted(set(characters)) opt.character= ''.join(characters) else: opt.character = opt.number + opt.symbol + opt.lang_char os.makedirs(f'./saved_models/{opt.experiment_name}', exist_ok=True) return opt ``` -------------------------------- ### Simplified OCR Output Source: https://github.com/jaidedai/easyocr/blob/master/README.md Perform OCR with `detail=0` to get a simplified output containing only the detected text strings. ```python reader.readtext('chinese.jpg', detail = 0) ``` -------------------------------- ### Initialize EasyOCR Reader with Custom Models Source: https://github.com/jaidedai/easyocr/blob/master/README.md Instantiate the EasyOCR Reader by specifying the desired languages and optionally custom detection and recognition models. This allows for flexible configuration of OCR pipelines. ```python reader = easyocr.Reader(['en'], detection='DB', recognition = 'Transformer') ``` -------------------------------- ### Initialize the UnitTest object Source: https://github.com/jaidedai/easyocr/blob/master/unit_test/demo.ipynb Creates an instance of the UnitTest class with specified paths and directories. ```python unit_test = UnitTest(easyocr_module, test_data, image_data_dir ) ``` -------------------------------- ### Check CUDA and NVCC Version Source: https://github.com/jaidedai/easyocr/blob/master/easyocr/DBNet/README.md Verify if NVCC and CUDA toolkit are installed on your system. This is a prerequisite for compiling the CUDA version of DCN operators. ```bash > nvcc --version ``` -------------------------------- ### Initialize Reader with Multiple Languages Source: https://context7.com/jaidedai/easyocr/llms.txt Demonstrates initializing the EasyOCR Reader with different language groups. The library automatically selects the appropriate pretrained models based on the provided ISO 639 language codes. ```python import easyocr # Latin script: af az bs cs cy da de en es et fr ga hr hu id is it ku la lt lv # mi ms mt nl no oc pi pl pt ro rs_latin sk sl sq sv sw tl tr uz vi reader = easyocr.Reader(['en', 'de', 'fr']) # Arabic script: ar fa ug ur reader = easyocr.Reader(['ar', 'en']) # Cyrillic: ru rs_cyrillic be bg uk mn (+ minority languages) reader = easyocr.Reader(['ru', 'en']) # Devanagari: hi mr ne bh mai ang bho mah sck new gom sa bgc reader = easyocr.Reader(['hi', 'en']) ``` -------------------------------- ### Initialize Reader with Specific Recognition Model Source: https://github.com/jaidedai/easyocr/blob/master/releasenotes.md Specify a particular recognition model when initializing the EasyOCR Reader. For example, to use the 1st generation Latin model. ```python reader = easyocr.Reader(['en','fr'], recog_network = 'latin_g1') ``` -------------------------------- ### Initialize EasyOCR Reader with Bengali and English Source: https://context7.com/jaidedai/easyocr/llms.txt Instantiate the EasyOCR Reader with a list of desired languages. English is compatible with all languages. ```python reader = easyocr.Reader(['bn', 'en']) ``` -------------------------------- ### Handle incompatible language combinations in EasyOCR Source: https://context7.com/jaidedai/easyocr/llms.txt Scripts incompatible with each other cannot be mixed in one Reader. For example, Chinese and Arabic will raise a ValueError. This snippet demonstrates how to catch and print the error. ```python try: reader = easyocr.Reader(['ch_sim', 'ar']) # Raises ValueError except ValueError as e: print(e) ``` -------------------------------- ### Initialize EasyOCR Reader with CJK and other scripts Source: https://context7.com/jaidedai/easyocr/llms.txt Instantiate the EasyOCR Reader with various scripts like Simplified Chinese, Traditional Chinese, Japanese, Korean, Thai, Tamil, Telugu, and Kannada, along with English. ```python reader = easyocr.Reader(['ch_sim', 'en']) # Simplified Chinese ``` ```python reader = easyocr.Reader(['ch_tra', 'en']) # Traditional Chinese ``` ```python reader = easyocr.Reader(['ja', 'en']) # Japanese ``` ```python reader = easyocr.Reader(['ko', 'en']) # Korean ``` ```python reader = easyocr.Reader(['th', 'en']) # Thai ``` ```python reader = easyocr.Reader(['ta', 'en']) # Tamil ``` ```python reader = easyocr.Reader(['te', 'en']) # Telugu ``` ```python reader = easyocr.Reader(['kn', 'en']) # Kannada ``` -------------------------------- ### Basic OCR Usage Source: https://github.com/jaidedai/easyocr/blob/master/README.md Initialize the EasyOCR Reader with desired languages and perform text recognition on an image. The Reader initialization loads models into memory and should be done once. ```python import easyocr reader = easyocr.Reader(['ch_sim','en']) # this needs to run only once to load the model into memory result = reader.readtext('chinese.jpg') ``` -------------------------------- ### EasyOCR Command Line Usage Source: https://github.com/jaidedai/easyocr/blob/master/README.md Execute EasyOCR from the command line, specifying languages, input file, detail level, and GPU usage. ```shell $ easyocr -l ch_sim en -f chinese.jpg --detail=1 --gpu=True ``` -------------------------------- ### Initialize EasyOCR Reader Source: https://context7.com/jaidedai/easyocr/llms.txt Initialize the OCR engine by loading text detector and recognition models. Reuse the same `Reader` instance for multiple calls. Supports various configurations for language, GPU usage, model storage, and network types. ```python import easyocr # Basic: English only, GPU enabled (auto-detects CUDA or MPS) reader = easyocr.Reader(['en']) ``` ```python # Multi-language: Simplified Chinese + English, CPU only reader = easyocr.Reader(['ch_sim', 'en'], gpu=False) ``` ```python # Custom model storage path, no auto-download reader = easyocr.Reader( lang_list=['en', 'de', 'fr'], gpu=True, model_storage_directory='/opt/ocr_models', download_enabled=True, detect_network='craft', # 'craft' (default) or 'dbnet18' recog_network='standard', # 'standard' or a custom model name quantize=True, # dynamic quantization on CPU cudnn_benchmark=False, verbose=True ) ``` ```python # Custom recognition model (requires yourmodel.pth, .yaml, .py in user_network_directory) reader = easyocr.Reader( lang_list=['en'], user_network_directory='~/.EasyOCR/user_network', recog_network='custom_example' ) ``` -------------------------------- ### Integrate Custom Recognition Model Source: https://context7.com/jaidedai/easyocr/llms.txt Shows how to integrate a custom recognition model by specifying the directories for model weights and user network definitions. Ensure the 'recog_network' matches the model's filename stem. ```python # File layout (example: ~/.EasyOCR/): # model/my_model.pth ← trained weights # user_network/my_model.py ← network class definition # user_network/my_model.yaml ← configuration # Example my_model.yaml: # lang_list: ['en'] # character_list: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" # imgH: 64 # network_params: # input_channel: 1 # output_channel: 256 # hidden_size: 256 import easyocr reader = easyocr.Reader( lang_list=['en'], model_storage_directory='~/.EasyOCR/model', user_network_directory='~/.EasyOCR/user_network', recog_network='my_model', # matches the filename stem download_enabled=False # weights are already local ) result = reader.readtext('test_image.jpg', detail=1) for bbox, text, conf in result: print(f"{text!r} conf={conf:.3f}") ```