当前位置: 首页 > news >正文

Cmake4编译PaddleOCR3.0成功步骤

编译相关软件: Cmake4.0+VS2022+PaddleOCR3.0

下载地址:

PaddleOCR发布版本3.0下载地址
https://github.com/PaddlePaddle/PaddleOCR/tree/release/3.0

PaddleOCR推理库3.0下载地址
https://paddle-inference-lib.bj.bcebos.com/3.0.0/cxx_c/Windows/CPU/x86-64_avx-mkl-vs2019/paddle_inference.zip

一、打开Cmake软件,配置PaddleOCR3.0编译相关参数如下:

源码目录:D:\PaddleOCR30\PaddleOCR-release-3.0\deploy\cpp_infer

生成目录:D:\PaddleOCR30\PaddleOCR-release-3.0\deploy\cpp_infer\build_vs2019_x64

二、点击【Configure】按钮,设置详细配置参数如下:

CMAKE_INSTALL_PREFIX设置安装路径为:D:/PaddleOCR30/PaddleOCR-release-3.0/deploy/cpp_infer/build_vs2019_x64/install

OPENCV_DIR设置为本地的Opencv目录:D:/opencv410/build_vs2019_x64/install/x64/vc16/lib

OpenCV_DIR目录设置同上:D:/opencv410/build_vs2019_x64/install/x64/vc16/lib

PADDLE_LIB目录设置为:D:/PaddleOCR30/paddle_inference3.0

WITH_GPU选项设置为:不勾选
WITH_MKL选项设置为:勾选
WITH_STATIC_LIB选项设置为:勾选
WITH_TENSORRT选项设置为:不勾选

三、异常错误处理办法如下:

3.1错误一: Failed to clone repository: 'https://github.com/LDOUBLEV/AutoLog.git'
    external-cmake/auto-log.cmake:13 (FetchContent_MakeAvailable)
  CMakeLists.txt:220 (include)

解决办法:修改D:\PaddleOCR30\PaddleOCR-release-3.0\deploy\cpp_infer\external-cmake\auto-log.cmake文件内容如下:

find_package(Git REQUIRED)
include(FetchContent)set(FETCHCONTENT_BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}/third-party")FetchContent_Declare(extern_AutologPREFIX autolog# If you don't have access to github, replace it with https://gitee.com/Double_V/AutoLogGIT_REPOSITORY https://gitee.com/Double_V/AutoLogGIT_TAG        main
)
FetchContent_MakeAvailable(extern_Autolog)

3.2错误二:D:\PaddleOCR30\PaddleOCR-release-3.0\deploy\cpp_infer\build_vs2019_x64\third-party\extern_autolog-src\CMakeLists.txt文件错误,需要修改VERSION3.5到4.0

cmake_minimum_required(VERSION 4.0)
project(cpp_auto_log CXX C)message("default cmake for auto_log, no need to compile")

四、点击【Generate】按钮生成VS项目解决方案文件:D:\PaddleOCR30\PaddleOCR-release-3.0\deploy\cpp_infer\build_vs2019_x64\ppocr.sln。点击【Open Project】按钮,系统自动在VS202软件中打开对应的解决方案。

在VS202软件中选则编译模式为Release+64位,鼠标右键点击解决方案名称,选择【重新生成解决方案】,系统报错,主要解决方法包含如下三点:

4.1需要下载头文件https://github.com/tronkko/dirent/blob/master/include/dirent.h,拷贝到
D:\PaddleOCR30\PaddleOCR-release-3.0\deploy\cpp_infer\include目录下,并修改D:\PaddleOCR30\PaddleOCR-release-3.0\deploy\cpp_infer\src\utility.cpp文件中引用路径为#include <include/dirent.h>

4.2删除D:\PaddleOCR30\PaddleOCR-release-3.0\deploy\cpp_infer\build_vs2019_x64\third-party\extern_autolog-src\auto_log\autolog.h文件中的报错代码

4.3参考上文Cmake编译yaml-cpp并在QT中测试成功操作步骤-CSDN博客手动编译和拷贝yaml-cpp对应的静态库文件D:\yaml-cpp-master\build_vs2022\Release\yaml-cpp.lib到D:\PaddleOCR30\paddle_inference3.0\third_party\install\yaml-cpp\lib\yaml-cpp.lib

 4.4拷贝D:\PaddleOCR30\paddle_inference3.0\paddle\lib\common.dll和D:\PaddleOCR30\paddle_inference3.0\paddle\lib\paddle_inference.dll两个文件到运行目录D:\PaddleOCR30\PaddleOCR-release-3.0\deploy\cpp_infer\build_vs2019_x64\Release下

4.5拷贝本地的opencv对应的dll文件(D:\opencv410\build_vs2019_x64\install\x64\vc16\bin\opencv_world4100.dll)到对应目录(D:\PaddleOCR\build_vs2019_x64\Release)下

4.6修改Source Files目录下的args.cpp文件中的配置项如下:

修改后的args.cpp全文内容如下:


