详见: https://blog.csdn.net/pwb1994001/article/details/81119339
OpenCV3.2+CUDA9.0+Cmake3.9 环境搭建
原因解析:
cuda9不再支持2.0架构 所以不用opencv 2.4而用 opencv3.2
1, 下载OpenCV 3.2.0
wget https://jaist.dl.sourceforge.net/project/opencvlibrary/opencv-unix/3.2.0/opencv-3.2.0.zip
2, 安装依赖库
yum -y install cmake
yum -y install gcc gcc-c++
yum -y install python python-devel numpy
yum -y install gtk2-devel
yum -y install libdc1394-devel
yum -y install libv4l-devel
yum -y install gstreamer-plugins-base-devel
yum -y install gtk+-devel gimp-devel gimp-devel-tools gimp-help-browser zlib-devel libtiff-devel libjpeg-devel libpng-devel libavc1394-devel libraw1394-devel jasper-devel jasper-utils swig libtool nasm
3, 安装OpenCV 3.2.0
下载wget https://raw.githubusercontent.com/Itseez/opencv_3rdparty/81a676001ca8075ada498583e4166079e5744668/ippicv/ippicv_linux_20151201.tgz
unzip opencv-3.2.0.zip
# 替换ippicv_linux_20151201.tgz
mkdir -p opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e
cp ippicv_linux_20151201.tgz opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e
cd opencv-3.2.0
mkdir build
cd build
# cmake(一步一步进行,不用理会warning)
使用此行 cmake -D WITH_IPP=OFF -D WITH_TBB=ON -D WITH_EIGEN=ON ..(正确)
-D WITH_IPP=OFF 的意思是不再下载了
不用这行 xxxx cmake -D WITH_TBB=ON -D WITH_EIGEN=ON .. (错误, 还是要重下ipp)xxxxxx
cmake -D BUILD_DOCS=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF ..
cmake -D WITH_OPENCL=OFF -D WITH_CUDA=OFF -D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF -D BUILD_opencv_gpubgsegm=OFF -D BUILD_opencv_gpucodec=OFF -D BUILD_opencv_gpufeatures2d=OFF -D BUILD_opencv_gpufilters=OFF -D BUILD_opencv_gpuimgproc=OFF -D BUILD_opencv_gpulegacy=OFF -D BUILD_opencv_gpuoptflow=OFF -D BUILD_opencv_gpustereo=OFF -D BUILD_opencv_gpuwarping=OFF ..
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
# make
make -j64
make install
4,动态库配置
/bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
ldconfig
5, 测试
vim test.cpp
//test.cpp
#include
#include
#include
int main(int argc,char *argv[])
{
cv::Mat image;
image=cv::imread("1.png");
cv::namedWindow("1.png");
cv::imshow("1.png",image);
cv::waitKey();
return 0;
}
编译前设置pkgconfig路径
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
g++ -g -o test test.cpp `pkg-config --cflags --libs opencv`
./test