1: Download several dependencies:
Update software Source: sudo apt-get update/upgrade;
Install the dependencies in turn:
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: Get Source code: I download opencv2.4.10 Linux version from OPENCV official website. Set up OpenCV folder, unzip opencv2.4.10 and OpenCV inside.
Unzip Opencv-2.4.10.zip
3: Compile the source code:
Enter the OPENCV source code directory and create a new folder named release:
cd/home/pi/opencv/opencv-2.4.10mkdir ReleaseCD releaseUse the CMake tool to generate the makefile file in this folder, specifying the OPENCV installation directory as/usr/local/cmake-d cmake_build_type=release-d with_ffmpeg=off-d cmake_install_prefix=/usr/local.Note that you need to add-D with_ffmpeg=off, otherwise errors will occur during compilation. The cause is a ffmpeg update issue.The time to compile the source code is very long.Makesudo make install;4: TestTest.cpp
#include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/ Highgui.hpp> #include <iostream>using namespace cv;using namespace std;int main (int argc, char **argv) { Mat Image, Image_gray; Image = Imread (argv[1], cv_load_image_color); if (argc! = 2 | |!image.data) { cout << "No image data\n"; return-1; } 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;}
CMakeLists.txt
Cmake_minimum_required (VERSION 2.8) Project (test) Find_package (OpenCV required) add_executable (test test.cpp) target_ Link_libraries (Test ${opencv_libs})
CMake. Generate a Makefile file, note "." Not less
Make compile to generate test program.
./test 1.jpg for testing
Raspberry Pi Learning: Source mode installation OpenCV