OpenCV3.4+DarkNet+KCF在linux下编译

对于单文件的编译
目录结构为

----------main.cpp

写一个CMakeLists.txt文件
内容为
cmake_minimum_required(VERSION 3.10.2) #----可以通过cmake -version查看
project(kcfAndDarknet)
add_executable(demo main.cpp)

  1. cmake_minimum_required:指定运行此配置文件所需的 CMake 的最低版本;
  2. project:参数值是 Demo1,该命令表示项目的名称是 Demo1 。
  3. add_executable: 将名为 main.cpp 的源文件编译成一个名称为 demo 的可执行文件。
    运行时通过 ./demo

多源多目录等基本cmake操作可以参考该博客https://blog.csdn.net/libaineu2004/article/details/78995740

本项目是使用英伟达嵌入式平台Jetson AGX开发套件,使用opencv里面的darknet库进行检测目标框,使用kcf算法进行跟踪,将opencv+darknet+kcf算法进行混编,在kcf算法中添加darknet库和opencv库的依赖项。
下面介绍一下如何进行编译:
我的主函数为runtracker.cpp

目录结构为

runtracker.cpp
kcftracker(子文件夹)
ffttools.hpp fhog.hpp fhog.cpp kcftracker.cpp
kcftracker.hpp rectools.hpp tracker.h labdata.hpp
在这里插入图片描述OpenCV3.4+DarkNet+KCF在linux下编译_第1张图片
OpenCV3.4+DarkNet+KCF在linux下编译_第2张图片
是因为我的runtracker.cpp文件中包含头文件
OpenCV3.4+DarkNet+KCF在linux下编译_第3张图片
kcftracker.hpp包含
OpenCV3.4+DarkNet+KCF在linux下编译_第4张图片

首先在根目录添加darknet,opencv以及runtracker所依赖的hpp文件。

# cmake needs this line
cmake_minimum_required(VERSION 3.10.2)
 
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(ROOT_DIR /home/nvidia/dx/darknet_ori/darknet)
# Define project name
project(kcfAndDarknet)
 
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED) 

#serve valiad DIR_SRCS
#aux_source_directory(. DIR_SRCS)

#add kcftracker library
add_subdirectory(kcftracker)
 
include_directories( ${OpenCV_INCLUDE_DIRS} )  
# Declare the executable target built from your sources
add_executable(demo runtracker.cpp)
 
include_directories(${ROOT_DIR})


target_link_libraries(demo kcftracker)


# Link your application with OpenCV libraries
target_link_libraries(demo ${OpenCV_LIBS})
target_link_libraries(demo ${ROOT_DIR}/libdarknet.a ${ROOT_DIR}/libdarknet.so)
target_link_libraries(demo /home/nvidia/dx/kcfAndDarknet/kcftracker/libkcftracker.a)



子文件夹中


cmake_minimum_required(VERSION 3.10.2)
 
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

find_package(OpenCV REQURED)

include_directories(${OpenCV_INCLUDE_DIRS})

aux_source_directory(. DIR_LIB_SRCS)

add_library(kcftracker ${DIR_LIB_SRCS})


你可能感兴趣的:(cmake)