Install both OpenCV3.4.0&OpenCV2.4.13 on Ubuntu16.04 with CUDA9.0

正文索引 [隐藏]

Michael Chen 12/11/2018

How to install OpenCV3.4.0 you can see OpenCV 3.4.0配置教程
This blog is installing 2.4.13 based on 3.4.0 installed, the most important thing is changing the installation path of 2.4.13, creat a direction in /usr (ex local1)
You will meet the error

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.

opencv_dep_CUDA_nppi_LIBRARY

Reason:
cuda9 don’t support OpenCV2.x

Solution

1)find FindCUDA.cmake

change

find_cuda_helper_libs(nppi)

to

  find_cuda_helper_libs(nppial)
  find_cuda_helper_libs(nppicc)
  find_cuda_helper_libs(nppicom)
  find_cuda_helper_libs(nppidei)
  find_cuda_helper_libs(nppif)
  find_cuda_helper_libs(nppig)
  find_cuda_helper_libs(nppim)
  find_cuda_helper_libs(nppist)
  find_cuda_helper_libs(nppisu)
  find_cuda_helper_libs(nppitc)

2)change

set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")

to

set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")

3)change

unset(CUDA_nppi_LIBRARY CACHE)

to

unset(CUDA_nppial_LIBRARY CACHE)
unset(CUDA_nppicc_LIBRARY CACHE)
unset(CUDA_nppicom_LIBRARY CACHE)
unset(CUDA_nppidei_LIBRARY CACHE)
unset(CUDA_nppif_LIBRARY CACHE)
unset(CUDA_nppig_LIBRARY CACHE)
unset(CUDA_nppim_LIBRARY CACHE)
unset(CUDA_nppist_LIBRARY CACHE)
unset(CUDA_nppisu_LIBRARY CACHE)
unset(CUDA_nppitc_LIBRARY CACHE)

4)find OpenCVDetectCUDA.cmake

change

  set(__cuda_arch_ptx "")
  if(CUDA_GENERATION STREQUAL "Fermi")
    set(__cuda_arch_bin "2.0")
  elseif(CUDA_GENERATION STREQUAL "Kepler")
    set(__cuda_arch_bin "3.0 3.5 3.7")
  ```

to

set(__cuda_arch_ptx “”)
if(CUDA_GENERATION STREQUAL “Kepler”)
set(__cuda_arch_bin “3.0 3.5 3.7”)
elseif(CUDA_GENERATION STREQUAL “Maxwell”)
set(__cuda_arch_bin “5.0 5.2”)
“`

5)

change opencv-2.4.13/modules/gpu/include/opencv2/gpu/device/common.hpp

add a line to common.hpp

#include <cuda_fp16.h>

cmake again