Compiling the opencv_contrib on ubuntu20.04

My computer configurations are:

  • gcc 11.1.0
  • cuda 11.8
  • cudnn 8.6.0
  • numpy 1.5.3
  • pandas 2.0.2
  • matplotlib 3.7.0
  • scipy 1.10.0

I act as this:

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
cd opencv-4.7.0
mkdir build
cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make -j8

and act like this:

$ cd <opencv_build_directory>
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
$ make -j5

Errors occurred as follows:

[ 94%] Built target opencv_perf_stereo
[ 94%] Built target opencv_test_superres
[ 94%] Built target opencv_perf_superres
[ 95%] Built target opencv_perf_gapi
[ 95%] Building CXX object modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o
[ 95%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o
[100%] Built target opencv_test_gapi
In file included from /home/hitcrt/Downloads/opencv-4.7.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:7,
                 from /home/hitcrt/Downloads/opencv-4.7.0/modules/python/src2/cv2.cpp:88:
/home/hitcrt/Downloads/opencv_contrib-4.7.0/modules/phase_unwrapping/misc/python/pyopencv_phase_unwrapping.hpp:2:13: error: ‘phase_unwrapping’ in namespace ‘cv’ does not name a type
    2 | typedef cv::phase_unwrapping::HistogramPhaseUnwrapping::Params HistogramPhaseUnwrapping_Params;
      |             ^~~~~~~~~~~~~~~~
In file included from /home/hitcrt/Downloads/opencv-4.7.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:8,
                 from /home/hitcrt/Downloads/opencv-4.7.0/modules/python/src2/cv2.cpp:88:
/home/hitcrt/Downloads/opencv_contrib-4.7.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:3:40: error: ‘ppf_match_3d’ was not declared in this scope
    3 | template<> struct pyopencvVecConverter<ppf_match_3d::Pose3DPtr >
      |                                        ^~~~~~~~~~~~
/home/hitcrt/Downloads/opencv_contrib-4.7.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:3:64: error: template argument 1 is invalid
    3 | template<> struct pyopencvVecConverter<ppf_match_3d::Pose3DPtr >
      |                                                                ^
/home/hitcrt/Downloads/opencv_contrib-4.7.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:16:21: error: ‘ppf_match_3d’ was not declared in this scope
   16 | typedef std::vector<ppf_match_3d::Pose3DPtr> vector_Pose3DPtr;
      |                     ^~~~~~~~~~~~
/home/hitcrt/Downloads/opencv_contrib-4.7.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:16:44: error: template argument 1 is invalid
   16 | typedef std::vector<ppf_match_3d::Pose3DPtr> vector_Pose3DPtr;
      |                                            ^
/home/hitcrt/Downloads/opencv_contrib-4.7.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:16:44: error: template argument 2 is invalid
In file included from /home/hitcrt/Downloads/opencv-4.7.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:15,
                 from /home/hitcrt/Downloads/opencv-4.7.0/modules/python/src2/cv2.cpp:88:
/home/hitcrt/Downloads/opencv_contrib-

      |                         erode
/home/hitcrt/Downloads/opencv_contrib-4.7.0/modules/barcode/misc/python/pyopencv_barcode.hpp:2:45: error: template argument 1 is invalid
    2 | typedef std::vector<cv::barcode::BarcodeType> vector_BarcodeType;
      |                                             ^
/home/hitcrt/Downloads/opencv_contrib- 
  4.7.0/modules/barcode/misc/python/pyopencv_barcode.hpp:2:45: error: template argument 2 is invalid
/home/hitcrt/Downloads/opencv_contrib-
  229 | bool pyopencv_to(PyObject* obj, cv::Vec2d& v, ArgInfo& info);ct* obj, cv::Vec2f& v, ArgInfo& info);
      |      ^~~~~~~~~~~

/home/hitcrt/Downloads/opencv-4.7.0/modules/python/src2/cv2_convert.hpp:227:6: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3i&, ArgInfo&)’
  227 | bool pyopencv_to(PyObject* obj, cv::Vec3i& v, ArgInfo& info);
      |      ^~~~~~~~~~~
/home/hitcrt/Downloads/opencv-4.7.0/modules/python/src2/cv2_convert.hpp:225:6: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3f&, ArgInfo&)’
  225 | bool pyopencv_to(PyObject* obj, cv::Vec3f& v, ArgInfo& info);
      |      ^~~~~~~~~~~
/home/hitcrt/Downloads/opencv-4.7.0/modules/python/src2/cv2_convert.hpp:223:6: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3d&, ArgInfo&)’
  223 | bool pyopencv_to(PyObject* obj, cv::Vec3d& v, ArgInfo& info);
      |      ^~~~~~~~~~~
/home/hitcrt/Downloads/opencv-4.7.0/modules/python/src2/cv2_convert.hpp:221:6: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4i&, ArgInfo&)’
  221 | bool pyopencv_to(PyObject* obj, cv::Vec4i& v, ArgInfo& info);
      |      ^~~~~~~~~~~
/home/hitcrt/Downloads/opencv-4.7.0/modules/python/src2/cv2_convert.hpp:219:6: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4f&, ArgInfo&)’
  219 | bool pyope>
      |                                                         ^
/home/hitcrt/Downloads/opencv_contrib-4.7.0/modules/rgbd/misc/python/pyopencv_linemod.hpp:30:40: error: ‘linemod’ was not declared in this scope

Because I can only use two links,the message is not enough ablove.
The errors are below:

/home/hitcrt/Downloads/opencv_contrib-4.7.0/modules/mcc/include/opencv2/mcc/checker_model.hpp:95:29: note:     ‘virtual cv::Point2f cv::mcc::CChecker::getCenter()’
   95 |     CV_WRAP virtual Point2f getCenter() = 0;
      |                             ^~~~~~~~~
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/build.make:76: modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:8282: modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
make: *** [Makefile:166: all] Error 2