您当前的位置: 首页 >  opencv

我什么都布吉岛

暂无认证

  • 1浏览

    0关注

    292博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

(五)CMake与OpenCV

我什么都布吉岛 发布时间:2020-11-16 11:43:48 ,浏览量:1

直接看CMakeLists.txt是怎么写的吧![1]

# cmake needs this line
cmake_minimum_required(VERSION 2.8)

# Define project name
project(opencvTest)

# 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)

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

# Add OpenCV headers location to your include paths
include_directories(${OpenCV_INCLUDE_DIRS})

# Declare the executable target built from your sources
add_executable(main main.cpp)

# Link your application with OpenCV libraries
target_link_libraries(main ${OpenCV_LIBS})

首先通过find_package语句找到CMake所需要的所有变量如:

  • OpenCV_VERSION
  • OpenCV_LIBS
  • OpenCV_INCLUDE_DIRS

接下来他和普通的头文件、库的引用就没有什么区别了:

  • 头文件支持:include_directories(${OpenCV_INCLUDE_DIRS})
  • 库文件连接:target_link_libraries(main ${OpenCV_LIBS})

参考文章,有不同版本的OpenCV的指定方法,其实就是将变量设置一下,仅此而已。

[1] https://www.cnblogs.com/tsvico/p/11877933.html

关注
打赏
1658157489
查看更多评论
立即登录/注册

微信扫码登录

0.0356s