ubuntu14.04下opencv3.0+python2.7安装测试

本文记录了ubuntu 14.04下使用源码手动安装opencv 3.0的过程。此外记录了在python中安装及载入opencv的方法。

1、安装opencv所需的库(编译器、必须库、可选库)

gcc 4.4.x or later
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] libtbb2 libtbb-dev
[optional] libdc1394 2.x
[optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev

[compiler] sudo apt-get install build-essential[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

2、从官网下载最新opencv源码(2.4以上)http://sourceforge.net/projects/opencvlibrary/

或者github

3、编译opencv

将opencv放至任意目录,解压

unzip opencv-3.0.0-rc1.zip

创建编译目录,编译

cd ~/opencv-3.0.0-rc1mkdir releasecd releasecmake -d cmake_build_type=release -d cmake_install_prefix=/usr/local ..makesudo make install

4、测试opencv

1) 创建工作目录

mkdir ~/opencv-lenacd ~/opencv-lenagedit displayimage.cpp

2) 编辑如下代码

#include #include

using namespace cv;

int main(int argc, char** argv ){ if ( argc != 2 ) { printf(“usage: displayimage.out \n”); return -1; }

mat image; image = imread( argv[1], 1 );

if ( !image.data ) { printf(“no image data \n”); return -1; } namedwindow(“display image”, window_autosize ); imshow(“display image”, image);

waitkey(0);

return 0;}

3) 创建cmake编译文件

gedit cmakelists.txt

写入如下内容

cmake_minimum_required(version 2.8)project( displayimage )find_package( opencv required )add_executable( displayimage displayimage.cpp )target_link_libraries( displayimage ${opencv_libs} )

4) 编译

cd ~/opencv-lenacmake .make

5) 执行

此时opencv-lena文件夹中已经产生了可执行文件displayimage,下载lena.jpg放在opencv-lena下,运行

./displayimage lena.jpg

6) 结果

5、安装python-opencv

可直接使用apt安装

sudo apt-get install python-opencvsudo apt-get install python-numpy

测试:

打开python,import cv模块成功即可。

import cv

————————————–分割线 ————————————–

ubuntu linux下安装opencv2.4.1所需包 http://www.linuxidc.com/linux/2012-08/68184.htm

ubuntu 12.04 安装 opencv2.4.2 http://www.linuxidc.com/linux/2012-09/70158.htm

centos下opencv无法读取视频文件 http://www.linuxidc.com/linux/2011-07/39295.htm

ubuntu 12.04下安装opencv 2.4.5总结 http://www.linuxidc.com/linux/2013-06/86704.htm

ubuntu 10.04中安装opencv2.1九步曲 http://www.linuxidc.com/linux/2010-09/28678.htm

基于qt和opencv的人脸识别系统 http://www.linuxidc.com/linux/2011-11/47806.htm

[翻译]ubuntu 14.04, 13.10 下安装 opencv 2.4.9 http://www.linuxidc.com/linux/2014-12/110045.htm

————————————–分割线 ————————————–

opencv的详细介绍:请点这里opencv的下载地址:请点这里

更多ubuntu相关信息见ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

本文永久更新链接地址:http://www.linuxidc.com/linux/2015-05/116960.htm

Posted in 未分类

发表评论