PPOCR
PP-OCR is a flexible OCR solution that supports both standalone detection/recognition modules and end-to-end system integration. This example demonstrates how to deploy and run this high-performance text recognition pipeline ("image in, text out") using Rockchip platform compute resources.
Environment Setup
Follow RKNN Installation to set up the environment.
Follow RKNN Model Zoo to download the example files.
Model Download
Download the ONNX model file.
cd rknn_model_zoo/examples/PPOCR/PPOCR-Det/model/
bash download_model.sh
cd ../../PPOCR-Rec/model/
bash download_model.sh
Model Conversion
Select the target platform.
- rk3588
- rk356x
- rk3576
export TARGET_PLATFORM=rk3588
export TARGET_PLATFORM=rk356x
export TARGET_PLATFORM=rk3576
Convert the ONNX model to an RKNN model.
cd ../python
python convert.py ../model/ppocrv4_rec.onnx ${TARGET_PLATFORM}
cd ../../PPOCR-Det/python/
python convert.py ../model/ppocrv4_det.onnx ${TARGET_PLATFORM}
Copy the converted models to the PPOCR-System/model directory.
cd ../../PPOCR-System/model/
cp ../../PPOCR-Det/model/ppocrv4_det.rknn ./
cp ../../PPOCR-Rec/model/ppocrv4_rec.rknn ./
C API
Build the Example
Go to the rknn_model_zoo directory and run build-linux.sh to build.
cd ../../../..
bash build-linux.sh -t ${TARGET_PLATFORM} -a aarch64 -d PPOCR-System
Sync Files to the Device
Copy the built demo directory under the install folder to the device.
cd install/${TARGET_PLATFORM}_linux_aarch64/
scp -r rknn_PPOCR-System_demo/ user@your_device_ip:target_directory
Run the Example
Export the runtime libraries to the environment variable.
cd rknn_PPOCR-System_demo
export LD_LIBRARY_PATH=./lib
Run the example.
./rknn_ppocr_system_demo ./model/ppocrv4_det.rknn ./model/ppocrv4_rec.rknn ./model/test.jpg
$ ./rknn_ppocr_system_demo ./model/ppocrv4_det.rknn ./model/ppocrv4_rec.rknn ./model/test.jpg
model input num: 1, output num: 1
input tensors:
index=0, name=x, n_dims=4, dims=[1, 480, 480, 3], n_elems=691200, size=691200, fmt=NHWC, type=INT8, qnt_type=AFFINE, zp=-14, scale=0.018658
output tensors:
index=0, name=sigmoid_0.tmp_0, n_dims=4, dims=[1, 1, 480, 480], n_elems=230400, size=230400, fmt=NCHW, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
model is NHWC input fmt
model input height=480, width=480, channel=3
model input num: 1, output num: 1
input tensors:
index=0, name=x, n_dims=4, dims=[1, 48, 320, 3], n_elems=46080, size=92160, fmt=NHWC, type=FP16, qnt_type=AFFINE, zp=0, scale=1.000000
output tensors:
index=0, name=softmax_11.tmp_0, n_dims=3, dims=[1, 40, 6625, 0], n_elems=265000, size=530000, fmt=UNDEFINED, type=FP16, qnt_type=AFFINE, zp=0, scale=1.000000
model is NHWC input fmt
model input height=48, width=320, channel=3
origin size=500x500 crop size=496x496
input image: 500 x 500, subsampling: 4:4:4, colorspace: YCbCr, orientation: 1
src width is not 4/16-aligned, convert image use cpu
finish
DRAWING OBJECT
[0] @ [(28, 37), (302, 39), (301, 71), (27, 69)]
recognize result: Nourishing Hair Conditioner, score=0.711077
[1] @ [(26, 82), (172, 82), (172, 104), (26, 104)]
recognize result: Product Information/Parameters, score=0.709612
[2] @ [(27, 112), (332, 112), (332, 134), (27, 134)]
recognize result: (45 CNY/kg, minimum order: 100 kg), score=0.691406
[3] @ [(28, 142), (282, 144), (281, 163), (27, 162)]
recognize result: 22 CNY per bottle, minimum order: 1000 bottles), score=0.706613
[4] @ [(25, 179), (298, 177), (300, 194), (26, 195)]
recognize result: [Brand]: Contract Manufacturing / OEM ODM, score=0.704963
[5] @ [(26, 209), (234, 209), (234, 228), (26, 228)]
recognize result: [Product Name]: Nourishing Hair Conditioner, score=0.710124
[6] @ [(26, 240), (241, 240), (241, 259), (26, 259)]
recognize result: [Product ID]: YM-X-3011, score=0.703522
[7] @ [(413, 233), (429, 233), (429, 305), (413, 305)]
recognize result: ODMOEM, score=0.708415
[8] @ [(25, 270), (179, 270), (179, 289), (25, 289)]
recognize result: [Net Content]: 220 ml, score=0.707519
[9] @ [(26, 303), (252, 303), (252, 321), (26, 321)]
recognize result: [Suitable For]: All skin types, score=0.709698
[10] @ [(26, 333), (341, 333), (341, 351), (26, 351)]
recognize result: [Main Ingredients]: Cetearyl Alcohol, Oat Beta-Glucan, score=0.689684
[11] @ [(27, 363), (283, 365), (282, 384), (26, 382)]
recognize result: Sugar, Cocamidopropyl Betaine, Pantothenic Acid, score=0.691807
[12] @ [(368, 368), (476, 368), (476, 388), (368, 388)]
recognize result: (Finished Packaging Material), score=0.706706
[13] @ [(27, 394), (362, 396), (361, 414), (26, 413)]
recognize result: [Main Function]: Tightens the hair cuticle to improve smoothness, score=0.696854
[14] @ [(27, 428), (371, 428), (371, 446), (27, 446)]
recognize result: Improves hair shine immediately and over time, while nourishing dry hair, score=0.711040
[15] @ [(27, 459), (136, 459), (136, 478), (27, 478)]
recognize result: Provides sufficient nourishment, score=0.711344
SAVE TO ./out.jpg
write_image path: ./out.jpg width=500 height=500 channel=3 data=0x2bf82010
Result Preview

