1. 官网下载opencv源文件,我下载的是 opencv-3.4.2.zip
2. 根据 https://blog.csdn.net/cocoaqin/article/details/78163171中一步步操作
但是我按照上文中第4步(如下)输入时,出现报错
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
于是我改成分开输入,发现是安装libtiff4.dev 有问题,改成安装libtiff5-dev,可能是版本不一样
总体上将上文改成
sudo apt-get install build-essential
sudo apt-get install libgtk2.0-dev
sudo apt-get install libavcodec-dev
sudo apt-get install libavformat-dev
sudo apt-get install libjpeg.dev
sudo apt-get install libtiff5-dev
sudo apt-get install libswscale-dev
sudo apt-get install libjasper-dev
后续其他操作仍按照上文进行,最后能成功运行文中的example,算是成功了。
3. 引用安装的opencv中的库文件,创建测试程序
安装的库文件在
/usr/local
本人使用的是Qtcreator,创建Qt console Application,下面是.pro文件和main.cpp
//.pro文件
QT += core
QT -= gui
TARGET = Test_opencv
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
INCLUDEPATH += /usr/local/include \
/usr/local/include/opencv \
/usr/local/include/opencv2
LIBS += /usr/local/lib/libopencv_highgui.so \
/usr/local/lib/libopencv_core.so \
/usr/local/lib/libopencv_imgproc.so \
/usr/local/lib/libopencv_imgcodecs.so
TEMPLATE = app
SOURCES += main.cpp
//main.cpp
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main()
{
Mat a(Size(3,3),CV_8UC1);
cout<<a;
return 0;
}
本人也是刚接触opencv,写此文章以备忘。