#include <gflags/gflags.h>// common args
DEFINE_bool(use_gpu, false, "Inferring with GPU or CPU.");
DEFINE_bool(use_tensorrt, false, "Whether use tensorrt.");
DEFINE_int32(gpu_id, 0, "Device id of GPU to execute.");
DEFINE_int32(gpu_mem, 4000, "GPU id when inferring with GPU.");
DEFINE_int32(cpu_threads, 10, "Num of threads with CPU.");
DEFINE_bool(enable_mkldnn, false, "Whether use mkldnn with CPU.");
DEFINE_string(precision, "fp32", "Precision be one of fp32/fp16/int8");
DEFINE_bool(benchmark, false, "Whether use benchmark.");
DEFINE_string(output, "C:/Users/Admin/Desktop/111/output/", "Save benchmark log path.");
DEFINE_string(image_dir, "C:/Users/Admin/Desktop/111/ocr/", "Dir of input image.");
DEFINE_string(type, "ocr","Perform ocr or structure, the value is selected in ['ocr','structure'].");
// detection related
DEFINE_string(det_model_dir, "D:/PaddleOCR30/model/ch_PP-OCRv4_det_infer", "Path of det inference model.");
DEFINE_string(limit_type, "max", "limit_type of input image.");
DEFINE_int32(limit_side_len, 960, "limit_side_len of input image.");
DEFINE_double(det_db_thresh, 0.3, "Threshold of det_db_thresh.");
DEFINE_double(det_db_box_thresh, 0.6, "Threshold of det_db_box_thresh.");
DEFINE_double(det_db_unclip_ratio, 1.5, "Threshold of det_db_unclip_ratio.");
DEFINE_bool(use_dilation, false, "Whether use the dilation on output map.");
DEFINE_string(det_db_score_mode, "slow", "Whether use polygon score.");
DEFINE_bool(visualize, true, "Whether show the detection results.");
// classification related
DEFINE_bool(use_angle_cls, false, "Whether use use_angle_cls.");
DEFINE_string(cls_model_dir, "D:/PaddleOCR30/model/ch_ppocr_mobile_v2.0_cls_infer", "Path of cls inference model.");
DEFINE_double(cls_thresh, 0.9, "Threshold of cls_thresh.");
DEFINE_int32(cls_batch_num, 1, "cls_batch_num.");
// recognition related
DEFINE_string(rec_model_dir, "D:/PaddleOCR30/model/ch_PP-OCRv4_rec_infer", "Path of rec inference model.");
DEFINE_int32(rec_batch_num, 6, "rec_batch_num.");
DEFINE_string(rec_char_dict_path, "D:/PaddleOCR30/PaddleOCR-release-3.0/ppocr/utils/ppocr_keys_v1.txt",              "Path of dictionary.");
DEFINE_int32(rec_img_h, 48, "rec image height");
DEFINE_int32(rec_img_w, 320, "rec image width");// layout model related
DEFINE_string(layout_model_dir, "", "Path of table layout inference model.");
DEFINE_string(layout_dict_path,"D:/PaddleOCR30/PaddleOCR-release-3.0/ppocr/utils/dict/layout_dict/layout_publaynet_dict.txt","Path of dictionary.");
DEFINE_double(layout_score_threshold, 0.5, "Threshold of score.");
DEFINE_double(layout_nms_threshold, 0.5, "Threshold of nms.");
// structure model related
DEFINE_string(table_model_dir, "", "Path of table structure inference model.");
DEFINE_int32(table_max_len, 488, "max len size of input image.");
DEFINE_int32(table_batch_num, 1, "table_batch_num.");
DEFINE_bool(merge_no_span_structure, true,"Whether merge <td> and </td> to <td></td>");
DEFINE_string(table_char_dict_path, "D:/PaddleOCR30/PaddleOCR-release-3.0/ppocr/utils/dict/table_structure_dict_ch.txt","Path of dictionary.");// ocr forward related
DEFINE_bool(det, true, "Whether use det in forward.");
DEFINE_bool(rec, true, "Whether use rec in forward.");
DEFINE_bool(cls, false, "Whether use cls in forward.");
DEFINE_bool(table, false, "Whether use table structure in forward.");
DEFINE_bool(layout, false, "Whether use layout analysis in forward.");

五、运行项目

使用Notepad--软件修改D:\PaddleOCR30\PaddleOCR-release-3.0\ppocr\utils\ppocr_keys_v1.txt文本文件编码为ANSI/GBK后再运行就没有乱码了。

总结:整个编译算是通过了,主要是根据各种错误来找解决办法。编译过程中这样那样的错误可能是PaddleOCR3.0的使用语言是Python、操作系统Linux环境居多,所以静态库和其他一堆问题都随之产生。

相关文章:

  • 分块查找详解
  • yolo最终笔记
  • 【node】Express创建服务器
  • 使用新一代达梦管理工具SQLark,高效处理 JSON/XML 数据!
  • linux快速入门-VMware安装linux,配置静态ip,使用服务器连接工具连接,快照和克隆以及修改相关配置信息
  • 通用前端框架项目静态部署到Hugging Face Space的实践指南
  • 2025.5.27学习日记 linux三剑客 sed与正则表达式
  • IEEE出版|2025人工智能驱动图像处理与计算机视觉技术国际学术研讨会 (AIPCVT 2025)
  • 自动生成提示技术突破:AUTOPROMPT重塑语言模型应用
  • Cesium添加点、线、面
  • threejs顶点UV坐标、纹理贴图
  • 三、web安全-信息收集
  • python 生成复杂表格,自动分页等功能
  • 【北京盈达科技】GEO优化:引领AI时代内容霸权,重塑行业生态
  • 【Redis】Redis使用规范
  • SAP Business One, Web Client Analytics-2
  • vllm server返回404的一种可能得解决方案
  • UE5 Mat HLSL - Load
  • LangGraph(七)——Workflows
  • Vue-02 (使用不同的 Vue CLI 插件)
  • 关于重新建设网站的申请表/指数搜索
  • 自贡网站制作/南宁seo主管
  • 常州网站建设基本流程/六六seo基础运营第三讲
  • 国外优秀app设计网站有哪些/北京seo外包
  • 佛山新网站建设流程/软文推广产品
  • 网站收录原创文章/网络营销的内容有哪些方面