既然你坚持将 opencv 保留在你的项目树中
这是更简单的方法,但我只想以这种方式进行。
这是肯定可以与您在问题中发布的项目树配合使用的解决方案opencv-3.4.1 https://github.com/opencv/opencv/tree/3.4.1。为了简单起见,我将忽略dlib
图书馆和Qt
依赖性,因为你对此没有任何问题。
Root CMakeLists.txt
应有以下内容:
cmake_minimum_required(VERSION 2.8.11) # or anything higher, if you wish
project(recognition-node CXX)
add_subdirectory(node)
The CMakeLists.txt
在下面node
目录应包含以下内容:
add_subdirectory(third_party)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g") # or any other additional flags
# at this point you can add find_package(Qt5Widgets REQUIRED) and later link your binary against Qt5::widgets as well
add_executable(myExec main.cpp
# and put here all the other source files of your project ...
)
# for linking libs I have put additionally highgui and imgproc to check the solution against OpenCV official sample
target_link_libraries(myExec opencv_core opencv_highgui opencv_imgproc)
target_include_directories(myExec PUBLIC
third_party/opencv/modules/calib3d/include
third_party/opencv/modules/core/include
third_party/opencv/modules/cudaarithm/include
third_party/opencv/modules/cudabgsegm/include
third_party/opencv/modules/cudacodec/include
third_party/opencv/modules/cudafeatures2d/include
third_party/opencv/modules/cudafilters/include
third_party/opencv/modules/cudaimgproc/include
third_party/opencv/modules/cudalegacy/include
third_party/opencv/modules/cudaobjdetect/include
third_party/opencv/modules/cudaoptflow/include
third_party/opencv/modules/cudastereo/include
third_party/opencv/modules/cudawarping/include
third_party/opencv/modules/cudev/include
third_party/opencv/modules/dnn/include
third_party/opencv/modules/features2d/include
third_party/opencv/modules/flann/include
third_party/opencv/modules/highgui/include
third_party/opencv/modules/imgcodecs/include
third_party/opencv/modules/imgproc/include
third_party/opencv/modules/ml/include
third_party/opencv/modules/objdetect/include
third_party/opencv/modules/photo/include
third_party/opencv/modules/shape/include
third_party/opencv/modules/stitching/include
third_party/opencv/modules/superres/include
third_party/opencv/modules/ts/include
third_party/opencv/modules/video/include
third_party/opencv/modules/videoio/include
third_party/opencv/modules/videostab/include
third_party/opencv/modules/viz/include
third_party/opencv/modules/world/include
)
The CMakeLists.txt
under third_party
应仅包含:
add_subdirectory(opencv)
# add_subdirectory(dlib) # if you will use dlib, of course also add dlib
我用来验证构建的示例是轮廓2.cpp https://docs.opencv.org/3.4.1/d0/d2a/contours2_8cpp-example.html(只需将内容复制粘贴到main.cpp
).
然而,我仍然认为使用这个解决方案是一个糟糕的主意。
- OpenCv 确实需要很多时间来编译
- 你必须手动添加包含目录(你可以使用一些宏生成器,但通常它看起来更难看)
- 在你的构建系统中,你有很多你并不真正需要的目标(超过 300 个),包括
install
target
所以,我的建议是:如果你愿意,可以将此解决方案用于科学目的,但当你真正需要使用它时,只需在系统上(或在本地,如果你不是管理员)编译和安装 OpenCv 即可。