ubuntu12.04安装Opencv2.4.9
之前在Linux下装过几次opencv,但几乎每次都要查一下怎么安装,这次索性记录一下安装过程,不用每次都看其他人的教程了。
至于安装过程,可以直接参考官方文档。在解压后的文件夹下opencv\build\doc的opencv_tutorials.pdf文件开头就讲怎样在Linux下安装opencv.
以下就是官方文档的原文:
1.1 Installation in Linux
These steps have been tested for Ubuntu 10.04 but should work with other distros as well.
Required Packages
• GCC 4.4.x or later. This can be installed with:
sudo apt-get install build-essential
• CMake 2.6 or higher;
• Git;
• GTK+2.x or higher, including headers (libgtk2.0-dev);
• pkg-config;
• Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy);
• ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev;
• [optional] libdc1394 2.x;
• [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev.
All the libraries above can be installed via Terminal or by using Synaptic Manager
Building OpenCV from Source Using CMake, Using the Command Line
1. Create a temporary directory, which we denote as <cmake_binary_dir>, where you want to put the generated
Makefiles, project files as well the object files and output binaries.
2. Enter the <cmake_binary_dir> and type
cmake [<some optional parameters>] <path to the OpenCV source directory>
For example
cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
3. Enter the created temporary directory (<cmake_binary_dir>) and proceed with:
make
sudo make install
因为是在虚拟机上操作,虚拟机网速有限,所以我的opencv2.4.9是从本地下载好后通过共享文件夹拷贝到虚拟机上的。
操作一 拷贝OPENCV源文件到虚拟机
先从虚拟机Terminal进入的共享文件夹,假设opencv-2.4.9.zip在共性文件夹内,使用命令复制到Documents文件夹下(其中xxxxxxxxx就是你设置的linux虚拟机的用户名):
cp opencv-2.4.9.zip /home/xxxxxxxxx/Documents/
这样就将 opencv-2.4.9.zip拷贝至虚拟机Documents文件夹下。
下一步就是解压opencv-2.4.9.zip文件:
unzip opencv-2.4.9.zip
操作二 安装Cmake
由于要安装opencv,按照上面官网教程的说明:
在我安装的ubuntu12.04上面测试过。自带的gcc版本:
嗯,4.6.3,比官网上说的4.4大,没问题。
然后按照下一步教程sudo apt-get install build-essential:
接着安装cmake,直接使用sudo apt-get install cmake安装的cmake一般都是ubuntu自带的支持的版本,不是最新的,但是使用该方法安装方便,我就暂且一试,毕竟下载源码自己编译很费事。
所以为图简便,就直接这样安装了,然后查一下版本号:
喔,相对于前面教程里面说的CMake 2.6 or higher,这个版本已经够用了。
操作三 安装必要库
由于Git是用来下载opencv源码用的,因为开始我们已经从本地拷贝过源码了,所以此处可以跳过。
下面是安装一些库和依赖文件:
sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev libtiff4-dev libswscale-dev libjasper-dev
安装pkg-config,它是一个提供从源代码中编译软件时查询已安装的库时使用的统一接口的计算机软件。(下面这个在我这里是默认安装好的)
sudo apt-get install pkg-config
操作三 编译安装opencv
没有gui的cmake我用不惯,所以先安装cmake-gui:
sudo apt-get install cmake-qt-gui
安装完成后,就可以使用cmake-gui了,在终端输入cmake-gui就可以打开GUI界面:
然后就是配置了。
选完原文件路径和生成路径,然后点Configure就可以完成配置。注意在生成路径下的static文件夹是我新建的,因为我要生成一份静态库。
注意我用黄色框框起来的部分,因为要生成静态库,所以把右侧的复选框的“√”去掉,然后重新点Configure按钮。
下一步点Generate,Cmake会根据CmakeList.txt生成make文件,接着就需要编译了。
关掉cmake-gui。由终端进入自己新建的那个static文件夹
使用make编译,其中-j4表示4核编译:
make -j4
嗯,大概这次是被我要写笔记吓到了,一次顺利通过,内心喜悦!
使用make install 安装
嗯,又顺利通过!
操作三 测试opencv
1.2 Using OpenCV with gcc and CMake
Note: We assume that you have successfully installed OpenCV in your workstation.
• The easiest way of using OpenCV in your code is to use CMake. A few advantages (taken from the Wiki):
1. No need to change anything when porting between Linux and Windows
2. Can easily be combined with other tools by CMake( i.e. Qt, ITK and VTK )
• If you are not familiar with CMake, checkout the tutorial on its website.
Steps
Create a program using OpenCV
Let’s use a simple program such as DisplayImage.cpp shown below.
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -;
}
Mat image;
image = imread( argv[], );
if ( !image.data )
{
printf("No image data \n");
return -;
}
namedWindow("Display Image", CV_WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey();
return ;
}
Create a CMake file
Now you have to create your CMakeLists.txt file. It should look like this:
Generate the executable
This part is easy, just proceed as with any other project using CMake:
cd <DisplayImage_directory>
cmake .
make
Result
By now you should have an executable (called DisplayImage in this case). You just have to run it giving an image
location as an argument, i.e.:
./DisplayImage lena.jpg
You should get a nice window as the one shown below:
嗯,就这样吧。
ubuntu12.04安装Opencv2.4.9的更多相关文章
- Ubuntu12.04安装64位系统出现编译错误error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or dir
问题: Ubuntu12.04安装64位系统出现编译错误error while loading shared libraries: libz.so.1: cannot open shared obje ...
- ubuntu12.04安装svn 1.7(转载)
ubuntu12.04安装svn 1.7 分类: ubuntu2013-10-22 16:03 239人阅读 评论(0) 收藏 举报 svnubuntu 目录(?)[+] 1.问题 在 ...
- ubuntu12.04 安装 php5.4/php5.5
1:修改源(我使用163的源)直接修改/etc/apt/sources.list deb http://mirrors.163.com/ubuntu/ precise main universe re ...
- Ubuntu12.04 安装Samba
Ubuntu12.04 安装Samba Ubuntu12.04 安装Samba 本教程介绍了在Ubuntu12.04安装Samba文件服务器,以及如何配置它通过SMB协议共享文件,以及如何将用户添加. ...
- Ubuntu12.04安装java6
按照android官方文档 http://source.android.com 下载编译android源代码,jdk安装失败,尝试一下方法成功(2013-11-20) 下面我就把在Ubuntu12.0 ...
- [分享]Ubuntu12.04安装基础教程(图文)
[分享]Ubuntu12.04安装基础教程(图文) 原文地址: http://teliute.org/linux/Ubsetup/lesson21/lesson21.html 1.进入 live cd ...
- ubuntu12.04 安装nginx+php+mysql (lnmp)的web服务器环境
1.Ubuntu12.04 安装nginx+php+mysql (lnmp)的web服务器环境 http://blog.db89.org/ubuntu12-04-install-nginx-php-m ...
- ubuntu12.04 安装CS:APP Y86模拟器
下的第一UBUNTU12.04下Y86模拟器的安装:(參考http://archive.cnblogs.com/a/1865627/ 作适当改动) 1.安装bison和flex词法分析工具 sudo ...
- Ubuntu12.04安装vscode i386
最近在Ubuntu12.04的32位版本上安装vscode,我下载的是32位deb包, vscode官网 安装命令 sudo dpkg -i vscode-i386.deb 安装完成没有报错,但是点 ...
随机推荐
- 大二上学期Javaweb阶段性学习总结
本学期主要学了h5,css3,js,Java,SQL server数据库基本操作等相关知识,学会了简单web系统的制作. 这个学期总的来说学到了很多东西. 前期Java学习因为有了暑期学习及pta上5 ...
- 【C语言】猴子吃桃问题
题目: 猴子第一天吃了若干个桃子,当即吃了一半,还不解馋,又多吃了一个: 第二天,吃剩下的桃子的一半,还不过瘾,又多吃了一个:以后每天都吃前一天剩下的一半多一个,到第10天想再吃时,只剩下一个桃子了. ...
- PP: GRU-ODE-Bayes: Continuous modeling of sporadically-observed time series
From: KU Leuven; ESAT-STADIUS比利时鲁汶大学 ?? How to model real-world multidimensional time series? especi ...
- 我的python笔记06
面向对象学习 本节内容: 面向对象编程介绍 为什么要用面向对象进行开发? 面向对象的特性:封装.继承.多态 类.方法. 引子 你现在是一家游戏公司的开发人员,现在需要你开发一款叫做< ...
- for循环与闭包
Es5 function box(){ var arr = []; ;i<;i++){ arr[i] = (function(num){ //自我执行,并传参(将匿名函数形成一个表达式)(传递一 ...
- AntDesign(React)学习-9 Dva model reducer实践
今天肺炎增长数字依然吓人,感觉穿越到丧失片里了. 本节开始学习dva model使用,官网的讲解太文档化,对新手实践不太友好,自己简化了一个最简单的演示代码. 1.在src,models文件夹下创建u ...
- js及jsp.java查错的几种方式
一.js 1.console.log("你想输出的内容"); 2.alert("你想输出的内容"); 3.debugger;(记得打开F12) 4.快速找到js ...
- 835. 字符串统计(Trie树模板题)
维护一个字符串集合,支持两种操作: “I x”向集合中插入一个字符串x: “Q x”询问一个字符串在集合中出现了多少次. 共有N个操作,输入的字符串总长度不超过 105105,字符串仅包含小写英文字母 ...
- DE1_MSEL
基础的一般实验:01001(现在用的)或10010 马上换linux,做个记录: sd卡启动linux系统时,启动开关0至4位拨至00000
- C#中常见的winform控件命名规范 转
我们知道Button 常常简称为btn,那么Winform中的其它控件呢,这篇文章在C#的winform控件命名规范 的基础上对一些控件的名称的简称进行了整理. 1. 标准控件 NO. 控件类型简写 ...