简介
本文将基于
- jetson nano 4G
- win10
- ubuntu18
三种环境介绍,如果想在QT或CPP中使用tensorrt cuda opencv部署深度學習模型,CMAKE和QT的pro文件怎么写
jetson nano
opencv是用apt-get安装的opencv4
cuda内置10.2
tensorrt内置7.1.3
QT pro
#-------------------------------------------------
#
# Project created by QtCreator 2021-09-01T23:32:22
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = demo_opencv
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
widget.cpp
HEADERS += \
widget.h
FORMS += \
widget.ui
#opencv
INCLUDEPATH += /usr/include/opencv4/
LIBS += /usr/lib/aarch64-linux-gnu/libopencv_calib3d.so \
/usr/lib/aarch64-linux-gnu/libopencv_core.so \
/usr/lib/aarch64-linux-gnu/libopencv_features2d.so \
/usr/lib/aarch64-linux-gnu/libopencv_flann.so \
/usr/lib/aarch64-linux-gnu/libopencv_highgui.so \
/usr/lib/aarch64-linux-gnu/libopencv_imgcodecs.so \
/usr/lib/aarch64-linux-gnu/libopencv_imgproc.so \
/usr/lib/aarch64-linux-gnu/libopencv_ml.so \
/usr/lib/aarch64-linux-gnu/libopencv_objdetect.so \
/usr/lib/aarch64-linux-gnu/libopencv_photo.so \
/usr/lib/aarch64-linux-gnu/libopencv_stitching.so \
/usr/lib/aarch64-linux-gnu/libopencv_videoio.so \
/usr/lib/aarch64-linux-gnu/libopencv_video.so
# cuda
INCLUDEPATH +=/usr/local/cuda/include/
LIBS += -L/usr/local/cuda/lib64/
LIBS += -lcudart
CUDA_USE_STATIC_CUDA_RUNTIME=OFF
# tensorrt
INCLUDEPATH +=/usr/include/aarch64-linux-gnu/
LIBS += -L/usr/lib/aarch64-linux-gnu/
LIBS += -lnvinfer
CmakeList
cmake_minimum_required(VERSION 2.6)
project(alphapose)
add_definitions(-std=c++11)
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)
find_package(CUDA REQUIRED)
include_directories(${PROJECT_SOURCE_DIR}/include)
# include and link dirs of cuda and tensorrt, you need adapt them if yours are different
# cuda
include_directories(/usr/local/cuda/include)
link_directories(/usr/local/cuda/lib64)
# tensorrt
include_directories(/usr/include/aarch64-linux-gnu/)
link_directories(/usr/lib/aarch64-linux-gnu/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")
find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(alphapose ${PROJECT_SOURCE_DIR}/fastpose.cpp)
target_link_libraries(alphapose nvinfer)
target_link_libraries(alphapose cudart)
target_link_libraries(alphapose ${OpenCV_LIBS})
add_executable(csicamera ${PROJECT_SOURCE_DIR}/csicamera.cpp)
target_link_libraries(csicamera ${OpenCV_LIBS})
if(UNIX)
add_definitions(-O2 -pthread)
endif(UNIX)
win10
opencv是github下载的编译好的4.5.1
cuda11.1
cudnn8.0.5
tensorrt7.2.2.3
CmakeList
cmake_minimum_required(VERSION 2.6)
project(yolov5)
add_definitions(-std=c++11)
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -D_MWAITXINTRIN_H_INCLUDED")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
# setup CUDA
find_package(CUDA REQUIRED)
message(STATUS " libraries: ${CUDA_LIBRARIES}")
message(STATUS " include path: ${CUDA_INCLUDE_DIRS}")
include_directories(${CUDA_INCLUDE_DIRS})
enable_language(CUDA) # add this line, then no need to setup cuda path in vs
set(TRT_DIR "D:/TensorRT-7.2.2.3") #4
include_directories(${TRT_DIR}/include)
set(OpenCV_DIR "D:/CProjects/opencv/build/x64/vc15/lib")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${TRT_DIR}/lib) #7
add_executable(fastpose ${PROJECT_SOURCE_DIR}/fastpose.cpp) #4
target_link_libraries(fastpose nvinfer nvinfer_plugin) #9
target_link_libraries(fastpose ${OpenCV_LIBS}) #10
target_link_libraries(fastpose ${CUDA_LIBRARIES}) #11
ubuntu 18
opencv是apt-get安装的
cuda11.1
cudnn8.0.5
tensorrt7.2.2.3
QT pro
#-------------------------------------------------
#
# Project created by QtCreator 2021-09-02T23:13:12
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = demo-opencv
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
widget.cpp
HEADERS += \
widget.h \
logging.h \
cuda_utils.h
FORMS += \
widget.ui
# opencv
LIBS += /usr/lib/x86_64-linux-gnu/libopencv_core.so \
/usr/lib/x86_64-linux-gnu/libopencv_features2d.so \
/usr/lib/x86_64-linux-gnu/libopencv_flann.so \
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so \
/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so \
/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so \
/usr/lib/x86_64-linux-gnu/libopencv_ml.so \
/usr/lib/x86_64-linux-gnu/libopencv_objdetect.so \
/usr/lib/x86_64-linux-gnu/libopencv_photo.so \
/usr/lib/x86_64-linux-gnu/libopencv_shape.so \
/usr/lib/x86_64-linux-gnu/libopencv_stitching.so \
/usr/lib/x86_64-linux-gnu/libopencv_superres.so \
/usr/lib/x86_64-linux-gnu/libopencv_videoio.so \
/usr/lib/x86_64-linux-gnu/libopencv_video.so \
/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so \
/usr/lib/x86_64-linux-gnu/libopencv_videostab.so
# cuda
INCLUDEPATH += /usr/local/cuda/include/
LIBS += -L/usr/local/cuda/lib64/
LIBS +=-lcudart
CUDA_USE_STATIC_CUDA_RUNTIME=OFF
# tensorrt
INCLUDEPATH += /home/leo/TensorRT-7.2.2.3/include/
LIBS += -L/home/leo/TensorRT-7.2.2.3/lib/
LIBS += -lnvinfer
CmakeList
cmake_minimum_required(VERSION 2.6)
project(yolov5)
add_definitions(-std=c++11)
add_definitions(-DAPI_EXPORTS)
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)
find_package(CUDA REQUIRED)
if(WIN32)
enable_language(CUDA)
endif(WIN32)
include_directories(${PROJECT_SOURCE_DIR}/include)
# include and link dirs of cuda and tensorrt, you need adapt them if yours are different
# cuda
include_directories(/usr/local/cuda/include)
link_directories(/usr/local/cuda/lib64)
# tensorrt
include_directories(/home/leo/TensorRT-7.2.2.3/include)
link_directories(/home/leo/TensorRT-7.2.2.3/lib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")
find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})
message("OpenCV_INCLUDE_DIRS=${OpenCV_INCLUDE_DIRS}")
message("OpenCV_LIBS=${OpenCV_LIBS}")
add_executable(fastpose ${PROJECT_SOURCE_DIR}/fastpose.cpp)
target_link_libraries(fastpose nvinfer)
target_link_libraries(fastpose cudart)
target_link_libraries(fastpose ${OpenCV_LIBS})
if(UNIX)
add_definitions(-O2 -pthread)
endif(UNIX)