https://blog.csdn.net/u012321968/article/details/105364113?utm_source=app
1.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
2./opencv-3.4.6/modules中的CMakeLists.txt中加上:
include_directories( #记得换成自己主机上的路径,相对路径也可以 ../../opencv_contrib-3.4.6/modules/xfeatures2d/include )
3.将ippicv_2019_lnx_intel64_general_20180723.tgz 放到opencv3.4.6/3rdparty/ippicv/下,
vim opencv3.4.6/3rdparty/ippicv/ippicv.cmake
找到ocv_download
将里面的网址那一行加#注释掉,新增一行
#"https://raw.githubsercontent.com/opencv/opencv_3reparty/${IPPICV_COMMIT}/ippicv/"
"file:./"
4.cd opencv-3.4.6/modules/cudacodec/src
修改以下五个文件如下:将#if CUDA_VERSION >= 9000 改为 #if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
修改前:
cuvid_video_source.hpp:47:#if CUDA_VERSION >= 9000
frame_queue.hpp:50:#if CUDA_VERSION >= 9000
precomp.hpp:59: #if CUDA_VERSION >= 9000
video_parser.hpp:47:#if CUDA_VERSION >= 9000
video_decoder.hpp:47:#if CUDA_VERSION >= 9000
修改后:
cuvid_video_source.hpp:47:#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
frame_queue.hpp:50:#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
precomp.hpp:59: #if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
video_parser.hpp:47:#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
video_decoder.hpp:47:#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
4.cd opencv-3.4.6
mkdir build
rm -rf ./*
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.6/modules -D PYTHON_EXCUTABLE=/usr/bin/python -D WITH_CUDA=ON -D WITH_CUBLAS=ON -D WITH_GTK=ON -D WITH_GTK_2_X=ON -D CUDA_GENERATION=Auto ..
sudo make install
5.~/.bashrc 添加环境变量
echo '#opencv 3.4.6' >> ~/.bashrc
echo 'export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
6.测试准备一张图片
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char* argv[]){
const char* imagename="lena.jpg";
Mat image = imread(imagename);
imshow("image",image);
waitKey();
return 0;
}
编译以下命令二选一
g++ -o test_opencv test_opencv.cpp -lopencv_core -lopencv_highgui -lopencv_imgcodecs
或者
g++ test_opencv.cpp -o test_opencv `pkg-config --cflags --libs opencv`
测试
./test_opencv