Install and test OpenCV 14.04 + Python 3.0 in Ubuntu 2.7

Source: Internet
Author: User

Install and test OpenCV 14.04 + Python 3.0 in Ubuntu 2.7

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 <stdio. h>
# Include <opencv2/opencv. hpp>

Using namespace cv;

Int main (int argc, char ** argv)
{
If (argc! = 2)
{
Printf ("usage: DisplayImage. out <Image_Path> \ 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 --------------------------------------

Install the required OpenCV2.4.1 package in Ubuntu Linux

Install OpenCV2.4.2 on Ubuntu 12.04

OpenCV in CentOS cannot read Video Files

Summary of installing OpenCV 2.4.5 in Ubuntu 12.04

Install OpenCv2.1 in Ubuntu 10.04

Face Recognition System Based on QT and OpenCV

Install OpenCV 2.4.9 in Ubuntu 14.04 and 13.10

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

OpenCV details: click here
OpenCV: click here

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.