Deploying the PP-OCRv5 Model Using C++ on Windows

# PaddleOCRv5 C++ Inference Project Tutorial

## 1. Project Overview

This project is based on PaddleOCR v5, utilizing Paddle Inference and OpenCV to implement text detection and recognition in both Chinese and English, supporting orientation classification, suitable for secondary development and deployment on the Windows platform.

## 2. Environment Preparation

– Operating System: Windows 10/11

– Compiler: Visual Studio 2019 or 2022

– CMake: Recommended version 3.14 or above (e.g., 3.30.1)

– OpenCV: Recommended version 4.9.0 (other 4.x versions are acceptable)

– Paddle Inference: Version 3.0.0 CPU version (included in the project under the paddle_inference-3.0.0-cpu directory)

## 3. Dependency Installation

1. Install Visual Studio 2019/2022 (ensure C++ development components are included).

2. Install CMake (https://cmake.org/download/).

3. Download and extract the OpenCV precompiled package (e.g., https://github.com/opencv/opencv/releases/download/4.9.0/opencv-4.9.0-windows.exe).

4. Ensure the `paddle_inference-3.0.0-cpu` directory exists.

## 4. Model Preparation

Place the following model folders into the `model/` directory:

– `PP-OCRv5_mobile_det`: Text detection model

– `PP-OCRv5_mobile_rec`: Text recognition model

– `ch_ppocr_mobile_v2.0_cls_infer`: Orientation classification model

– `ppocr_keys.txt`: Dictionary file

## 5. Compilation Method

1. Modify the following paths in `CMakeLists.txt` to your local actual paths (ensure there are no Chinese characters or spaces):

“`cmake

SET(PADDLE_LIB “C:\your_path\paddle_inference-3.0.0-cpu”)

SET(OpenCV_DIR “D:\your_path\opencv\build\x64\vc16\lib”)

“`

2. Use CMake to generate the VS project or compile directly:

“`shell

mkdir build

cd build

cmake ..

cmake –build . –config Release

“`

3. After compilation, `ppocr.exe` and the required DLLs will be generated in the `build/Release/` directory.

## 6. Running Method

1. Switch to the `build/Release/` directory.

2. Execute the following command (replace the paths with your actual model and image paths):

“`shell

ppocr.exe \

–det_model_dir=C:\path\model\PP-OCRv5_mobile_det \

–rec_model_dir=C:\path\model\PP-OCRv5_mobile_rec \

–cls_model_dir=C:\path\model\ch_ppocr_mobile_v2.0_cls_infer \

–image_dir=C:\path\2.jpg \

–use_angle_cls=true –det=true –rec=true –cls=true \

–rec_char_dict_path=C:\path\model\ppocr_keys.txt

“`

3. The results will be output in the command line; if `–visualize=true` is enabled, the detection result images will be saved in the directory specified by `–output`.

## 7. Parameter Description

– `–det_model_dir`: Detection model directory

– `–rec_model_dir`: Recognition model directory

– `–cls_model_dir`: Orientation classification model directory

– `–image_dir`: Path or directory of the image to be recognized

– `–rec_char_dict_path`: Path to the dictionary file

– `–use_angle_cls`: Whether to use orientation classification

– `–det`: Whether to enable text detection

– `–rec`: Whether to enable text recognition

– `–cls`: Whether to enable orientation classification

– `–output`: Result output directory (optional)

– For other parameters, see `main.cpp` and the source code comments

Original Image:

Deploying the PP-OCRv5 Model Using C++ on Windows

Recognition Result:

Deploying the PP-OCRv5 Model Using C++ on WindowsDeploying the PP-OCRv5 Model Using C++ on Windows

## 8. Common Issues

– **Paths must not contain Chinese characters or spaces**, as this may cause model loading failures.

– If a DLL is missing, ensure that `paddle_inference.dll`, `common.dll`, `mkldnn.dll`, `libiomp5md.dll`, `mklml.dll`, etc., are present in the `build/Release/` directory.

– OpenCV must match the version used during compilation.

## 9. Secondary Development Guidelines

– The main entry point is `src/main.cpp`, where parameters or calling processes can be modified according to actual needs.

– The core logic of OCR can be found in `src/paddleocr.cpp`, supporting batch image recognition, detection, orientation classification, etc.

– For integration into other projects, refer to the interface of the `PPOCR` class.

Source code address:https://mbd.pub/o/bread/YZWUmJhubA==

Leave a Comment