简单易上手的在windows部署cmake版paddledetection/yolo(c++)

news2024/12/25 2:52:46

一.下载源代码

官方地址:
https://gitee.com/paddlepaddle/PaddleDetection

网盘:
paddledetection
链接:https://pan.baidu.com/s/1g0z5SYQNDR1pwe9iAtvR3A?pwd=ktl6 
提取码:ktl6
paddleocr
链接:https://pan.baidu.com/s/1QcLbGJD7NB9UVPbUAulCuA?pwd=o68i 
提取码:o68i

二.找到c++部署代码

在这里插入图片描述
在这里插入图片描述
我个人为了整体性把src文件里的后缀都改为了cpp
在这里插入图片描述

三.改CMakeLists.txt文件

原版cmake文件很繁琐,我改写了一个简洁版的
移植的时候只需要改头文件地址和库文件地址即可

1.改前

cmake_minimum_required(VERSION 3.0)
project(PaddleObjectDetector CXX C)

option(WITH_MKL        "Compile demo with MKL/OpenBlas support,defaultuseMKL."          ON)
option(WITH_GPU        "Compile demo with GPU/CPU, default use CPU."                    ON)
option(WITH_TENSORRT   "Compile demo with TensorRT."                                    OFF)

option(WITH_KEYPOINT        "Whether to Compile KeyPoint detector"                    OFF)
option(WITH_MOT       "Whether to Compile MOT detector" OFF)

SET(PADDLE_DIR "" CACHE PATH "Location of libraries")
SET(PADDLE_LIB_NAME "" CACHE STRING "libpaddle_inference")
SET(OPENCV_DIR "" CACHE PATH "Location of libraries")
SET(CUDA_LIB "" CACHE PATH "Location of libraries")
SET(CUDNN_LIB "" CACHE PATH "Location of libraries")
SET(TENSORRT_INC_DIR "" CACHE PATH "Compile demo with TensorRT")
SET(TENSORRT_LIB_DIR "" CACHE PATH "Compile demo with TensorRT")

include(cmake/yaml-cpp.cmake)

include_directories("${CMAKE_SOURCE_DIR}/")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/ext/yaml-cpp/src/ext-yaml-cpp/include")
link_directories("${CMAKE_CURRENT_BINARY_DIR}/ext/yaml-cpp/lib")

if (WITH_KEYPOINT)
    set(SRCS src/main_keypoint.cc src/preprocess_op.cc src/object_detector.cc src/picodet_postprocess.cc src/utils.cc src/keypoint_detector.cc src/keypoint_postprocess.cc)
elseif (WITH_MOT)
    set(SRCS src/main_jde.cc src/preprocess_op.cc src/object_detector.cc src/jde_detector.cc src/tracker.cc src/trajectory.cc src/lapjv.cpp src/picodet_postprocess.cc src/utils.cc)
else ()
    set(SRCS src/main.cc src/preprocess_op.cc src/object_detector.cc src/picodet_postprocess.cc src/utils.cc)
endif()

