操作系统: ubuntu16.04 32bit
Qt环境: Qt 5.5.0
1.下载opencv地址: https://github.com/opencv/opencv.git
2.下载一些类包及编译工具
安装编译工具 sudo apt-get install build-essential
安装依赖包 sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
安装可选包 sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
2.解压后,在当前目录下
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .
make
sudo make install
3.在系统/etc/ld.so.conf.d下创建文件OpenCV.conf,向其中写入:
/usr/local/lib
ps:该路径为opencv install的路径,一般默认是/usr/local/lib
在终端执行命令:
sudo ldconfig
为什么要加上这一步?请参考文档:http://blog.csdn.net/lql0716/article/details/54434695
3.在Qt中创建一个项目,在pro文件中添加:
INCLUDEPATH += /usr/local/include /usr/local/include/opencv /usr/local/include/opencv2
LIBS += /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_objdetect.so \
/usr/local/lib/libopencv_calib3d.so.3.2 /usr/local/lib/libopencv_objdetect.so.3.2 \
/usr/local/lib/libopencv_calib3d.so.3.2.0 /usr/local/lib/libopencv_objdetect.so.3.2.0 \
/usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_photo.so \
/usr/local/lib/libopencv_core.so.3.2 /usr/local/lib/libopencv_photo.so.3.2 \
/usr/local/lib/libopencv_core.so.3.2.0 /usr/local/lib/libopencv_photo.so.3.2.0 \
/usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_shape.so \
/usr/local/lib/libopencv_features2d.so.3.2 /usr/local/lib/libopencv_shape.so.3.2 \
/usr/local/lib/libopencv_features2d.so.3.2.0 /usr/local/lib/libopencv_shape.so.3.2.0 \
/usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_stitching.so \
/usr/local/lib/libopencv_flann.so.3.2 /usr/local/lib/libopencv_stitching.so.3.2 \
/usr/local/lib/libopencv_flann.so.3.2.0 /usr/local/lib/libopencv_stitching.so.3.2.0 \
/usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_superres.so \
/usr/local/lib/libopencv_highgui.so.3.2 /usr/local/lib/libopencv_superres.so.3.2 \
/usr/local/lib/libopencv_highgui.so.3.2.0 /usr/local/lib/libopencv_superres.so.3.2.0 \
/usr/local/lib/libopencv_imgcodecs.so /usr/local/lib/libopencv_videoio.so \
/usr/local/lib/libopencv_imgcodecs.so.3.2 /usr/local/lib/libopencv_videoio.so.3.2 \
/usr/local/lib/libopencv_imgcodecs.so.3.2.0 /usr/local/lib/libopencv_videoio.so.3.2.0 \
/usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_video.so \
/usr/local/lib/libopencv_imgproc.so.3.2 /usr/local/lib/libopencv_video.so.3.2 \
/usr/local/lib/libopencv_imgproc.so.3.2.0 /usr/local/lib/libopencv_video.so.3.2.0 \
/usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_videostab.so \
/usr/local/lib/libopencv_ml.so.3.2 /usr/local/lib/libopencv_videostab.so.3.2 \
/usr/local/lib/libopencv_ml.so.3.2.0 /usr/local/lib/libopencv_videostab.so.3.2.0
开始编写第一个opencv程序:
#include <iostream>
using namespace std;
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{
Mat image;
image = imread( "/home/fish/Pictures/cat.png");
namedWindow( "cat" );
imshow( "cat", image );
waitKey(60000);
return 0;
}
运行成功。