Python API
Activate the virtual environment
conda activate rknn
Run the Example
Dependency note: Install dependencies with the command below.
pip install shapely pyclipper
Copy the related files to the device and run the following commands.
python ppocr_system.py --det_model_path ../model/ppocrv4_det.rknn --rec_model_path ../model/ppocrv4_rec.rknn --target ${TARGET_PLATFORM}
$ python ppocr_system.py --det_model_path ../model/ppocrv4_det.rknn --rec_model_path ../model/ppocrv4_rec.rknn --target rk3588
/home/radxa/miniforge3/envs/rknn/lib/python3.12/site-packages/rknn/api/rknn.py:51: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
self.rknn_base = RKNNBase(cur_path, verbose)
I rknn-toolkit2 version: 2.3.2
--> Init runtime environment
I target set by user is: rk3588
done
Model-../model/ppocrv4_det.rknn is rknn model, starting val
I rknn-toolkit2 version: 2.3.2
--> Init runtime environment
I target set by user is: rk3588
done
Model-../model/ppocrv4_rec.rknn is rknn model, starting val
W inference: The 'data_format' is not set, and its default value is 'nhwc'!
W inference: The 'data_format' is not set, and its default value is 'nhwc'!
W inference: The 'data_format' is not set, and its default value is 'nhwc'!
W inference: The 'data_format' is not set, and its default value is 'nhwc'!
[[('Nourishing Hair Conditioner', 0.7113560438156128)], [('Product Information/Parameters', 0.7074497938156128)], [('(45 CNY/kg, minimum order: 100 kg)', 0.6900849938392639)], [('22 CNY per bottle, minimum order: 1000 bottles)', 0.7073799967765808)], [('[Brand]: Contract Manufacturing/OEM ODM', 0.7077493071556091)], [('[Product Name]: Nourishing Hair Conditioner', 0.7105305790901184)], [('[Product ID]: YM-X-3011', 0.705413818359375)], [('ODM OEM', 0.6839424967765808)], [('[Net Content]: 220ml', 0.7086736559867859)], [('[Suitable For]: All skin types', 0.7099984884262085)], [('[Main Ingredients]: Cetearyl Alcohol, Oat Beta-Glucan', 0.6929739117622375)], [('Sugar, Cocamidopropyl Betaine, Pantothenic Acid', 0.6709420084953308)], [('(Finished Packaging Material)', 0.708251953125)], [('[Main Function]: Tightens the hair cuticle for better shine', 0.7064401507377625)], [('Improves shine and nourishes dry hair', 0.7103207111358643)], [('Provides sufficient nourishment', 0.7110188603401184)]]