Ubuntu14.04 installs opencv3.4.5+opencv contrib3.4.5 detailed tutorial

Hits: 0

github

First of all, the download versions of [opencv] and opencv_contrib should be the same! ! ! ! !

Many tutorials on the Internet do not mention the need to download the corresponding version of the contrib version. I had many problems with the previous installation. This time, I deliberately summarized my own installation tutorial and some installation points.

Opencv3.4.5 official website installation tutorial

Document preparation:

1. opencv3.4.5 version download

Note: Choose the version of clone or download, not necessarily what you need. It is also easy to confuse the version, which is mainly error-prone

Opencv download official website : https://opencv.org/releases.html

This article downloads opencv3.4.5, as shown in the following figure:

2. Opencv_contrib3.4.5 version download, select release

Note: Choose the version of clone or download, not necessarily what you need. It is also easy to confuse the version, which is mainly error-prone

opencv_contirb URL : https://github.com/opencv/opencv_contrib

Installation begins:

1. Update all at once

sudo apt-get update
sudo apt-get upgrade

2. Install the following dependencies first

sudo apt-get install build-essential  

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev  

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev  

sudo apt-get install build-essential qt5-default ccache libv4l-dev libavresample-dev  libgphoto2-dev libopenblas-base libopenblas-dev doxygen  openjdk-8-jdk pylint libvtk6-dev

sudo apt-get install pkg-config

3. Unzip the downloaded package:

sudo unzip opencv-3.4.5.zip
sudo unzip opencv_contrib-3.4.5.zip

4. After decompression, you need to extract opencv_contrib-3.4.5.zip to the opencv-3.4.5 directory, and create a new folder build in this directory.

sudo  cp  -r  opencv_contrib-3 .4 .5  opencv-3 .4 .5   #Copy opencv_contrib to the opencv directory

cd opencv-3.4.5

sudo  mkdir  build #New                               folder build

5. Now go to the opencv-3.3.1 directory and view the file structure:

#ls

3rdparty  cmake            data     LICENSE               platforms
apps      CMakeLists.txt   doc      modules               README.md
build     CONTRIBUTING.md  include  opencv_contrib-3.4.5  samples

6. Enter the build directory and execute cmake to generate the makefile:

cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv-3.4.5/opencv_contrib-3.4.5/modules/ -DOPENCV_ENABLE_NONFREE=True ..

Note: OPENCV_EXTRA_MODULES_PATH is the modules directory under your opencv_contrib-3.3.1, please modify the address according to your actual directory. There are two points that cannot be omitted! !

-DOPENCV_ENABLE_NONFREE=True This is very important, this is the statement to install the opencv patent module.

But there is a problem in this process:

IPPICV and face_landmark_model.dat cannot be downloaded

Refer to the following blog to modify some files, but note that opencv3.4.5ippicv is ippicv_2019_lnx_intel64_general_20180723, and the two required files have been uploaded to Baidu Cloud:

/CSDN330/article/details/86747867

Link: https://pan.baidu.com/s/1SPLRWlIGlRf0YMri2l7MOQ 
Extraction code: haas 

Next is the long wait…

The generated prompt is similar to the following:

--   Install path:                  /usr/local
-- 
--   cvconfig.h is in:              /home/files/opencv-3.4.5/build
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/files/opencv-3.4.5/build

7. After cmake is successful, you can make under the build file:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig 
export PKG_CONFIG_PATH

Then came a longer wait… The exact time [varies from person to person] , but my computer ran for 1 hour. If you see the picture below, it means success.

export PKG_CONFIG_PATH=/usr/local/opencv/lib/pkgconfig 
export LD_LIBRARY_PATH=/usr/local/opencv/lib 

The resulting graph is as follows:

8. Configure environment variables

(1) After the installation is successful, you also need to set the environment variables of opencv. open a file:

mkdir ~/test
cd ~/test
gedit Image_show.cpp

(2) Add the following content to the blank document:

