当前位置:   article > 正文

Could not find a package configuration file provided by “OpenCV“

could not find a package configuration file provided by "opencv" with any of

问题1:  cmake 进行 c/c++ 联合opencv编译时出现

  Could not find a package configuration file provided by "OpenCV" with any
  of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake


原始CMakeLists.txt

  1. cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
  2. project(trans)
  3. find_package(OpenCV REQUIRED)
  4. # Print some message showing some of them
  5. message(STATUS "OpenCV library status:")
  6. message(STATUS " config: ${OpenCV_DIR}")
  7. message(STATUS " version: ${OpenCV_VERSION}")
  8. message(STATUS " libraries: ${OpenCV_LIBS}")
  9. message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
  10. add_executable(Transform Transform.cpp)
  11. target_link_libraries(Transform "${OpenCV_LIBS}")

解决方案:

  1. # locate 全局搜索一下该文件,没有locate可以 apt install locate
  2. >> locate OpenCVConfig.cmake
  3. 搜索结果会出现很多,选择安装路径下对应的OpenCVConfig.cmake 即可。
  4. 本文安装了两个版本,选择自己对应的即可。
  5. /usr/local/opencv/3.4.9/share/OpenCV/OpenCVConfig.cmake
  6. /usr/local/opencv/4.5.1/lib/cmake/opencv4/OpenCVConfig.cmake
  7. opencv3 和 opencv4 的OpenCVConfig.cmake位置不一样,请确定自己版本对症用药。

在CMakeLists.txt中用 

set(OpenCV_DIR /usr/local/opencv/4.5.1/lib/cmake/opencv4/)

指定对应的OpenCVConfig.cmake路径即可。

  1. cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
  2. project(trans)
  3. # 指定opencv 对应的OpenCVConfig.cmake 文件目录。 opencv4 不在share目录下。
  4. # 可以用locate OpenCVConfig.cmake 全局搜索下该文件
  5. set(OpenCV_DIR /usr/local/opencv/4.5.1/lib/cmake/opencv4/)
  6. # 这里的OpenCV 会对应查找 OpenCVConfig.cmake 文件
  7. find_package(OpenCV REQUIRED)
  8. # Print some message showing some of them
  9. message(STATUS "OpenCV library status:")
  10. message(STATUS " config: ${OpenCV_DIR}")
  11. message(STATUS " version: ${OpenCV_VERSION}")
  12. message(STATUS " libraries: ${OpenCV_LIBS}")
  13. message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
  14. add_executable(Transform Transform.cpp)
  15. # target_link_libraries(CrnnEval_batch ${OpenCV_LIBS})
  16. target_link_libraries(Transform "${OpenCV_LIBS}")
  17. # set_property(TARGET lltm PROPERTY CXX_STANDARD 11)

问题2: cmake ncnn + opencv4.x 联合编译demo时出现

运行命令:  cmake -DCMAKE_BUILD_TYPE=Release -DNCNN_VULKAN=ON -DNCNN_BUILD_EXAMPLES=ON ..

CMake Warning at examples/CMakeLists.txt:72 (message):
  OpenCV not found and NCNN_SIMPLEOCV disabled, examples won't be built

修改后命令:

cmake -DCMAKE_BUILD_TYPE=Release -DNCNN_VULKAN=ON -DNCNN_BUILD_EXAMPLES=ON -DOpenCV_DIR=/usr/local/opencv/4.5.1/lib/cmake/opencv4/ ..

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/292921
推荐阅读
相关标签
  

闽ICP备14008679号