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
git clone https://github.com/opencv/opencv_contrib.git
git clone https://github.com/opencv/opencv.git
mkdir build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_ENABLE_NONFREE=ON -DOPENCV_ENABLE_NONFREE:BOOL=ON -D ENABLE_FAST_MATH=1 -D WITH_CUBLAS=1 -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -D WITH_JAVA=OFF -D WITH_WEBP=OFF -D BUILD_EXAMPLES=off -D OPENCV_GENERATE_PKGCONFIG=ON ..
make -j$(nproc)
sudo make install
==========================================================================
boostdesc_bgm_bi.i boostdesc_binboost_128.i vgg_generated_48.i
boostdesc_bgm_hd.i boostdesc_binboost_256.i vgg_generated_64.i
boostdesc_bgm.i boostdesc_lbgm.i vgg_generated_80.i
boostdesc_binboost_064.i vgg_generated_120.i
需要文件下载地址
并且把opencv/modules/features2d 拷贝到opencv_contrib/modules/xfeatures2d/test中
42行的"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/"改为"file:///home/xxx/opencv/3rdparty/ippicv/"即可。
下载地址
创建build文件并camke
命令说明:
-D OPENCV_GENERATE_PKGCONFIG=ON:OpenCV4以上版本默认不使用pkg-config,该编译选项开启生成opencv4.pc文件,支持pkg-config功能。
-D CMAKE_INSTALL_PREFIX=/usr/local:指定安装目录。
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_ENABLE_NONFREE=ON -D WITH_CUDA=ON -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D CUDA_ARCH_BIN=7.5 -D WITH_CUBLAS=1 -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -D HAVE_OPENCV_PYTHON3=ON -D PYTHON3_EXECUTABLE=/usr/local/bin/python3.7.7/bin/python3.7 -D WITH_WEBP=OFF -D BUILD_EXAMPLES=off -D OPENCV_GENERATE_PKGCONFIG=ON ..
make -j$(nproc)
sudo make install
=========================================================================
cmake开启OPENCV_GENERATE_PKGCONFIG=ONpkg-config --libs opencv4 就应该可以找到lib 就不需要此步骤
sudo find / -iname opencv4.pc
==》/usr/local/lib/pkgconfig/opencv4.pc
sudo gedit /etc/profile.d/pkgconfig.sh
加入
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
然后激活
source /etc/profile
pkg-config --libs opencv4
-L/usr/local/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cudabgsegm -lopencv_cudafeatures2d -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_highgui -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_cudacodec -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_cudaoptflow -lopencv_optflow -lopencv_cudalegacy -lopencv_videoio -lopencv_cudawarping -lopencv_viz -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_imgproc -lopencv_cudaarithm -lopencv_core -lopencv_cudev
sudo gedit /etc/ld.so.conf.d/opencv4.conf “opencv4.conf 文件可能为空”
加入
/usr/local/lib
刷新
sudo ldconfig
sudo find / -iname cv2*.so
/usr/local/lib/python2.7/dist-packages/cv2/python-2.7/cv2.so
/usr/local/lib/python3.7/site-packages/cv2/python-3.7/cv2.cpython-37m-x86_64-linux-gnu.so
/usr/local/bin/python3.7.7/lib/python3.7/site-packages/cv2/cv2.cpython-37m-x86_64-linux-gnu.so
/usr/local/bin/python3.7.7/lib/python3.7/site-packages/cv2.so
sudo ln -s /usr/local/lib/python3.7/site-packages/cv2/python-3.7/cv2.cpython-37m-x86_64-linux-gnu.so /usr/local/lib/python3.7/site-packages/cv2.so
opencv4.5
opencv/opencv_contrib/modules/xfeatures2d/test/features2d/misc/java/src/cpp/features2d_converters.cpp:2:10: fatal error: common.h: 没有那个文件或目录
2 | #include “common.h”
解决方法:
1、想办法让其找到common.h
2、想办法不让其编译此test模块,最暴力的方法把test文件夹删除