Opencv
https://github.com/opencv/opencv/archive/3.2.0.zip下载
二、安装常用依赖项:
1. sudo apt-get install build-essential libgtk2.0-dev libvtk5-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev libtbb-dev
三、安装 OpenCV 3.2:
1、将opencv-3.2.0.zip文件解压到任意目录(我解压到家目录~)
1. unzip opencv-3.2.0.zip -d ~/
2、切换到 OpenCV 3.2 目录下:
1. cd ~/opencv-3.2.0/
3、建立编译文件目录,并切换到该目录下:
一般在source下用cd命令转移到改目录(可以自行查询cd命令用法)
1. mkdir build
2.
3. cd build
4、开始编译(.. 为上层目录,不可缺少):
1. cmake ..
如果遇到这样的错误:-- ICV:Downloading ippicv_linux_20151201.tgz... CMake Error at3rdparty/ippicv/downloader.cmake:73 (file): file DOWNLOAD HASH mismatch
去这里(点击打开链接)下载ippicv_linux_20151201.tgz并粘贴(替换)到目录opencv-3.2.0/3rdparty/ippicv/downloads/Linux-808b791a6eac9ed78d32a7666804320e/
5、make -j4 (-j4表示开启4个线程编译,取决于CPU的速度,比如我make -j7)
1. make -j4
6、安装:默认安装到/usr/local下
1. sudo make install
测试
测试opencv
1) 创建工作目录
mkdir ~/opencv-lena
cd ~/opencv-lena
gedit DisplayImage.cpp
2) 编辑如下代码
#include<stdio.h>
#include<opencv2/opencv.hpp>
usingnamespace cv;
intmain(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage:DisplayImage.out <Image_Path>\n");
return-1;
}
Matimage;
image= imread( argv[1], 1 );
if ( !image.data )
{
printf("No imagedata \n");
return-1;
}
namedWindow("DisplayImage", WINDOW_AUTOSIZE );
imshow("DisplayImage", image);
waitKey(0);
return0;
}
3) 创建CMake编译文件
gedit CMakeLists.txt
写入如下内容
cmake_minimum_required(VERSION2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
4) 编译
cd ~/opencv-lena
cmake .
make
5) 执行
此时opencv-lena文件夹中已经产生了可执行文件DisplayImage,下载lena.jpg放在opencv-lena下,运行
./DisplayImage lena.jpg
qt安装
http://download.qt.io/development_releases/qt/5.8/5.8.0-rc/
_下载
.run的运行
cd /home/koudai/下载 (就是cd+你安装包的目录) chmod +x./(你.Run的名字注意命令和名字间各种空格).run sudo ./ (软件名字).run
用Qt创建我的第一个项目
注意点:创建一个控制台项目,最好将项目创建在 /tmp或者/~下,否则你会发现项目创建不成功。
第一个小测试代码如下:
[cpp] view plain copy
1. #include <QCoreApplication>
2. #include <opencv2/core/core.hpp>
3. #include <opencv2/highgui/highgui.hpp>
4. #include <opencv2/imgproc/imgproc.hpp>
5.
6. using namespace cv;
7.
8. int main(int argc, char *argv[])
9. {
10. QCoreApplication a(argc, argv);
11.
12. namedWindow( "src", WINDOW_AUTOSIZE );
13. Mat src1 = imread( "/tmp/untitled/lena.jpg" );
14.
15. imshow( "src", src1 );
16.
17. return a.exec();
18. }
然后注意需要将opencv的头文件和库文件与Qt关联起来,在项目的**.pro后面添加以下代码:
[plain] view plain copy
1. INCLUDEPATH += /usr/local/include \
2. /usr/local/include/opencv \
3. /usr/local/include/opencv2
4.
5. LIBS += /usr/local/lib/libopencv_highgui.so \
6. /usr/local/lib/libopencv_core.so \
7. /usr/local/lib/libopencv_imgproc.so \
8. /usr/local/lib/libopencv_imgcodecs.so
注意点:
lena.jpg路径最好要写全,也就是写成绝对路径的格式,否则可能会报错最终,排除所有错误,
运行,结果如下: