1.安装一些依赖库

sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev

2.下载源码并编译

opencv的下载地址:http://opencv.org/downloads.html
unzip opencv-x-x-x.zip
cd opencv
mkdir build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j && make install

3.安装和 配置

sudo vi /etc/ld.so.d/opencv.conf
输入:
/usr/local/lib
保存并退出
运行ldconfig使生效
sudo ldconfig
在shell的配置的文件中加入
我使用的是oh-my--zsh,所以在~/.zshrc中加入就可以了
#opencv config

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
  export PKG_CONFIG_PATH

4.测试

显示图片

ShowImage.cpp

 /**
* File name :ShowImage.cpp
* Author :kangkangliang
* File desc :test Opencv
* Mail :942504876@qq.com
* Create time :2016-07-26
*/ /**
* headfile
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <iterator>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
/**
* main function
*/
int
main(int argc,char **argv)
{
/// error way
if (argc < )
cout << "usage :./show image_name" << endl; /// read image from agrv
Mat src = imread(argv[]);
if (!src.data)
{
cout << "read iamge error" << endl;
return -;
} /// show image
imshow("image",src);
waitKey();
return ;
}

make.sh 脚本

 #########################################
# File name :make.sh
# Author :liangkangkang
# File desc :compile opencv
# Mail :@qq.comm
# Create time :--
#########################################
#!/usr/bin/bash
#obj = `echo $ | cut -d '.' -f1`
#g++ -Wall -std=c++0x $ -o $obj
g++ -Wall -std=c++0x $ `pkg-config --cflags --libs opencv` -o `echo $ | cut -d '.' -f1`
#./`echo $ | cut -d '.' -f1`
$sh make.sh ShowImage.cpp
$./ShowImage image_name

或者使用cmake来编译

编写CMakeLists.txt

 cmake_minimum_required(VERSION 2.8)
project( ShowImage )
find_package( OpenCV REQUIRED )
add_executable( ShowImage ShowImage.cpp )
target_link_libraries( ShowImage ${OpenCV_LIBS} )

$cmake .

$make

$./ShowImage image_name

祝你成功,开始OpenCV之旅!!!

note:懒人的话就直接用opencv-install 脚本

address

OpenCV-ubuntu-install的更多相关文章

  1. Ubuntu install TensorFlow

    /******************************************************************************** * Ubuntu install T ...

  2. ubuntu install zabbix

    ubuntu install zabbix reference1 reference2 some ERRORS raise during install process, may it help. z ...

  3. Ubuntu install android studio

    Ubuntu install android studio 1. 安装 openjdk8,并在配置文件 /etc/profile 中,追加如下内容: sudo aptitude install ope ...

  4. ubuntu install redis

    ubuntu install redis apt-get update apt-get install redis-server redis-server --daemonize yes

  5. ubuntu install opencv

    1. install the newest opencv version pip install opencv-python

  6. Ubuntu install Docker

    首先需要说明的是,根据Docker的官方文档,Docker的安装必须在64位的机子上.这里只说明Ubuntu 14.04与16.04,我成功安装成功过Ubuntu 14.04,16.04还没有测试过, ...

  7. Ubuntu install g++

    We can use two ways to  install g++ on Ubuntu. 1.  a. sudo apt-get install make gcc g++.      b. sud ...

  8. [Ubuntu] Install teamviewer9 on Ubuntu14.04_x64

    The article copied from http://ubuntuhandbook.org/index.php/2013/12/install-teamviewer-ubuntu-1404/ ...

  9. [Ubuntu] Install subversion1.8 on Ubuntu13.10

    Subversion1.8 is difference far away from subversion1.7, here is the steps to install subversion1.8. ...

  10. Ubuntu Install Chrome Brwoser

    在ubuntu下安装chrome浏览器,可以直接从官网下载:http://www.google.cn/intl/zh-CN/chrome/browser/thankyou.html?platform= ...

随机推荐

  1. IOS多线程 总结 -------------核心代码(GCD)

    //NSObject //在子线程中执行代码 // 参数1: 执行的方法 (最多有一个参数,没有返回值) //参数2: 传递给方法的参数 [self performSelectorInBackgrou ...

  2. js运算符的优先级

    自上向下优先级降低 运算符 描述 . [] () 字段访问.数组下标.函数调用以及表达式分组 ++ -- - ~ ! delete new typeof void 一元运算符.返回数据类型.对象创建. ...

  3. os8 location authorization 错误.

    今天在XCode6上打开之前写的地图时,给我报这个错 location authorization 去网上查了一番,才知道Xcode6对地图的设置稍有修改 在stackoverflow上找到了答案 i ...

  4. android 中View, Window, Activity, WindowManager,ViewRoot几者之间的关系

    (1)View:最基本的UI组件,表示屏幕上的一个矩形区域. (2)Window: 表示一个窗口,不一定有屏幕那么大,可以很大也可以很小:                         它包含一个V ...

  5. Qt 的信号与槽机制介绍(10个要注意的问题)

    QT 是一个跨平台的 C++ GUI 应用构架,它提供了丰富的窗口部件集,具有面向对象.易于扩展.真正的组件编程等特点,更为引人注目的是目前 Linux 上最为流行的 KDE 桌面环境就是建立在 QT ...

  6. Qt使用MinGW编译,如何忽略警告

    Qt编译时经常出现以下警告: warning: unused parameter 'arg1' [-Wunused-parameter] warning: unused variable 'i' [- ...

  7. IDA pro 的Python环境变量设置

    推荐使用IDA PRO6.1+Python2.6 安装完毕Python2.6后,添加如下的环境变量: PYTHONHOME=C:\Python26PATH=%PATH%;C:\Python26LIB= ...

  8. Java7新语法 -try-with-resources

    http://docs.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html The try-with- ...

  9. 转:linux执行shell脚本的方式及一些区别

    假设shell脚本文件为hello.sh放在/root目录下.下面介绍几种在终端执行shell脚本的方法: [root@localhost home]# cd /root/ [root@localho ...

  10. logstash tomcat catalina.out zabbix 插件不会引起崩溃

    input { file { type => "zj_api" path => ["/data01/applog_backup/zjzc_log/zj-api ...