RapidOcrOnnx Documentation

repository·main·Indexed Aug 6, 2026

https://github.com/rapidai/rapidocronnx

An OCR engine utilizing the ONNX Runtime framework for high-performance inference. It supports detection, classification, and recognition tasks using PP-OCR models. The documentation covers installation and configuration for GPU acceleration via CUDA and cuDNN, compilation guides for Windows (nmake and Visual Studio) and macOS, and CLI usage for tuning recognition accuracy and image preprocessing.

Tokens
4.7K
Snippets
10
Records
20
Agent score
62%

What's inside RapidOcrOnnx

  1. Compile RapidOcrOnnx on Windows (nmake)

    main

    Prerequisites

    • Windows 10 x64
    • Visual Studio 2019 (with 'Desktop development with C++' workload installed). Note: OnnxRuntime 1.7.0+ requires VS2019.
    • CMake >= 3.12

    Steps

    1. Open the "x64 Native Tools Command Prompt for VS 2019" (or VS2017 equivalent) from the Start menu.
    2. Navigate to the project root directory.
    3. Run the build script:
      build.bat
    4. Follow the prompts and select BIN可执行文件 (BIN Executable).
    5. To test the build, run:
      run-test.bat
      Note: You must modify the target image path inside the script before running.

    Compile JNI Dynamic Library (Optional for Java integration)

    1. Install JDK 8u221 (ensure 'Source Code' is selected during installation).
    2. Set up environment variables:
      • JAVA_HOME: C:\Program Files\Java\jdk1.8.0_221
      • CLASSPATH: .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;
      • Update Path: Add %JAVA_HOME%\bin to your system Path.
    3. In the "x64 Native Tools Command Prompt", run build.bat and select JNI动态库 (JNI Dynamic Library).
    # Build executable
    build.bat
    
    # Run tests
    run-test.bat
  2. Download third-party dependencies

    main

    RapidOcrOnnx requires OpenCV and ONNX Runtime. Download the pre-built static libraries and extract them into the project root directory.

    OpenCV:

    • Download from OpenCVBuilder releases.
    • Use the static library version: opencv-(version)-platform.7z.
    • On Windows, note the distinction between mt (static CRT linking) and md (dynamic CRT linking) versions.
    • Ensure the directory structure after extraction follows this pattern:
    opencv-static
    ├── OpenCVWrapperConfig.cmake
    ├── linux
    ├── macos
    └── windows-x64 (or windows-x86)

    ONNX Runtime:

    • Download from OnnxruntimeBuilder releases.
    • Use the static library version: onnxruntime-(version)-platform-static.7z.
    • Ensure the directory structure after extraction follows this pattern:
    onnxruntime-static
    ├── OnnxRuntimeWrapper.cmake
    ├── linux
    ├── macos
    └── windows-x64 (or windows-x86)
  3. Configure CUDA and cuDNN for GPU acceleration

    main

    To enable GPU acceleration via the CUDA Execution Provider, ensure your environment meets the specific version requirements for onnxruntime v1.12:

    • Linux: CUDA 11.4 and cuDNN 8.2.4.
    • Windows: CUDA 11.4 and cuDNN 8.2.2.26.

    cuDNN Setup

    • Windows: Unzip the cuDNN DLLs and place them in the same directory as your compiled executable.
    • Linux:
      1. Unzip cuDNN to a directory (e.g., /opt/cudnn).
      2. Add the cuDNN path and your CUDA library path to LD_LIBRARY_PATH.

    CUDA Setup

    • Download from NVIDIA CUDA Downloads.
    • During installation, you can select only the Development and Runtime components under the CUDA section to minimize installation size.
    # Linux: Add cuDNN and CUDA to LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/cudnn:/usr/local/cuda-11.4/lib64
    
    # Alternatively, add paths to /etc/ld.so.conf and run ldconfig as root
  4. Download RapidOcrOnnx binaries and libraries

    main

    RapidOcrOnnx provides pre-compiled binaries and libraries for various platforms and integration types. You can find these in the GitHub Releases section or the project's QQ group.

    Available Packages:

    • Executables (Demos): linux-bin.7z, macos-bin.7z, windows-bin.7z
    • Java JNI Libraries: linux-jni.7z, macos-jni.7z, windows-jni.7z
    • C Dynamic Libraries (Shared): linux-clib.7z, macos-clib.7z, windows-clib.7z

    Note: The Linux binaries are compiled on Ubuntu 18.04. If your Linux distribution is incompatible, you must compile from source.

  5. Compile RapidOcrOnnx on Linux

    main

    Prerequisites

    • Ubuntu 18.04 LTS (or other distributions if you manually compile/adapt OpenCV and ONNX Runtime).
    • build-essential (install via sudo apt-get install build-essential).
    • g++ >= 5
    • CMake >= 3.17

    Steps

    1. Open a terminal in the project root.
    2. Run the build script:
      ./build.sh
    3. Follow the prompts and select BIN可执行文件 (BIN Executable).
    4. To test, run:
      ./run-test.sh
      Note: Modify the target image path inside the script before running.

    Compile JNI Dynamic Library (Optional)

    1. Install and configure JDK 8u221.
    2. Run ./build.sh and select JNI动态库 (JNI Dynamic Library).
    3. Requirement: For JNI compilation, g++ version must be >= 6.

    Deployment

    If using dynamic libraries, either:

    • Add the library path to LD_LIBRARY_PATH.
    • Copy or link the libraries to /usr/lib.
    # Build executable
    ./build.sh
    
    # Run tests
    ./run-test.sh
  6. Use the RapidOcrOnnx JVM wrapper

    main

    The rapidocronnx repository contains the core C++ implementation. If you are a Java or Kotlin developer looking to use this library, you should use the RapidOcrOnnxJvm project instead. This project provides the JNI (Java Native Interface) bindings required to call the OCR engine from a JVM environment.

    Refer to the following repository for instructions on how to integrate RapidOcrOnnx into your Java/Kotlin applications: https://github.com/RapidAI/RapidOcrOnnxJvm

  7. Debug RapidOcrOnnx on Windows (Visual Studio)

    main

    To debug the project using Visual Studio, you cannot use the Release libraries provided in the standard demo. You must use Debug (md) libraries.

    1. Replace the existing libraries in your project folder with the Debug version (which must be md type).
    2. Run generate-vs-project.bat and select option 2)Debug to generate the build folder.
    3. Open the generated RapidOcrOnnx.sln.
    4. Right-click the RapidOcrOnnx project in Solution Explorer and select Set as Startup Project.
    5. If using DLLs, copy the required DLLs (e.g., onnxruntime.dll) into the build-win-vsxxx-xx\Debug folder alongside the .exe.
    6. Set the Command Arguments in Project Properties -> Debugging: --models ../models --det ch_PP-OCRv3_det_infer.onnx --cls ch_ppocr_mobile_v2.0_cls_infer.onnx --rec ch_PP-OCRv3_rec_infer.onnx --keys ppocr_keys_v1.txt --image ../images/1.jpg
    7. Start the local Windows debugger.
  8. Run tests and benchmarks

    main

    After downloading and extracting the appropriate package for your system, you can verify the installation and performance using the provided scripts:

    • To view recognition results: Run run-test.sh (Linux/macOS) or run-test.bat (Windows).
    • To view average processing time (benchmarking): Run run-benchmark.sh (Linux/macOS) or run-benchmark.bat (Windows).
    # Linux/macOS
    ./run-test.sh
    ./run-benchmark.sh
    
    # Windows
    run-test.bat
    run-benchmark.bat
  9. Download and organize onnxruntime-gpu libraries

    main

    To use the GPU version of RapidOcrOnnx, you must manually download and structure the onnxruntime-gpu libraries.

    Requirements:

    • Supported platforms: Linux and Windows (x64 only).
    • Download from: onnxruntime releases.
    • Windows package: onnxruntime-win-x64-gpu-<version>.zip.
    • Linux package: onnxruntime-linux-x64-gpu-<version>.tgz.

    Setup Instructions:

    For Windows:

    1. Unzip the lib folder from the package into a directory named windows-x64.
    2. Create the directory path include/onnxruntime/core/session inside windows-x64.
    3. Unzip all .h files from the package into that session folder.

    For Linux:

    1. Unzip the lib folder from the package into a directory named linux.
    2. Create the directory path include/onnxruntime/core/session inside linux.
    3. Unzip all .h files from the package into that session folder.
    # Target Directory Structure
    
    onnxruntime-gpu
    ├── linux
    │   ├── include
    │   │   └── onnxruntime
    │   │       └── core
    │   │           └── session
    │   │               ├── onnxruntime_c_api.h
    │   │               └── ...
    │   └── lib
    │       ├── libonnxruntime.so
    │       └── ...
    └── windows-x64
        ├── include
        │   └── onnxruntime
        │       └── core
        │           └── session
        │               ├── onnxruntime_c_api.h
        │               └── ...
        └── lib
            ├── onnxruntime.dll
            └── ...
  10. Run RapidOcrOnnx tests and benchmarks

    main

    To verify your installation and measure performance, follow these steps:

    1. Download and extract the appropriate package for your system (e.g., windows-bin.7z).
    2. Download the required models and extract them into the models folder within the extracted directory.
    3. To check recognition results: Run run-test.sh (Linux/macOS) or run-test.bat (Windows).
    4. To check average processing time: Run run-benchmark.sh (Linux/macOS) or run-benchmark.bat (Windows).