This document documents the process of manually installing OPENCV 3.0 using source code under Ubuntu 14.04. The method of installing and loading OpenCV in Python is also documented.
1. Install OpenCV required libraries (compilers, required libraries, optional libraries)
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-d EV Libdc1394-22-dev
2, download the latest OpenCV source (more than 2.4) from the official website http://sourceforge.net/projects/opencvlibrary/
or GitHub.
======================2016.8.13 Update ===================
Encounter a problem like this:
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32 against `.rodata.str1.1‘ can not be used when making a shared object; recompile with -fPIC/usr/local/lib/libavcodec.a: could not read symbols: Bad value
Need to compile FFmpeg plus shared options
sudo apt-get remove ffmpeg
./configure--ENABLE-GPL--ENABLE-LIBFAAC--enable-libmp3lame--enable-libopencore-amrnb--ENABLE-LIBOPENCORE-AMRWB --enable-libtheora--enable-libvorbis--enable-libxvid--enable-nonfree--enable-postproc--enable-version3-- Enable-x11grab--enable-shared--enable-pic
Make-j16
sudo make install
======================================================
3. Compiling OPENCV
Put OpenCV into any directory, unzip
Unzip Opencv-3.0.0-rc1.zip
Create a compiled directory, compile
CD ~/OPENCV-3.0.0-RC1
mkdir Release
CD release
cmake-d with_cuda=on-d cmake_build_type=release-d cmake_install_prefix=/net/wanggu/local.
(Recommended with Ccmake. ) More options can be manually configured, such as Cmake_install_prefix, "cuda_generation" = Auto)
-----------------------
Cmake_install_prefix/net/wanggu/software/opencv-master/install
Problems with Cuda:
Cuda_generation Auto
-----------------
(2016.8.24 Update)
Nonfree contains features2d, to enable
in the opencv3.x, you should first download Https://github.com/opencv/opencv_contrib
Then Ccmake.
Set the following:
Opencv_enable_nonfree on
Opencv_extra_modules_path/net/wanggu/software/opencv-master/opencv_contrib/modules
----------------
/usr/local change to other, or sudo permissions.
(Opencv-3.0.0-alpha This version is not reliable)
check python for any detection and location
Make-j8
sudo make install-j8
-----------------------------------
Add the Python environment variable for CV to. BASHRC
Export Cvpath=/usr/local/lib/python2.7/site-packages
Export pythonpath= $CVPATH: $PYTHONPATH
(may also be dist-packages) The dist inside the server is 3.0.0site inside is 2.4.10 contains cv2.so and cv.py-------------------because the OpenCV version under the USR directory is often changed, so cvpath points to their anaconda Package under/home/wanggu/anaconda/lib Find yourself compiled cv2.so (in Release/lib) and cv.py (OPENCV-2.4.13/MODULES/PYTHON/SRC2), then copy into/ Home/wanggu/anaconda/lib. -------------------
To view the installed version of OPENCVPkg-Config --modversionOpenCV
=============================python3 anaconda3 ubuntu Opencv3:conda install-c Https://conda.binstar.org/menpo Openc V3
========================
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 CMake compilation file
Gedit CMakeLists.txt
Write the following:
Cmake_minimum_required (VERSION 2.8)
Project (DisplayImage)
Find_package (OpenCV REQUIRED)
Add_executable (DisplayImage DisplayImage.cpp)
Target_link_libraries (DisplayImage ${opencv_libs})
4) Compiling
CD ~/opencv-lena
CMake.
Make
5) execution
At this time the Opencv-lena folder has produced the executable file displayimage, download lena.jpg placed under Opencv-lena, run
./displayimage lena.jpg
6) Results
5, Installation Python-opencv
Can be installed directly using apt
sudo apt-get install PYTHON-OPENCV
sudo apt-get install Python-numpy
Test:
Open the Python,import CV module to succeed.
Import CV
Import Cv2
Related articles:
Ubuntu 12.04 Install OpenCV 2.3.1, image binary: http://www.linuxdiyf.com/linux/8615.html
QT/QT Creator Add OPENCV configuration in Linux environment: http://www.linuxdiyf.com/linux/9314.html
Install OpenCv2.1 Nine steps in Ubuntu: http://www.linuxdiyf.com/linux/9848.html
From Wiznote
UBUNTU14 OpenCV python Installation