# include  <iostream>
 # include  <opencv2/opencv.hpp> //Header file
 # include  <opencv2/xfeatures2d.hpp>
 using  namespace cv;   //Include cv namespace 
using  namespace  std ;

int main()
{
    //Create SIFT class pointer
    Ptr<Feature2D> f2d = xfeatures2d::SIFT::create();
    //Read in the picture 
    Mat img_1 = imread( "1.jpg" );
    Mat img_2 = imread("2.jpg");
    //Detect the keypoints
    vector<KeyPoint> keypoints_1, keypoints_2;
    f2d->detect(img_1, keypoints_1);
    f2d->detect(img_2, keypoints_2);
    //Calculate descriptors (feature vectors)
    Mat descriptors_1, descriptors_2;
    f2d->compute(img_1, keypoints_1, descriptors_1);
    f2d->compute(img_2, keypoints_2, descriptors_2);    
    //Matching descriptor vector using BFMatcher
    BFMatcher matches;
    vector<DMatch> matches;
    matcher.match(descriptors_1, descriptors_2, matches);
    // draw the matched key points
    Mat img_matches;
    drawMatches(img_1, keypoints_1, img_2, keypoints_2, matches, img_matches);
    imwrite( "final.jpg" ,img_matches);
     //Wait for any key to be pressed 
    waitKey( 0 );
}

(3) Next configure the library:

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

(4) Change the environment variable:

cd ~/test
cmake .
make

(5) Add after the file:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig 
export PKG_CONFIG_PATH

or add:

export PKG_CONFIG_PATH=/usr/local/opencv/lib/pkgconfig 
export LD_LIBRARY_PATH=/usr/local/opencv/lib 

(6) Save and exit. Before running the following routine, you need to restart the terminal to make the configuration take effect.

Now to test whether opencv3.4.5 and opencv_contrib3.4.5 are installed successfully

The test document has been uploaded to Baidu Cloud:

Link: https://pan.baidu.com/s/1EG8Hz9SnSnhgPBaSC3VJvA 
Extraction code: uf2u 

  1. Create a working directory

mkdir ~/test
cd ~/test
gedit Image_show.cpp

  1. Image_show.cpp compiles the following code

# include  <iostream>
 # include  <opencv2/opencv.hpp> //Header file
 # include  <opencv2/xfeatures2d.hpp>
 using  namespace cv;   //Include cv namespace 
using  namespace  std ;

int main()
{
    //Create SIFT class pointer
    Ptr<Feature2D> f2d = xfeatures2d::SIFT::create();
    //Read in the picture 
    Mat img_1 = imread( "1.jpg" );
    Mat img_2 = imread("2.jpg");
    //Detect the keypoints
    vector<KeyPoint> keypoints_1, keypoints_2;
    f2d->detect(img_1, keypoints_1);
    f2d->detect(img_2, keypoints_2);
    //Calculate descriptors (feature vectors)
    Mat descriptors_1, descriptors_2;
    f2d->compute(img_1, keypoints_1, descriptors_1);
    f2d->compute(img_2, keypoints_2, descriptors_2);    
    //Matching descriptor vector using BFMatcher
    BFMatcher matches;
    vector<DMatch> matches;
    matcher.match(descriptors_1, descriptors_2, matches);
    // draw the matched key points
    Mat img_matches;
    drawMatches(img_1, keypoints_1, img_2, keypoints_2, matches, img_matches);
    imwrite( "final.jpg" ,img_matches);
     //Wait for any key to be pressed 
    waitKey( 0 );
}

  1. Create a CMake file in the test folder

gedit CMakeLists.txt

Write the following

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

  1. Compile

cd ~/test
cmake .
make

5. Execute
  At this point, the executable file test has been generated in the test folder, download 1.jpg and 2.jpg and put them in the test folder, run

./test

6. Results

Figure 1.jpg:

Figure 2.jpg: 

Referenced from:

/xiangxianghehe/article/details/78780269

/u012704941/article/details/80396249

/qq_28467367/article/details/87933947

You may also like...

Leave a Reply

Your email address will not be published.