Raspberry Pi Learning: Source mode installation OpenCV

Source: Internet
Author: User

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

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.