How to install opencv on BPI-M2 Berry

how to install opencv on BPI-M2 Berry.

The first is to install the various dependencies of opencv and the library of image video.

update at first:

sudo apt-get update

1.install build-essential、cmake、git and pkg-config tool

sudo apt-get install build-essential cmake git pkg-config

2.:Install the various image packages required.

sudo apt-get install libjpeg8-dev (jpeg lib)

sudo apt-get install libtiff5-dev  (tif lib)

sudo apt-get install libjasper-dev (JPEG-2000 lib)

sudo apt-get install libpng12-dev   (png lib)

3.:The package for video.

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

  1. install gtk2.0:

sudo apt-get install libgtk2.0-dev

5.Optimize package installation.:

sudo apt-get install libatlas-base-dev gfortran

At this point, various toolkits are installed successfully.

Releases · opencv/opencv · GitHub download opencv sorce code (tar.gz file ),

unzip tar.gz file

1.cd ~ enter opencv dir

2.create build dir

mkdir build

3.cd build enter build dir

4.install to /urs/local

cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local ..

5.Start Compilation:

sudo  make

sudo make install 

sudo ldconfig   

opencv install finished.

write cod to test

create test.cpp

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
int main()
{
Mat img=imread("1.jpg");

imshow("test",img);
waitKey(0);

return 0;

}

create CMakeLists.txt and write

cmake_minimum_required(VERSION 2.8)  
project( test)  
find_package( OpenCV REQUIRED )  
add_executable( test test.cpp )  
target_link_libraries( test${OpenCV_LIBS} )  

Put a picture named 1.jpg in this file directory.

cd 
cmake .
make
./test

If the output image is configured correctly.