我在 Android Studio 中创建了一个本机应用程序,它为我生成了所有 gradle 和 CMakeLists.txt 文件。当我在其中添加 find_package() 时,它会显示以下内容:
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
但是当我在另一个不是 Android Studio 项目的目录中创建 CMakeLists.txt 文件时,我可能会在终端中运行 cmake 命令,它将能够找到 OpenCV 包。
这是 CMakeLists.txt 文件内容:
cmake_minimum_required(VERSION 3.16)
project(CVExample)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(my_run my_run.cpp)
target_link_libraries(my_run PRIVATE ${OpenCV_LIBS})
问题:为什么我在 Android Studio 中找不到 OpenCV 包?
注意:我使用的操作系统是 MacOS,OpenCV 是使用 brew 安装的