macro(safe_set_static_flag)
    foreach(flag_var
        CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
        CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
      if(${flag_var} MATCHES "/MD")
        string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
      endif(${flag_var} MATCHES "/MD")
    endforeach(flag_var)
endmacro()

if (WITH_MKL)
    ADD_DEFINITIONS(-DUSE_MKL)
endif()

if (NOT DEFINED PADDLE_DIR OR ${PADDLE_DIR} STREQUAL "")
    message(FATAL_ERROR "please set PADDLE_DIR with -DPADDLE_DIR=/path/paddle_influence_dir")
endif()
message("PADDLE_DIR IS:" ${PADDLE_DIR})

if (NOT DEFINED OPENCV_DIR OR ${OPENCV_DIR} STREQUAL "")
    message(FATAL_ERROR "please set OPENCV_DIR with -DOPENCV_DIR=/path/opencv")
endif()

include_directories("${CMAKE_SOURCE_DIR}/")
include_directories("${PADDLE_DIR}/")
include_directories("${PADDLE_DIR}/third_party/install/protobuf/include")
include_directories("${PADDLE_DIR}/third_party/install/glog/include")
include_directories("${PADDLE_DIR}/third_party/install/gflags/include")
include_directories("${PADDLE_DIR}/third_party/install/xxhash/include")
if (EXISTS "${PADDLE_DIR}/third_party/install/snappy/include")
    include_directories("${PADDLE_DIR}/third_party/install/snappy/include")
endif()
if(EXISTS "${PADDLE_DIR}/third_party/install/snappystream/include")
    include_directories("${PADDLE_DIR}/third_party/install/snappystream/include")
endif()
include_directories("${PADDLE_DIR}/third_party/boost")
include_directories("${PADDLE_DIR}/third_party/eigen3")

if (EXISTS "${PADDLE_DIR}/third_party/install/snappy/lib")
    link_directories("${PADDLE_DIR}/third_party/install/snappy/lib")
endif()
if(EXISTS "${PADDLE_DIR}/third_party/install/snappystream/lib")
    link_directories("${PADDLE_DIR}/third_party/install/snappystream/lib")
endif()

link_directories("${PADDLE_DIR}/third_party/install/protobuf/lib")
link_directories("${PADDLE_DIR}/third_party/install/glog/lib")
link_directories("${PADDLE_DIR}/third_party/install/gflags/lib")
link_directories("${PADDLE_DIR}/third_party/install/xxhash/lib")
link_directories("${PADDLE_DIR}/third_party/install/paddle2onnx/lib")
link_directories("${PADDLE_DIR}/third_party/install/onnxruntime/lib")
link_directories("${PADDLE_DIR}/paddle/lib/")
link_directories("${CMAKE_CURRENT_BINARY_DIR}")



if (WIN32)
  include_directories("${PADDLE_DIR}/paddle/fluid/inference")
  include_directories("${PADDLE_DIR}/paddle/include")
  link_directories("${PADDLE_DIR}/paddle/fluid/inference")
  find_package(OpenCV REQUIRED PATHS ${OPENCV_DIR}/build/ NO_DEFAULT_PATH)

else ()
  find_package(OpenCV REQUIRED PATHS ${OPENCV_DIR}/share/OpenCV NO_DEFAULT_PATH)
  include_directories("${PADDLE_DIR}/paddle/include")
  link_directories("${PADDLE_DIR}/paddle/lib")
endif ()
include_directories(${OpenCV_INCLUDE_DIRS})

if (WIN32)
    add_definitions("/DGOOGLE_GLOG_DLL_DECL=")
    set(CMAKE_C_FLAGS_DEBUG   "${CMAKE_C_FLAGS_DEBUG} /bigobj /MTd")
    set(CMAKE_C_FLAGS_RELEASE  "${CMAKE_C_FLAGS_RELEASE} /bigobj /MT")
    set(CMAKE_CXX_FLAGS_DEBUG  "${CMAKE_CXX_FLAGS_DEBUG} /bigobj /MTd")
    set(CMAKE_CXX_FLAGS_RELEASE   "${CMAKE_CXX_FLAGS_RELEASE} /bigobj /MT")
else()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -o2 -fopenmp -std=c++11")
    set(CMAKE_STATIC_LIBRARY_PREFIX "")
endif()

# TODO let users define cuda lib path
if (WITH_GPU)
    if (NOT DEFINED CUDA_LIB OR ${CUDA_LIB} STREQUAL "")
        message(FATAL_ERROR "please set CUDA_LIB with -DCUDA_LIB=/path/cuda-8.0/lib64")
    endif()
    if (NOT WIN32)
        if (NOT DEFINED CUDNN_LIB)
            message(FATAL_ERROR "please set CUDNN_LIB with -DCUDNN_LIB=/path/cudnn_v7.4/cuda/lib64")
        endif()
    endif(NOT WIN32)
endif()


if (NOT WIN32)
  if (WITH_TENSORRT AND WITH_GPU)
	  include_directories("${TENSORRT_INC_DIR}/")
	  link_directories("${TENSORRT_LIB_DIR}/")
  endif()
endif(NOT WIN32)

if (NOT WIN32)
    set(NGRAPH_PATH "${PADDLE_DIR}/third_party/install/ngraph")
    if(EXISTS ${NGRAPH_PATH})
        include(GNUInstallDirs)
        include_directories("${NGRAPH_PATH}/include")
        link_directories("${NGRAPH_PATH}/${CMAKE_INSTALL_LIBDIR}")
        set(NGRAPH_LIB ${NGRAPH_PATH}/${CMAKE_INSTALL_LIBDIR}/libngraph${CMAKE_SHARED_LIBRARY_SUFFIX})
    endif()
endif()

if(WITH_MKL)
  include_directories("${PADDLE_DIR}/third_party/install/mklml/include")
  if (WIN32)
    set(MATH_LIB ${PADDLE_DIR}/third_party/install/mklml/lib/mklml.lib
            ${PADDLE_DIR}/third_party/install/mklml/lib/libiomp5md.lib)
  else ()
    set(MATH_LIB ${PADDLE_DIR}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX}
            ${PADDLE_DIR}/third_party/install/mklml/lib/libiomp5${CMAKE_SHARED_LIBRARY_SUFFIX})
    execute_process(COMMAND cp -r ${PADDLE_DIR}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX} /usr/lib)
  endif ()
  set(MKLDNN_PATH "${PADDLE_DIR}/third_party/install/mkldnn")
  if(EXISTS ${MKLDNN_PATH})
    include_directories("${MKLDNN_PATH}/include")
    if (WIN32)
      set(MKLDNN_LIB ${MKLDNN_PATH}/lib/mkldnn.lib)
    else ()
      set(MKLDNN_LIB ${MKLDNN_PATH}/lib/libmkldnn.so.0)
    endif ()
  endif()
