Install and run OpenCV on Linux

Source: Internet
Author: User

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

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.