Install the opencv_contrib extension library based on Ubuntu's opencv library

Reminder: This blog post is in an environment where the same version of the opencv library has been installed. To install the opencv library, please see [ Compile and Install OpenCV with cmake on Ubuntu ].

If you don't have opencv installed, you can also install opencv and contrib together, and you need to install the opencv tutorial together.

The practical version of this article: opencv-3.2.0 opencv-3.4.0


That's right, the blogger has tossed both versions like this. See below for various issues.

I found the official face recognition example of opencv-3.x, COPY came over to try it out, but there was an error when compiling!

Are the official examples all wrong? Makes no sense.

Quickly Baidu, it turns out that the opencv_contrib extension module needs to be installed.


Prepare to install the package:

Go to https://github.com/opencv/opencv_contrib to download, remember to need the corresponding version of the package.

For opencv-3.xx, opencv_contrib-3.xx.tar.gz should be selected


1. Install related dependencies

$ 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

Note: If the installation fails, please execute the update command and try again (if it fails again, please change the software source. I use 163, which is available for personal testing)

$ sudo apt-get update

$ sudo apt-get upgrade

2. Installation

General idea: decompress opencv (for those without opencv installed), opencv_contrib, move opencv_contrib to the opencv directory, create a compilation directory build under opencv, and enter the build to configure cmake, make, make install.

1. Unzip

$ tar zxvf opencv_contrib-3.2.0.tar.gz

2. Copy/move the decompressed library to the opencv source directory

$ mv opencv_contrib-3.2.0 opencv-3.2.0 -rf
3. The build directory under the opencv source code will be carried out, the build directory will be cleared, and the cmake command will be executed (create it if there is no build directory)
$ cd opencv-3.2.0/build

$ rm * -rf

$ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.2.0/modules/ ..

The command is similar to the one when installing the opencv library, with the additional parameter OPENCV_EXTRA_MODULES_PATH, which refers to the modules directory under the opencv_contrib library

The ".." at the end refers to the opencv source directory


In this step, the following error will occur in version 3.2.0 (in fact, version 3.4 will also have this situation, but it will not report an error, maybe you won't notice it, leave it alone):

-- Downloading v3.1.0/protobuf-cpp-3.1.0.tar.gz...
CMake Error at cmake/OpenCVUtils.cmake:1043 (file):
  file DOWNLOAD HASH mismatch

    for file: [/root/library/opencv/opencv-3.2.0/opencv_contrib-3.2.0/modules/dnn/.download/bd5e3eed635a8d32e2b99658633815ef/v3.1.0/protobuf-cpp-3.1.0.tar.gz]
      expected hash: [bd5e3eed635a8d32e2b99658633815ef]
        actual hash: [d41d8cd98f00b204e9800998ecf8427e]
             status: [1;"Unsupported protocol"]

Call Stack (most recent call first):
  opencv_contrib-3.2.0/modules/dnn/cmake/download_protobuf.cmake:23 (ocv_download)
  opencv_contrib-3.2.0/modules/dnn/cmake/download_protobuf.cmake:51 (ocv_protobuf_download)
  opencv_contrib-3.2.0/modules/dnn/cmake/OpenCVFindLibProtobuf.cmake:30 (include)
  opencv_contrib-3.2.0/modules/dnn/CMakeLists.txt:35 (include)

The solution is similar to that encountered in compiling and installing OpenCV with cmake on Ubuntu.

Manually download protobuf-cpp-3.1.0.tar first, and then place it in the specified directory (see the prompt information output above, as follows:)

[/root/library/opencv/opencv-3.2.0/opencv_contrib-3.2.0/modules/dnn/.download/bd5e3eed635a8d32e2b99658633815ef/v3.1.0/protobuf-cpp-3.1.0.tar.gz]

PS: This protobuf-cpp-3.1.0.tar is hard to find, and all you can find are CSDN points. If you don't have points, you need to find the official download.

Free download address: https://github.com/google/protobuf Find the corresponding version and download it.

Notice:

There are several such problems with opencv-3.2, and the solutions are the same as above.

Online resources are downloaded from CSDN points. (The one I asked for help at the time was [ Universal Taobao ])

I have all these files. I wanted to share them for free, but CSDN resources have to be credited. If you want to send me a private message for free.

CSDN download link [ opencv3_cmake_files ]:

https://download.csdn.net/download/qq_30155503/10305922

File download list:

boostdesc_bgm.i  boostdesc_bgm_bi.i  boostdesc_bgm_hd.i   boostdesc_binboost_064.i   boostdesc_binboost_128.i

boostdesc_binboost_256.i   boostdesc_lbgm.i   ippicv_linux_20151201.tgz   protobuf-cpp-3.1.0.tar.gz

vgg_generated_48.i   vgg_generated_64.i   vgg_generated_80.i   vgg_generated_120.i



4. Compile

$ make

Long compilation road. . . . . . In the end, the compilation was successful.

Sorry to tell you that this is only the result of version 3.2.


The results of version 3.4 are as follows:

Error one:

In file included from /root/library/opencv/opencv-3.4.0/modules/stitching/include/opencv2/stitching.hpp:49:0,
                 from /root/library/opencv/opencv-3.4.0/modules/stitching/src/precomp.hpp:59,
                 from /root/library/opencv/opencv-3.4.0/build/modules/stitching/opencv_stitching_pch_dephelp.cxx:1:
/root/library/opencv/opencv-3.4.0/modules/stitching/include/opencv2/stitching/detail/matchers.hpp:52:42: fatal error: opencv2/xfeatures2d/cuda.hpp: No such file or directory
 #  include "opencv2/xfeatures2d/cuda.hpp"
                                          ^
compilation terminated.
[ 24%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/field_mask.pb.cc.o
[ 24%] Linking CXX static library ../../lib/libopencv_test_face_pch_dephelp.a
[ 24%] Built target opencv_test_face_pch_dephelp
[ 24%] Generate files for Python bindings and documentation
make[2]: *** [modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/opencv_stitching_pch_dephelp.cxx.o] 错误 1
make[1]: *** [modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/all] 错误 2
make[1]: *** Waiting for unfinished task....

Opencv2/xfeatures2d/cuda.hpp not found ? ? ?

or

Error two:

[ 84%] Built target pch_Generate_opencv_xfeatures2d
[ 84%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/boostdesc.cpp.o
/root/library/opencv/opencv-3.4.0/opencv_contrib-3.4.0/modules/xfeatures2d/src/boostdesc.cpp:646:37: fatal error: boostdesc_bgm.i: No such file or directory
           #include "boostdesc_bgm.i"
                                     ^
compilation terminated.
make[2]: *** [modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/boostdesc.cpp.o] 错误 1
make[1]: *** [modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/all] 错误 2
make: *** [all] Error 2

How to solve this situation? Recalling the 3.2 version, you may think that cmake failed to download files in the build directory.

When the opencv-3.4.0 version of cmake fails to download the file, it will not terminate but continue, giving you the illusion that everything is normal.

However, come out and mix, sooner or later you will have to pay it back. 3.4 something happened when make.

Go back to cmake again, turn over the output information, and you will find that many download failed are as follows:

-- xfeatures2d/boostdesc: Download: boostdesc_lbgm.i
CMake Warning at cmake/OpenCVDownload.cmake:190 (message):
  xfeatures2d/boostdesc: Download failed: 1;"Unsupported protocol"

Therefore, it is still necessary to operate according to the above honestly.

However, 3.4 does not seem to prompt a specific file directory. . . Anyway, I chose 3.2, but I haven't tried 3.4.


5. Installation

$ make install

smoothly!












Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325521801&siteId=291194637