else()
  set(MATH_LIB ${PADDLE_DIR}/third_party/install/openblas/lib/libopenblas${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()


if (WIN32)
    if(EXISTS "${PADDLE_DIR}/paddle/fluid/inference/${PADDLE_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
        set(DEPS
            ${PADDLE_DIR}/paddle/fluid/inference/${PADDLE_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
    else()
        set(DEPS
            ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
    endif()
endif()


if (WIN32)
    set(DEPS ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
    set(DEPS ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()

message("PADDLE_LIB_NAME:" ${PADDLE_LIB_NAME})
message("DEPS:" $DEPS)

if (NOT WIN32)
    set(DEPS ${DEPS}
        ${MATH_LIB} ${MKLDNN_LIB}
        glog gflags protobuf z xxhash yaml-cpp
        )
    if(EXISTS "${PADDLE_DIR}/third_party/install/snappystream/lib")
        set(DEPS ${DEPS} snappystream)
    endif()
    if (EXISTS "${PADDLE_DIR}/third_party/install/snappy/lib")
        set(DEPS ${DEPS} snappy)
    endif()
else()
    set(DEPS ${DEPS}
        ${MATH_LIB} ${MKLDNN_LIB}
        glog gflags_static libprotobuf xxhash libyaml-cppmt)
    set(DEPS ${DEPS} libcmt shlwapi)
    if (EXISTS "${PADDLE_DIR}/third_party/install/snappy/lib")
        set(DEPS ${DEPS} snappy)
    endif()
    if(EXISTS "${PADDLE_DIR}/third_party/install/snappystream/lib")
        set(DEPS ${DEPS} snappystream)
    endif()
endif(NOT WIN32)

if(WITH_GPU)
  if(NOT WIN32)
    if (WITH_TENSORRT)
	    set(DEPS ${DEPS} ${TENSORRT_LIB_DIR}/libnvinfer${CMAKE_SHARED_LIBRARY_SUFFIX})
	    set(DEPS ${DEPS} ${TENSORRT_LIB_DIR}/libnvinfer_plugin${CMAKE_SHARED_LIBRARY_SUFFIX})
    endif()
    set(DEPS ${DEPS} ${CUDA_LIB}/libcudart${CMAKE_SHARED_LIBRARY_SUFFIX})
    set(DEPS ${DEPS} ${CUDNN_LIB}/libcudnn${CMAKE_SHARED_LIBRARY_SUFFIX})
  else()
    set(DEPS ${DEPS} ${CUDA_LIB}/cudart${CMAKE_STATIC_LIBRARY_SUFFIX} )
    set(DEPS ${DEPS} ${CUDA_LIB}/cublas${CMAKE_STATIC_LIBRARY_SUFFIX} )
    set(DEPS ${DEPS} ${CUDNN_LIB}/cudnn${CMAKE_STATIC_LIBRARY_SUFFIX})
  endif()
endif()

if (NOT WIN32)
    set(EXTERNAL_LIB "-ldl -lrt -lgomp -lz -lm -lpthread")
    set(DEPS ${DEPS} ${EXTERNAL_LIB})
endif()

set(DEPS ${DEPS} ${OpenCV_LIBS})
add_executable(main ${SRCS})
ADD_DEPENDENCIES(main ext-yaml-cpp)
message("DEPS:" $DEPS)
target_link_libraries(main ${DEPS})

if (WIN32 AND WITH_MKL)
    add_custom_command(TARGET main POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/mklml.dll ./mklml.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/libiomp5md.dll ./libiomp5md.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mkldnn/lib/mkldnn.dll ./mkldnn.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/mklml.dll ./release/mklml.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/libiomp5md.dll ./release/libiomp5md.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mkldnn/lib/mkldnn.dll ./release/mkldnn.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}.dll ./release/${PADDLE_LIB_NAME}.dll
    )
endif()

if (WIN32 AND NOT WITH_MKL)
    add_custom_command(TARGET main POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/openblas/lib/openblas.dll ./openblas.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/openblas/lib/openblas.dll ./release/openblas.dll
    )
endif()

if (WIN32)
    add_custom_command(TARGET main POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/onnxruntime/lib/onnxruntime.dll ./onnxruntime.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/paddle2onnx/lib/paddle2onnx.dll ./paddle2onnx.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/onnxruntime/lib/onnxruntime.dll ./release/onnxruntime.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/paddle2onnx/lib/paddle2onnx.dll ./release/paddle2onnx.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}.dll ./release/${PADDLE_LIB_NAME}.dll
    )
endif()

2.改后

cmake_minimum_required(VERSION 3.5)

set(CMAKE_BUILD_TYPE "Release")   #option: Debug / Release

if (CMAKE_BUILD_TYPE MATCHES "Debug" 
        OR CMAKE_BUILD_TYPE MATCHES "None")
    message(STATUS "CMAKE_BUILD_TYPE is Debug")
elseif (CMAKE_BUILD_TYPE MATCHES "Release")
    message(STATUS "CMAKE_BUILD_TYPE is Release")
endif()

# 设置c++标准
set(CMAKE_CXX_STANDARD 20)
project(DsYolo)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

option(WITH_MKL        "Compile demo with MKL/OpenBlas support, default use MKL."       ON)
option(WITH_GPU        "Compile demo with GPU/CPU, default use CPU."                    ON)
option(WITH_STATIC_LIB "Compile demo with static/shared library, default use static."   ON)
option(WITH_TENSORRT "Compile demo with TensorRT."   ON)

macro(safe_set_static_flag)
    foreach(flag_var
        CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
        CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
      if(${flag_var} MATCHES "/MD")
        string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
      endif(${flag_var} MATCHES "/MD")
    endforeach(flag_var)
endmacro()

if (WITH_MKL)
    ADD_DEFINITIONS(-DUSE_MKL)
endif()

if (MSVC)
    add_definitions(-w)
    #add_definitions(-W0)
endif()

if (WIN32)
    add_definitions("/DGOOGLE_GLOG_DLL_DECL=")
    set(CMAKE_C_FLAGS /source-charset:utf-8)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
    add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
    if(WITH_MKL)
        set(FLAG_OPENMP "/openmp")
    endif()
    set(CMAKE_C_FLAGS_DEBUG   "${CMAKE_C_FLAGS_DEBUG} /bigobj /MTd ${FLAG_OPENMP}")
    set(CMAKE_C_FLAGS_RELEASE  "${CMAKE_C_FLAGS_RELEASE} /bigobj /MT ${FLAG_OPENMP}")
    set(CMAKE_CXX_FLAGS_DEBUG  "${CMAKE_CXX_FLAGS_DEBUG} /bigobj /MTd ${FLAG_OPENMP}")
    set(CMAKE_CXX_FLAGS_RELEASE   "${CMAKE_CXX_FLAGS_RELEASE} /bigobj /MT ${FLAG_OPENMP}")
    if (WITH_STATIC_LIB)
        safe_set_static_flag()
        add_definitions(-DSTATIC_LIB)
    endif()
    message("cmake c debug flags " ${CMAKE_C_FLAGS_DEBUG})
    message("cmake c release flags " ${CMAKE_C_FLAGS_RELEASE})
    message("cmake cxx debug flags " ${CMAKE_CXX_FLAGS_DEBUG})
    message("cmake cxx release flags " ${CMAKE_CXX_FLAGS_RELEASE})
endif()


# 头文件
include_directories(${PROJECT_SOURCE_DIR}/include)
#include_directories(/home/nvidia/paddleOCR/PaddleOCR-release-2.6/deploy/cpp_infer/include)
#include_directories(/home/nvidia/paddleOCR/PaddleOCR-release-2.6/deploy/cpp_infer)
#include_directories(/usr/include)
include_directories(./)
include_directories(./include)
include_directories(./Ds_inference/opencv410/include/opencv4)
include_directories(./Ds_inference/opencv410/include/opencv4/opencv2)
include_directories(./Ds_inference/third_party/install/mklml/include)
include_directories(./Ds_inference/third_party/install/mkldnn/include)
include_directories(./Ds_inference/third_party/install/glog/include)
include_directories(./Ds_inference/third_party/AutoLog-main)
include_directories(./Ds_inference/third_party/install/gflags/include)
include_directories(./Ds_inference/third_party/install/protobuf/include)
include_directories(./Ds_inference/third_party/threadpool)
include_directories(./Ds_inference/third_party/yaml-cpp)
include_directories(./Ds_inference/paddle_gpu11.6/include)
# 库文件
#link_directories(/usr/lib)
link_directories(./Ds_inference/third_party/install/mklml/lib)
link_directories(./Ds_inference/third_party/install/mkldnn/lib)
link_directories(./Ds_inference/third_party/install/glog/lib)
link_directories(./Ds_inference/opencv410/lib)
link_directories(./Ds_inference/third_party/install/protobuf/lib)
link_directories(./Ds_inference/third_party/install/gflags/lib)
link_directories(./Ds_inference/paddle_gpu11.6/lib)
link_directories(./Ds_inference/third_party/yaml-cpp/lib)


aux_source_directory (src SRC_LIST)
add_executable (yoloV5 ${SRC_LIST})

set(LIBRARY_OUTPUT_PATH  ${PROJECT_SOURCE_DIR}/bin)
set(output)

target_link_libraries(yoloV5
opencv_world410
#opencv_highgui opencv_core opencv_imgproc opencv_imgcodecs opencv_calib3d opencv_features2d opencv_videoio 
paddle_inference mklml libiomp5md mkldnn glog gflags_static libprotobuf libcmt shlwapi yaml-cpp
)

# 注意测试
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

四.(windows平台)创造一个文件夹将生成可执行文件需要的库放入

在这里插入图片描述
在这里插入图片描述
需要用到gpu,就需要事先配置好cuda这一套的环境变量,就不用在cmakelists里面专门写来引用了,配置方法见http://t.csdn.cn/mgIMD

五.编译的时候遇到的bug

1.xxx已经在obj中定义

在这里插入图片描述
这三个关于main的cpp中只能同事存在一个,看自己需要那个,将不需要的文件里面代码全部注释,,我是使用了main.cpp,反正遇到这种报错通常把一些东西注释掉就能解决

2.error C7555: … requires at least ‘/std:c++latest’ when build in Win10

意思是c++版本低了
在这里插入图片描述
找到cmakelists这句函数,然后我发现我之前写的是17,我改成20之后完美解决。

3.fatal error C1083: 无法打开包括文件: “yaml-cpp/yaml.h”: No such file or directory

其实源cmakelists中是套了一个include(cmake/yaml-cpp.cmake),来编译


find_package(Git REQUIRED)

include(ExternalProject)

message("${CMAKE_BUILD_TYPE}")

ExternalProject_Add(
        ext-yaml-cpp
        URL https://bj.bcebos.com/paddlex/deploy/deps/yaml-cpp.zip
        URL_MD5 9542d6de397d1fbd649ed468cb5850e6
        CMAKE_ARGS
        -DYAML_CPP_BUILD_TESTS=OFF
		-DYAML_CPP_BUILD_TOOLS=OFF
        -DYAML_CPP_INSTALL=OFF
        -DYAML_CPP_BUILD_CONTRIB=OFF
		-DMSVC_SHARED_RT=OFF
		-DBUILD_SHARED_LIBS=OFF
        -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
        -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
        -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}
        -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
        -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}/ext/yaml-cpp/lib
        -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}/ext/yaml-cpp/lib
        PREFIX "${CMAKE_BINARY_DIR}/ext/yaml-cpp"
        # Disable install step
        INSTALL_COMMAND ""
	    LOG_DOWNLOAD ON
        LOG_BUILD 1
)

我还是想自己来编译,因为根据之前的经验,这种需要远程下载源码的总是有这样那样的问题。

下载源码

https://github.com/jbeder/yaml-cpp

在这里插入图片描述
我以为只是缺少头文件,cmakelists里面补上之后
在这里插入图片描述
出现无法解析的外部符号,大概率是缺少库,然后我去编译yaml-cpp的库。
在这里插入图片描述
就是很常规的操作,用cmake … 直接就编译出了一个lib库,很顺利,但是使用的时候显示无法打开此lib
在这里插入图片描述
我再重新生成找原因
在这里插入图片描述
注意到这一句Defining YAML_CPP_API for DLL import,然后我搜索这个关键词,搜到了https://blog.csdn.net/m0_37833142/article/details/115180471,
即在cmake后多加了一个参数,就成功可以正常调用了,到底是什么原理,我还得继续学习

cmake -DYAML_BUILD_SHARED_LIBS=ON ..

在这里插入图片描述

六.下载模型测试

下载地址:
https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/docs/feature_models/PaddleYOLO_MODEL.md
里面有yolo一系列的库
在这里插入图片描述
在部署模型里面选择模型下载,左边导出后的权重那些模型是paddle框架的paddle格式模型,右边onnx指onnx格式模型,_nms表示带NMS后处理,可以直接使用预测出最终检测框结果如python deploy/python/infer.py --model_dir=ppyoloe_crn_l_300e_coco_w_nms/ --image_file=demo/000000014439.jpg --device=GPU;wo_nms表示不带NMS后处理,是测速时使用
在这里插入图片描述

六.改源码

改main.cpp中的这些参数,改成自己装图片和模型的地址
在这里插入图片描述
在这里插入图片描述

注意这个参数的值不要改,它的备注显示这个参数已经被废弃,写成true会停止运行
在这里插入图片描述

七.添加dll到exe目录

如果exe文件同一目录没有加需要的动态库,会直接报错,由于找不到 paddle inference.dll,无法继续执行代码。重新安装程序可能会
解决此问题
,这种问题很简单解决,直接缺啥补啥就行
请添加图片描述
按照提示补好了的dll库是这样

在这里插入图片描述
然后再次运行
在这里插入图片描述
报错应用程序无法正常启动(0xc000007b)。请单击”确定”关闭应用程序,这样就很难弄了,不知道到底缺的是什么,但是可以说出现这种问题还是缺库

if (WIN32 AND WITH_MKL)
    add_custom_command(TARGET main POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/mklml.dll ./mklml.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/libiomp5md.dll ./libiomp5md.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mkldnn/lib/mkldnn.dll ./mkldnn.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/mklml.dll ./release/mklml.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mklml/lib/libiomp5md.dll ./release/libiomp5md.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/mkldnn/lib/mkldnn.dll ./release/mkldnn.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}.dll ./release/${PADDLE_LIB_NAME}.dll
    )
endif()

if (WIN32 AND NOT WITH_MKL)
    add_custom_command(TARGET main POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/openblas/lib/openblas.dll ./openblas.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/openblas/lib/openblas.dll ./release/openblas.dll
    )
endif()

if (WIN32)
    add_custom_command(TARGET main POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/onnxruntime/lib/onnxruntime.dll ./onnxruntime.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/paddle2onnx/lib/paddle2onnx.dll ./paddle2onnx.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/onnxruntime/lib/onnxruntime.dll ./release/onnxruntime.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/third_party/install/paddle2onnx/lib/paddle2onnx.dll ./release/paddle2onnx.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_DIR}/paddle/lib/${PADDLE_LIB_NAME}.dll ./release/${PADDLE_LIB_NAME}.dll
    )
endif()

在原cmakelists里面找到了玄机。这些都是可执行文件需要的dll
在这里插入图片描述
如果懒得看原代码,有个非常简单的方法
在这里插入图片描述
直接在这个项目依赖的第三方库里面找dll文件,全部放到exe同一文件夹就可以

bug记录

由于我下载模型的时候下载错了,只下载了一个pdparams文件,但是很无语的时候并不会有任何报错,只会运行完就停止了,没有报任何异常,看这个object_detector.cpp代码里只有函数实现,没有类实现,真的很奇怪,不知道如何排查哪里出的问题,后来我发现这个类实现在了头文件里,排查到了是我模型的原因。

打注释小窍门

在前面定义这个,然后在需要打印的地方直接输Dlog(你想打印的内容)就可以直接打印。不用每次都cout,endl

#define Dlog(x) std::cout<<x<<std::endl

查bug小窍门

exe文件运行后无输出直接闪退如何找解决办法
搜索栏搜事件查看器
在这里插入图片描述
在这里插入图片描述
找到错误处
在这里插入图片描述
点开有错误的详细信息,直接用搜索引擎搜索这个异常代码能大致判断是什么问题,给了一个解决思路,不至于不知道到底哪里出了问题
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1049161.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数码配件商城搭建教程:一步一步实现自己的小程序商城

在如今数字化的时代&#xff0c;电子商务成为了一种非常重要的商业模式。而随着移动互联网的发展&#xff0c;小程序商城成为了许多企业和个人创业者的选择。本文将介绍如何使用乔拓云平台搭建一个数码配件商城的小程序&#xff0c;并实现自己的商业梦想。 第一步&#xff1a;登…

raw图片处理推荐 DxO PhotoLab 6 for Mac中文最新

DxO PhotoLab 6是一款专业的RAW图片处理软件&#xff0c;适用于Mac操作系统。它具有先进的图像处理技术和直观易用的界面&#xff0c;可帮助用户轻松地将RAW格式的照片转换为高质量的JPEG或TIFF图像。以下是对DxO PhotoLab 6软件的详细介绍&#xff1a; RAW图像处理&#xff1…

python监控ES索引数量变化

文章目录 1, datafram根据相同的key聚合2, 数据合并&#xff1a;获取采集10,20,30分钟es索引数据脚本测试验证 1, datafram根据相同的key聚合 # 创建df1 > json {key:A, value:1 } {key:B, value:2 } data1 {key: [A, B], value: [1, 2]} df1 pd.DataFrame(data1)# 创建d…

【广州华锐互动】奶牛养殖难产助产3D沉浸式教学平台

在传统的奶牛难产助产教学中&#xff0c;主要依赖理论知识和2D图像来进行教学。然而&#xff0c;这种教学方式往往无法全面、真实地展示奶牛难产的各种情况&#xff0c;教学效果也不尽如人意。随着科技的发展&#xff0c;3D互动教学的出现&#xff0c;为奶牛难产助产教学带来了…

TextMeshPro创建中文资源出现内容不全的问题记录

原因可能是出现乱码了&#xff0c;如下图3500的汉字没有乱码可以创建成功&#xff0c;但7000的汉字创建时没有乱码的能创建出来&#xff0c;乱码的内容在创建出来的资源里不存在。

rk3568 weston 桌面相关

rk3568 weston 桌面相关 1、Weston 桌面参考链接 https://www.mankier.com/5/weston.ini#Output_Section 2、查看显示设备 输入 ls /sys/class/drm 命令&#xff0c;以MIPI 屏为例。 3、调整屏幕方向 修改 /etc/xdg/weston/weston.ini 文件 [output] nameDSI-1 //与上面列…

亿发连锁商超新零售解决方案提供商,提供定制新零售管理系统

时代的发展带动了经济环境的变化&#xff0c;为迎合市场经济的发展需求&#xff0c;数字化收银逐渐融入到大中生活中&#xff0c;中小型商铺都倾向于使用智慧收银系统取代传统收银模式。新零售系统成为了商家在竞争激烈的市场中立足的关键。但随之也带来了数不尽的竞争压力&…

openlayers-18-聚合显示补充(切换聚合与非聚合状态)

最近有一些网友问我&#xff0c;聚合显示怎么实现聚合与不聚合之间的切换&#xff0c;有很多方法能够实现&#xff0c;下面是一个示例作为参考。 <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-…

怎么保护苹果手机移动应用程序ios ipa文件中的代码?

目录 前言 代码混淆步骤 1. 选择要混淆保护的ipa文件 2. 选择要混淆的类名称 3. 选择要混淆保护的函数&#xff0c;方法 4. 配置签名证书 5. 混淆和测试运行 前言 在当今移动应用市场竞争激烈的环境中&#xff0c;代码保护功能对于iOS应用程序的成功非常关键。代码保护可…

不同走向地下管线的地质雷达响应特征分析

不同走向地下管线的地质雷达响应特征分析 前言 以PVC管线为例&#xff0c;建立不同走向&#xff08;水平倾斜、垂直倾斜、水平相邻&#xff09;的三维管线地质模型&#xff0c;进行三维地质雷达数据模拟&#xff0c;分析不同走向地下管线的地质雷达响应特征。 文章目录 不同…

【AntDesign】封装全局异常处理-全局拦截器

[toc] 场景 本文前端用的是阿里的Ant-Design框架&#xff0c;其他框架也有全局拦截器&#xff0c;思路是相同&#xff0c;具体实现自行百度下吧 因为每次都需要调接口&#xff0c;都需要单独处理异常情况&#xff08;code !0&#xff09;&#xff0c;因此前端需要对后端返回的…

vue3-ts-vite:Google 多语言调试 / 网页中插入谷歌翻译元素 / 翻译

一、实现目标 二、代码实现 2.1、项目vue3 - ts - vite 2.2、index.html 引入文件 <script>window.onload function () {const script document.createElement(SCRIPT)script.src https://translate.google.com/translate_a/element.js?cbgoogleTranslateElementI…

ROS的通信机制

ROS是一个分布式框架&#xff0c;为用户提供多节点&#xff08;进程&#xff09;之间的通信服务&#xff0c;所有软件功能和工 具都建立在这种分布式通信机制上&#xff0c;所以ROS的通信机制是最底层也是最核心的技术。在大多数应用场景下&#xff0c;尽管我们不需要关注底层通…

缓冲技术在嵌入式中的应用

引言 在嵌入式中&#xff0c;不可避免地会遇到数据的收发。 其实&#xff0c;数据的收发有很多情况。 总体上&#xff0c;分为数据的收和发&#xff1a; 其中&#xff0c;数据发送是一个主动的行为&#xff0c;我们对要发送数据的数量特点等都是知道的&#xff0c;比如我们通过…

通俗讲解深度学习轻量网络MobileNet-v1/v2/v3

MobileNet网络是由google团队在2017年提出的&#xff0c;专注于移动端或者嵌入式设备中的轻量级CNN网络。相比传统卷积神经网络&#xff0c;在准确率小幅降低的前提下大大减少模型参数与运算量。(相比VGG16准确率减少了0.9%&#xff0c;但模型参数只有VGG的1/32)。MobileNet网络…

读取.nrrd和.dcm文件格式医学图片可视化与预处理

nrrd数据格式 MITK默认会将医学图像保存为格式为NRRD的图像&#xff0c;在这个数据格式中包含&#xff1a; 1、一个单个的数据头文件&#xff1a;为科学可视化和医学图像处理准确地表示N维度的栅格信息。 2、既能分开又能合并的图像文件。 nrrd_options输出 {u’dimension’:…

CoreData/数据存储管理, CoreDataRelationships/关系型数据结构存储管理 的使用

1. CoreData 数据的增删改查操作 1.1 创建数据实体管理文件 点击菜单栏 File -> New -> File... -> Core Data 栏下&#xff0c;选择 Data Mode&#xff0c;创建 FruitsContainer.xcdatamodeld 文件 1.2 创建 FruitEntity 实体表 打开 FruitsContainer.xcdatamodeld 文…

Quartus医院病房呼叫系统病床呼叫Verilog,源代码下载

名称&#xff1a;医院病房呼叫系统病床呼叫 软件&#xff1a;Quartus 语言&#xff1a;Verilog 要求&#xff1a; 1、用1~6个开关模拟6个病房的呼叫输入信号,1号优先级最高;1~6优先级依次降低; 2、 用一个数码管显示呼叫信号的号码;没信号呼叫时显示0;有多个信号呼叫时,显…

2023年鄂州中级职称申报时间是什么时候呢?

鄂州在6.7月份组织了一次水平能力测试&#xff0c;鄂州中级职称申报时间终于出来了&#xff0c;关于鄂州中级职称申报的一些情况&#xff0c;甘建二告诉你&#xff1a; 一、鄂州中级职称申报时间&#xff1a; 1.网上申报审核时间。个人申报2023年09月27日至2023年10月10日&…

单链表操作 C实现

struct LNode { //定义一个节点 int data; //数据域 struct LNode *next; //指针域 }; 0.初始化 typedef sturct LNode{ //定义单链表结点类型 int date ; //每个结点存放一个数据元素struct LNode *next; //指针指向下…