Ubuntu14.04 + opencv 3.0 + python2.7 installation and testing, ubuntu14.04opencv
This document describes how to manually install opencv using the source code in ubuntu. The steps are from the opencv official website.
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)
Reprinted please description http://www.cnblogs.com/llxrl/p/4471831.html
- 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
1 [compiler] sudo apt-get install build-essential2 [required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev3 [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 (over 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-rc1mkdir releasecd releasecmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..makesudo make install
4. Test opencv1) 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 DisplayImage.cpp )target_link_libraries( DisplayImage ${OpenCV_LIBS} )4) Compile
cd ~/opencv-lenacmake .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-opencvsudo apt-get install python-numpy
Test:
Open python and import the cv module.
import cv