• opencv3在CMakeLists.txt中的调用问题


    在cmake工程中使用opencv需要在CMakeLists.txt文件中加以调用,在opencv2.xx版本,可以用以下语句

    # 寻找OpenCV库
    find_package( OpenCV REQUIRED )
     
    # 添加头文件
    include_directories(  ${OpenCV_INCLUDE_DIRS}  )
    
    add_executable( xxx xxx.cpp )
    
    # 链接OpenCV库
    target_link_libraries( xxx ${OpenCV_LIBS}  )

    但如果你使用的是OpenCV 3.x版本,再用上面的方法就会报错

    CMake Warning at /home/zn/opencv-3.1.0/cmake/OpenCVConfig.cmake:166 (message):
      Found OpenCV Windows Pack but it has no binaries compatible with your
      configuration.
    
      You should manually point CMake variable OpenCV_DIR to your build of OpenCV
      library.
    Call Stack (most recent call first):
      CMakeLists.txt:11 (find_package)
    
    
    CMake Error at CMakeLists.txt:11 (find_package):
      Found package configuration file:
    
        /home/zn/opencv-3.1.0/cmake/OpenCVConfig.cmake
    
      but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
      NOT FOUND.
    
    
    -- Configuring incomplete, errors occurred!

    从上面的报错可以看出在OpenCVConfig.cmake文件中设置OpenCV_FOUND to FALSE,故find_package( OpenCV REQUIRED )是不可用的。我认为这是opencv3.x版本对opencv2.x版本的屏蔽,以防混用。要使用opencv3.x需要用如下语句

    # 寻找OpenCV库  我的版本的opencv3.1.0
    find_package( OpenCV 3.1  REQUIRED ) 
     
    # 添加头文件
    include_directories(  ${OpenCV_INCLUDE_DIRS}  )
    
    add_executable( xxx xxx.cpp )
    
    # 链接OpenCV库
    target_link_libraries( xxx ${OpenCV_LIBS}  )

    也就是要加上opencv对应的版本号就可以解决报错了。

  • 相关阅读:
    MISC | ctfshow 31
    010editor 没有分块高亮显示了
    BUUCTF | [网鼎杯 2020 朱雀组]phpweb
    python2与python3共存后,如何使用
    kali2020 装不上docker
    php代码审计整理
    [MRCTF2020]Ezpop
    kali没有tcptraceroute如何安装
    [BUUCTF] 真的很杂
    【弱网测试】备份弱网测试相关数据
  • 原文地址:https://www.cnblogs.com/feifanrensheng/p/8682311.html
Copyright © 2020-2023  润新知