OpenCV cmake在为Docker构建映像时找不到CUDA

时间:2019-07-04 13:47:59

标签: c++ docker opencv

我正在尝试使用最新的opencv版本4.1.0构建docker映像,以便能够使用cudafeatures2D。我已经安装了cuda 9.0,但是每次我尝试从源代码编译opencv时都说找不到CUDA。

我正在使用来自nvidia / cuda:9.0-cudnn7-runtime的构建运行时映像。我已经在当前图像中检查了CUDA /usr/local/cuda-9.0的位置。

这是我要安装的代码:

ENV PATH=$PATH:/usr/local/cuda/bin:$PATH
ENV LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
RUN ldconfig

RUN wget https://github.com/opencv/opencv/archive/4.1.0.tar.gz && tar xf 4.1.0.tar.gz && rm 4.1.0.tar.gz
RUN wget https://github.com/opencv/opencv_contrib/archive/4.1.0.tar.gz  && tar xf 4.1.0.tar.gz && rm 4.1.0.tar.gz
RUN cd opencv-4.1.0/ && mkdir build && cd build && cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=ON -D WITH_CUBLAS=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_OPENGL=ON -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" -D PYTHON2_EXECUTABLE=/usr/bin/python2.7 -D PYTHON_INCLUDE_DIR=/usr/include/python2.7/ -D PYTHON_INCLUDE_DIR2=/usr/include/x86_64-linux-gnu/python2.7/ -D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so -D PYTHON2_NUMPY_INCLUDE_DIRS=/usr/local/lib/python2.7/dist-packages/numpy/core/include/  -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.0/modules/ -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-9.0 -D CUDA_CUDART_LIBRARY=/usr/local/cuda/lib64/libcudart.so -D CUDA_VERBOSE_BUILD=ON .. && make -j$(nproc) && make install

但是我总是会收到此错误:

-- at: /app/opencv-3.4.6/build/3rdparty/ippicv/ippicv_lnx/iw
CMake Warning at cmake/OpenCVFindLibsPerf.cmake:35 (message):
  OpenCV is not able to find/configure CUDA SDK (required by WITH_CUDA).

  CUDA support will be disabled in OpenCV build.

  To eliminate this warning remove WITH_CUDA=ON CMake configuration option.

Call Stack (most recent call first):
  CMakeLists.txt:794 (include)

1 个答案:

答案 0 :(得分:1)

最后,来自opencv存储库的某人指出我遇到的问题是由于我使用的映像造成的:

从nvidia / cud:9.0-cudnn7-runtime

运行时版本通常不包含SDK文件,解决方法是将-runtime更改为-develop。