环境:ubuntu16.04TLS、opencv3.3
按照百度上的安装教程安装完成后,发现2个问题。
1、执行网上的测试文件时候,发生错误,错误如下:
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.
接下来贴出我的测试方法
先创建一个文件,名为DisplayImage.cpp,代码如下:
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
然后是创建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} )
在执行 cmake . 的时候,发生了上面的错误,这个的解决方法有两种:
一种为修改CMakeLists.txt文件
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
set(OpenCV_DIR /home/zzz/software/opencv-3.3.0/release)
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
注:我是在opencv3.3目录下创建一个release文件夹
再次cmake . 就可以了编译了
第二种就是方法就是按照第二个问题来解决
2、执行执行pkg-config --modversion opencv命令时,没显示opencv的版本型号
前提是:环境安装正确
我是在在opencv3.3目录下创建一个release文件夹,打开release文件夹,使用cmake .. 命令和make install 命令,然后发现在opencv3.3目录下有一个build夹,把build文件夹里的bin、include、lib、share文件夹里的内容放到/usr/ 目录下相对应的文件夹里去,这个方法也可以解决第一个问题。
搞定睡觉