OpenCV3.0 + Python2.7 installation and testing in Ubuntu14.04

Source: Internet
Author: User
This document describes how to manually install OpenCV3.0 using the source code in Ubuntu14.04. In addition, the method for installing and loading OpenCV in Python is recorded. 1. Install the library required by OpenCV (compiler, required library, and optional Library) GCC4.4.xorlaterCMake2.6orhigherGitGTK + 2. xorhigher, includingheaders (libgtk2.0-dev)

This document describes how to manually install OpenCV 14.04 using the source code in Ubuntu 3.0. In addition, the method for installing and loading OpenCV in Python is recorded.

1. Install the library required by OpenCV (compiler, required library, and optional Library)

  • 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, download the latest opencv source code from the official website (more than 2.4) http://sourceforge.net/projects/opencvlibrary/

Or github

3. Compile opencv

Store opencv in any directory and decompress it.

Unzip opencv-3.0.0-rc1.zip

Create a compilation directory and compile

Cd ~ Opencv-3.0.0-rc1
Mkdir release
Cd release
Cmake-D CMAKE_BUILD_TYPE = RELEASE-D CMAKE_INSTALL_PREFIX =/usr/local ..
Make
Sudo make install

4. Test opencv

1) Create a working directory

Mkdir ~ /Opencv-lena
Cd ~ /Opencv-lena
Gedit DisplayImage. cpp

2) edit the following code:

# 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) create a CMake compiling File

Gedit CMakeLists.txt

Write the following content

Cmake_minimum_required (VERSION 2.8)
Project (DisplayImage)
Find_package (OpenCV REQUIRED)
Add_executable (DisplayImage. cpp)
Target_link_libraries (DisplayImage $ {OpenCV_LIBS })

4) Compile

Cd ~ /Opencv-lena
Cmake.
Make

5) Execution

Export opencv-lena the executable file displayimagehas been stored in the folder, and lena.jpg is downloaded under opencv-lena to run

./DisplayImage lena.jpg

6) Result

5. Install python-opencv

You can directly use apt for installation.

Sudo apt-get install python-opencv
Sudo apt-get install python-numpy

Test:

Open python and import the cv module.

Import cv

-------------------------------------- Split line --------------------------------------

OpenCV2.4.1 package http://www.linuxidc.com/Linux/2012-08/68184.htm installed in Ubuntu Linux

Ubuntu 12.04 install OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htm

OpenCV in CentOS cannot read video file http://www.linuxidc.com/Linux/2011-07/39295.htm

Summary of installing OpenCV 2.4.5 in Ubuntu 12.04Http://www.linuxidc.com/Linux/2013-06/86704.htm

Install OpenCv2.1 nine-step http://www.linuxidc.com/Linux/2010-09/28678.htm in Ubuntu 10.04

Http://www.linuxidc.com/Linux/2011-11/47806.htm of face recognition system based on QT and OpenCV

Install OpenCV 2.4.9 in Ubuntu 14.04 and 13.10Http://www.linuxidc.com/Linux/2014-12/110045.htm

-------------------------------------- Split line --------------------------------------

OpenCV details: Click here
OpenCV: Click here

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-05/116960.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.