# paddleocr_fastdeploy_cpp_demo **Repository Path**: wl-echo/paddleocr_fastdeploy_cpp_demo ## Basic Information - **Project Name**: paddleocr_fastdeploy_cpp_demo - **Description**: 1. 这个仓库用于 C++ 环境下自动测试开发验证。 2. 基线代码来自 PaddleOCR 仓库,commit 40c56628fda416e1c8710eb19e4b260536902520 - **Primary Language**: C++ - **License**: Apache-2.0 - **Default Branch**: develop - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-10 - **Last Updated**: 2024-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # paddleocr_fastdeploy_cpp_demo - [paddleocr\_fastdeploy\_cpp\_demo](#paddleocr_fastdeploy_cpp_demo) - [Introduction](#introduction) - [deps](#deps) - [build](#build) - [cpp\_gtest](#cpp_gtest) - [cpp\_catch2](#cpp_catch2) - [inference test (applied to both cpp\_gtest and cpp\_catch2)](#inference-test-applied-to-both-cpp_gtest-and-cpp_catch2) - [run test cases with GoogleTest](#run-test-cases-with-googletest) - [run test cases with Catch2](#run-test-cases-with-catch2) - [convert xml test report to html for reading](#convert-xml-test-report-to-html-for-reading) ## Introduction 1. 这个仓库用于 C++ 环境下自动测试开发验证。 2. 基线代码来自 PaddleOCR 仓库,commit 40c56628fda416e1c8710eb19e4b260536902520 3. test with macOS + clang. ## deps 1. refer to: https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md 2. download: https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-1.0.7.tgz ## build ### cpp_gtest googletest should be downloaded automatically during cmake process. ``` cd cpp_gtest mkdir build cd build wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-1.0.7.tgz tar -zxvf fastdeploy-osx-arm64-1.0.7.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-osx-arm64-1.0.7 make -j ``` googletest deps structure is as following: ``` build/_deps ├── googletest-build │   ├── CMakeFiles │   ├── CTestTestfile.cmake │   ├── Makefile │   ├── cmake_install.cmake │   ├── googlemock │   └── googletest ├── googletest-src │   ├── BUILD.bazel │   ├── CMakeLists.txt │   ├── CONTRIBUTING.md │   ├── CONTRIBUTORS │   ├── LICENSE │   ├── MODULE.bazel │   ├── README.md │   ├── WORKSPACE │   ├── WORKSPACE.bzlmod │   ├── ci │   ├── docs │   ├── fake_fuchsia_sdk.bzl │   ├── googlemock │   ├── googletest │   └── googletest_deps.bzl └── googletest-subbuild ├── CMakeCache.txt ├── CMakeFiles ├── CMakeLists.txt ├── Makefile ├── cmake_install.cmake └── googletest-populate-prefix ``` ### cpp_catch2 catch2 should be downloaded automatically during cmake process. ``` cd cpp_catch2 mkdir build cd build cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-osx-arm64-1.0.7 make -j ``` catch2 deps structure is as following: ``` build/_deps ├── catch2-build │   ├── CMakeFiles │   ├── Makefile │   ├── cmake_install.cmake │   ├── generated-includes │   └── src ├── catch2-src │   ├── BUILD.bazel │   ├── CMake │   ├── CMakeLists.txt │   ├── CMakePresets.json │   ├── CODE_OF_CONDUCT.md │   ├── Doxyfile │   ├── LICENSE.txt │   ├── MODULE.bazel │   ├── README.md │   ├── SECURITY.md │   ├── WORKSPACE.bazel │   ├── appveyor.yml │   ├── codecov.yml │   ├── conanfile.py │   ├── data │   ├── docs │   ├── examples │   ├── extras │   ├── fuzzing │   ├── mdsnippets.json │   ├── meson.build │   ├── meson_options.txt │   ├── src │   ├── tests │   ├── third_party │   └── tools └── catch2-subbuild ├── CMakeCache.txt ├── CMakeFiles ├── CMakeLists.txt ├── Makefile ├── catch2-populate-prefix └── cmake_install.cmake ``` ## inference test (applied to both cpp_gtest and cpp_catch2) inference with Backend::ORT in Device::CPU. ``` cd cpp_gtest #or cd cpp_catch2 ./build/infer_demo ../models/ch_PP-OCRv3_det_infer ../models/ch_ppocr_mobile_v2.0_cls_infer ../models/ch_PP-OCRv3_rec_infer ../models/ch_PP-OCRv3_rec_infer/ppocr_keys_v1.txt ../images/12.jpg 2 ./build/infer_demo ../models/ch_PP-OCRv3_det_infer ../models/ch_ppocr_mobile_v2.0_cls_infer ../models/ch_PP-OCRv3_rec_infer ../models/ch_PP-OCRv3_rec_infer/ppocr_keys_v1.txt ../images 2 ``` output is as following: ``` [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. det boxes: [[42,413],[483,391],[484,428],[43,450]]rec text: 上海斯格威铂尔大酒店 rec score:0.980087 cls label: 0 cls score: 1.000000 det boxes: [[187,456],[399,448],[400,480],[188,488]]rec text: 打浦路15号 rec score:0.964994 cls label: 0 cls score: 1.000000 det boxes: [[23,507],[513,488],[515,529],[24,548]]rec text: 绿洲仕格维花园公寓 rec score:0.993729 cls label: 0 cls score: 1.000000 det boxes: [[74,553],[427,542],[428,571],[75,582]]rec text: 打浦路252935号 rec score:0.947725 cls label: 0 cls score: 1.000000 Visualized result saved in ./vis_result.jpg ``` ## run test cases with GoogleTest xml test report is saved in ./build/test_reports/ directory. ``` cd cpp_gtest/build ctest #ctest --rerun-failed --output-on-failure #re-run the failed cases verbosely #ctest --verbose #Enable verbose output from tests ``` output from 「ctest」 is as following: ``` Test project /Users/leiwu/Documents/gitee/paddleocr_fastdeploy_cpp_demo/cpp_gtest/build Start 1: InferTest 1/2 Test #1: InferTest ........................ Passed 2.19 sec Start 2: InferMock 2/2 Test #2: InferMock ........................ Passed 0.85 sec 100% tests passed, 0 tests failed out of 2 Total Test time (real) = 3.05 sec ``` Cases can also be run by test suite name as following: ``` cd cpp_gtest/build ./infer_test ./infer_mock ``` ## run test cases with Catch2 ``` cd cpp_catch2 ./build/run_tests # create xml report #./build/run_tests --reporter xml --out test_reports/report.xml ``` output is as following: ``` Randomness seeded to: 963192831 [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. det boxes: [[42,413],[483,391],[484,428],[43,450]]rec text: 上海斯格威铂尔大酒店 rec score:0.980087 cls label: 0 cls score: 1.000000 det boxes: [[187,456],[399,448],[400,480],[188,488]]rec text: 打浦路15号 rec score:0.964994 cls label: 0 cls score: 1.000000 det boxes: [[23,507],[513,488],[515,529],[24,548]]rec text: 绿洲仕格维花园公寓 rec score:0.993729 cls label: 0 cls score: 1.000000 det boxes: [[74,553],[427,542],[428,571],[75,582]]rec text: 打浦路252935号 rec score:0.947725 cls label: 0 cls score: 1.000000 Visualized result saved in ./vis_result.jpg [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [WARNING] fastdeploy/runtime/runtime_option.cc(395)::SetTrtInputShape `RuntimeOption::SetTrtInputShape` will be removed in v1.2.0, please use `RuntimeOption.trt_option.SetShape()` instead. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. [INFO] fastdeploy/runtime/runtime.cc(300)::CreateOrtBackend Runtime initialized with Backend::ORT in Device::CPU. det boxes: [[42,413],[483,391],[484,428],[43,450]]rec text: 上海斯格威铂尔大酒店 rec score:0.980087 cls label: 0 cls score: 1.000000 det boxes: [[187,456],[399,448],[400,480],[188,488]]rec text: 打浦路15号 rec score:0.964994 cls label: 0 cls score: 1.000000 det boxes: [[23,507],[513,488],[515,529],[24,548]]rec text: 绿洲仕格维花园公寓 rec score:0.993729 cls label: 0 cls score: 1.000000 det boxes: [[74,553],[427,542],[428,571],[75,582]]rec text: 打浦路252935号 rec score:0.947725 cls label: 0 cls score: 1.000000 Visualized result saved in ./vis_result.jpg Usage: infer_demo path/to/det_model path/to/cls_model path/to/rec_model path/to/rec_label_file path/to/image run_option, e.g ./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 0 The data type of run_option is int, e.g. 0: run with paddle inference on cpu; Invalid run option: 999 =============================================================================== All tests passed (6 assertions in 4 test cases) ``` ## convert xml test report to html for reading xsltproc is required. ``` cd cpp_gtest xsltproc gtest-to-html.xslt build/test_reports/infer_test.xml > build/test_reports/infer_test.html ```