I installed it on the Raspberry Pi.
1. Install the Dependencies first
OpenCV 2.2 will require CMake to generate the makefile file, so you will need to install CMake first.
sudo apt-get install build-essentialsudo apt-get install Cmakesudo apt-get install libgtk2.0- Devsudo apt-get install pkg-configsudo apt-get install python-dev python-numpysudo apt-get Install Libavcodec-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libtiff-dev Libjasper-dev
2. Download the compilation OpenCV
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/3.1.0/opencv-3.1.0.zip/ Download Opencv-3.1.0.zip
After unpacking, create a folder build in its directory, enter the folder, use the CMake tool to generate the makefile file in the folder, and specify that the OPENCV installation directory for /USR/LOCAL,OPENCV source code is located in the previous level directory.
Cmake-d cmake_build_type=release-d cmake_install_prefix=/usr/local.
Make # very slow
At last
sudo make install # Update search dynamic link library sudo ldconfig
3. Testing
//read a picture and convert it into black and white#include <opencv2/core/core.hpp>#include<opencv2/imgproc/imgproc.hpp>#include<opencv2/highgui/highgui.hpp>#include<iostream>using namespaceCV; using namespacestd; intMain (intargcChar**argv) {Mat image, Image_gray; Image= Imread ("1.jpg"); Cvtcolor (image, Image_gray, Cv_rgb2gray); Namedwindow ("Image", cv_window_autosize); Namedwindow ("Image Gray", cv_window_autosize); Imshow ("Image", image); Imshow ("Image Gray", Image_gray); Waitkey (0); return 0; }
Need to write Makefile file:
#header FileINCLUDE = $ (Shell pkg-config--cflags OpenCV)#Extension LibrariesLIBS = $ (Shell pkg-config--Libs OpenCV)#target fileSOURCES =Test.cpp#executable fileOBJECTS = $ (sources:.cpp=. O) TARGET=Test $ (TARGET): $ (OBJECTS) G+-O $ (TARGET) $ (OBJECTS)-I $ (INCLUDE) $ (LIBS) $ (OBJECTS): $ (SOURCES) G++ -C $ (SOURCES) Clean:rm $ (OBJECTS) $ (TARGET)#compile rule [email protected] represents the target file $< represents the first dependent file%.o:%. cpp g+ I $ (INCLUDE)-o [email protected]-C $<
Note: tab is not a space before the action can be performed!
Reference: http://blog.csdn.net/xukai871105/article/details/40988101
Install and run OpenCV on Linux