问题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
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(trans)
find_package(OpenCV REQUIRED)
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
add_executable(Transform Transform.cpp)
target_link_libraries(Transform "${OpenCV_LIBS}")
解决方案:
# locate 全局搜索一下该文件,没有locate可以 apt install locate
>> locate OpenCVConfig.cmake
搜索结果会出现很多,选择安装路径下对应的OpenCVConfig.cmake 即可。
本文安装了两个版本,选择自己对应的即可。
/usr/local/opencv/3.4.9/share/OpenCV/OpenCVConfig.cmake
/usr/local/opencv/4.5.1/lib/cmake/opencv4/OpenCVConfig.cmake
opencv3 和 opencv4 的OpenCVConfig.cmake位置不一样,请确定自己版本对症用药。
在CMakeLists.txt中用
set(OpenCV_DIR /usr/local/opencv/4.5.1/lib/cmake/opencv4/)
指定对应的OpenCVConfig.cmake路径即可。
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(trans)
# 指定opencv 对应的OpenCVConfig.cmake 文件目录。 opencv4 不在share目录下。
# 可以用locate OpenCVConfig.cmake 全局搜索下该文件
set(OpenCV_DIR /usr/local/opencv/4.5.1/lib/cmake/opencv4/)
# 这里的OpenCV 会对应查找 OpenCVConfig.cmake 文件
find_package(OpenCV REQUIRED)
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
add_executable(Transform Transform.cpp)
# target_link_libraries(CrnnEval_batch ${OpenCV_LIBS})
target_link_libraries(Transform "${OpenCV_LIBS}")
# 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/ ..