一、用QtCreator创建一个项目
1、新建项目
2、选择项目类型
3、修改项目名和项目存放地址
4、接下来都选择下一步,直到项目生成成功
二、项目创建成功后,开始写opencv小程序
1、在pro配置文件中加入opencv库目录
INCLUDEPATH += /usr/local/include \
/usr/local/include/opencv \
/usr/local/include/opencv2
- 1
- 2
- 3
LIBS += /usr/local/lib/libopencv_calib3d.so \
/usr/local/lib/libopencv_core.so \
/usr/local/lib/libopencv_features2d.so \
/usr/local/lib/libopencv_flann.so \
/usr/local/lib/libopencv_highgui.so \
/usr/local/lib/libopencv_imgcodecs.so \
/usr/local/lib/libopencv_imgproc.so \
/usr/local/lib/libopencv_ml.so \
/usr/local/lib/libopencv_objdetect.so \
/usr/local/lib/libopencv_photo.so \
/usr/local/lib/libopencv_shape.so \
/usr/local/lib/libopencv_stitching.so \
/usr/local/lib/libopencv_superres.so \
/usr/local/lib/libopencv_videoio.so \
/usr/local/lib/libopencv_video.so \
/usr/local/lib/libopencv_videostab.so
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
qt下opencv配置完成
3、在main.cpp编写第一个opencv小程序,显示一张图片
#include<cstdlib>
#include<iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc,char* argv[])
{
cv::Mat img; //定义一个Mat变量
img = cv::imread("/home/1.jpg"); //读取图片
cv::imshow("window",img); //显示图片
cv::waitKey(0);
return 0;
}
- 15
三、Qt下caffe的配置
1、在pro配置文件加入caffe库目录
INCLUDEPATH += caffe的主目录/include \
caffe的主目录/build/src
#caffe的库目录每个人根据自己目录填写,例如/home/caffe
- 3
LIBS += -L caffe的主目录/build/lib \
LIBS += lcaffe
- 2
注意:libcaffe.so.1.0.0-rc3根据caffe的版本确定,要进入那个lib目录下看下它的名称,改成和它一样。
3、pro下cuda、cudnn的配置(注意只有安装cuda或cudnn才进行配置此步骤)
INCLUDEPATH += /usr/local/cuda/include \
LIBS += -L/usr/local/cuda/lib64
LIBS += -lcudart -lcublas -lcurand
- 3
4、pro文件中caffe相关依赖项的加入
LIBS += -lglog -lgflags -lprotobuf -lboost_system -lboost_thread -llmdb -lleveldb -lstdc++ -lcblas -latlas
- 1
5、经过上面配置,qtcreator下caffe配置完成。