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 安装完成没有报错,但是点 ...
随机推荐
- 云服务器 使用 onedrive 快速同步
重大更新:支持微软的onedrive网盘,可以自动实时双向同步数据,也可以多台服务器和网盘之间实时同步数据.新增了一个虚拟环境python367,支持pytorch1.2:-----------微软O ...
- 【已解决】使用 yarn 安装时,报错node_modules\node sass:Command failed.
npm install -g mirror-config-china --registry=http://registry.npm.taobao.org npm install node-sass y ...
- K3标准产品的BOS单据发布至自定义模块
在自定义模块 下先随便发布一张单据,然后后台更新数据表. select * from icclasstype where fname_chs like '付款申请单%' --查询表单的ID upd ...
- Ubutu安装oracle jdk1.8
环境: Ubuntu 18.04 LTS x64位 系统用户 hou 工具: jdk-8u171-linux-x64.tar.gz 实验的心 步骤: 第一步: 查看有没有装jdk,按住 ctr+a ...
- start.sh在linux下启动报错 Can't connect to any repository: ,cannot open git-receive-pack
个人博客 地址:http://www.wenhaofan.com/article/20181223135418 报错信息 Can't connect to any repository: ,canno ...
- vscode中LaTeX的编写
前言 在学习\(\mathrm{\LaTeX}\)的时候尝试过很多编辑器,但都被其复古的外观或者复杂的配置劝退.并且因为本身就在使用VScode写其他的一些语言,正好借此机会也学习一下怎么用VScod ...
- Spring boot --- 自动配置
spring boot 自动配置 指的是针对很多spring 应用程序常见的应用功能,spring boot 能自动提供相关配置. spring boot 自动配置加载 Spring boot ...
- hashmap与currentHashMap
hashmap的缺点 多线程不安全,在并发场景下使用时容易出现死循环,脏读问题等 死循环:https://juejin.im/post/5a66a08d5188253dc3321da0 (这篇好点)h ...
- 用户注册(php)login(非美化)
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- spring boot使用freemarker模版整合spring Data JPA
目录结构 第一步:在pom.xml文件中添加依赖 <!--模板依赖--> <dependency> <groupId>org.springframework.boo ...