我已经安装了Opencv-3.2,我可以看到bin和lib文件
$ ls /share/apps/computer/opencv-3.2.0/built/bin/opencv_
opencv_annotation opencv_createsamples opencv_traincascade opencv_version opencv_visualisation
$ ls /share/apps/computer/opencv-3.2.0/built/lib/
libopencv_calib3d.so libopencv_imgcodecs.so.3.2.0 libopencv_stitching.so.3.2
libopencv_calib3d.so.3.2 libopencv_imgproc.so libopencv_stitching.so.3.2.0
libopencv_calib3d.so.3.2.0 libopencv_imgproc.so.3.2 libopencv_superres.so
libopencv_core.so libopencv_imgproc.so.3.2.0 libopencv_superres.so.3.2
libopencv_core.so.3.2 libopencv_ml.so libopencv_superres.so.3.2.0
libopencv_core.so.3.2.0 libopencv_ml.so.3.2 libopencv_videoio.so
libopencv_features2d.so libopencv_ml.so.3.2.0 libopencv_videoio.so.3.2
libopencv_features2d.so.3.2 libopencv_objdetect.so libopencv_videoio.so.3.2.0
libopencv_features2d.so.3.2.0 libopencv_objdetect.so.3.2 libopencv_video.so
libopencv_flann.so libopencv_objdetect.so.3.2.0 libopencv_video.so.3.2
libopencv_flann.so.3.2 libopencv_photo.so libopencv_video.so.3.2.0
libopencv_flann.so.3.2.0 libopencv_photo.so.3.2 libopencv_videostab.so
libopencv_highgui.so libopencv_photo.so.3.2.0 libopencv_videostab.so.3.2
libopencv_highgui.so.3.2 libopencv_shape.so libopencv_videostab.so.3.2.0
libopencv_highgui.so.3.2.0 libopencv_shape.so.3.2 pkgconfig/
libopencv_imgcodecs.so libopencv_shape.so.3.2.0
libopencv_imgcodecs.so.3.2 libopencv_stitching.so
现在,根据tutorial,我写了一个简单的程序。问题是,cmake
出现了一些错误,似乎无法找到库。
CMake Error at CMakeLists.txt:3 (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.
我不知道如何设置CMAKE_PREFIX_PATH
或OpenCV_DIR
。我该如何解决这个问题?
CMakeLists.txt的内容是
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
答案 0 :(得分:0)
这取决于您是否有安装OpenCV(即安装目录OpenCVConfig.cmake
下)附带的/share/apps/computer/opencv-3.2.0/built/
脚本。
如果您安装的OpenCV 缺少 OpenCVConfig.cmake
脚本,则需要使用脚本FindOpenCV.cmake
发送您的项目(查找并从中复制)网,几乎任何一个都适合),并将此脚本的目录添加到CMAKE_MODULE_PATH
变量:
list(APPEND CMAKE_MODULE_PATH <directory-with-find-script>)
提示CMake安装OpenCV的可能方法:
如果您有OpenCVConfig.cmake
脚本,请将OpenCV_DIR
变量设置为包含此脚本的目录:
cmake -DOpenCV_DIR=/share/apps/computer/opencv-3.2.0/built/<...>
将CMAKE_PREFIX_PATH
变量设置为OpenCV的安装前缀:
cmake -DCMAKE_PREFIX_PATH=/share/apps/computer/opencv-3.2.0/built
这适用于OpenCVConfig.cmake
和FindOpenCV.cmake
脚本。另请参阅该问题:Hinting Find<name>.cmake Files with a custom directory。