pkg-config --modversion opencv
sudo make uninstall
cd ..
sudo rm -r build
sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
cd /usr
find . -name "*opencv*" | xargs sudo rm -rf
然后在home目录下也去搜索opencv,并删除。
opencv官网选择 3.1.0 版本的 source , 下载 opencv-3.1.0.zip。
这个是真的慢,我直接windows下载了再拷贝过来。
解压到你要安装的位置,命令行进入已解压的文件夹 opencv-3.1.0 目录下,执行:
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_nppi_LIBRARY (ADVANCED)
linked by target "opencv_cudev" in directory /home/x/opencv-3.1.0/modules/cudev
linked by target "opencv_cudev" in directory /home/x/opencv-3.1.0/modules/cudev
linked by target "opencv_test_cudev" in directory /home/x/opencv-3.1.0/modules/cudev/test
linked by target "opencv_test_core" in directory /home/x/opencv-3.1.0/modules/core
linked by target "opencv_core" in directory /home/x/opencv-3.1.0/modules/core
linked by target "opencv_core" in directory /home/x/opencv-3.1.0/modules/core
linked by target "opencv_perf_core" in directory /home/x/opencv-3.1.0/modules/core
....
解决:
修改源码包中某些文件:
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)
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")
改为:
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}")
unset(CUDA_nppi_LIBRARY CACHE)
改为: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)
將
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")
改成:
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")
将头文件cuda_fp16.h添加至 opencv\modules\cudev\include\opencv2\cudev\common.hpp
即在common.hpp中添加
#include
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
trick2:
CMake Error at cmake/OpenCVDetectCUDA.cmake:214 (else):
else An ELSE command was found outside of a proper IF ENDIF structure. Or
its arguments did not match the opening IF command.
Call Stack (most recent call first):
cmake/OpenCVFindLibsPerf.cmake:32 (include)
CMakeLists.txt:537 (include)
CMake Error at cmake/OpenCVDetectCUDA.cmake:217 (endif):
endif An ENDIF command was found outside of a proper IF ENDIF structure.
Or its arguments did not match the opening IF command.
Call Stack (most recent call first):
cmake/OpenCVFindLibsPerf.cmake:32 (include)
CMakeLists.txt:537 (include)
由于cuda9以上不再支持2.0架构,在编译的命令里面添加一条-D WITH_CUDA=OFF就行了。
cmake -D CMAKE_BUILD_TYPE=Release -D WITH_CUDA=OFF -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j8
trick3:
/usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
cmake时加上参数-D ENABLE_PRECOMPILED_HEADERS=OFF:
cmake -D CMAKE_BUILD_TYPE=Release -D WITH_CUDA=OFF -D ENABLE_PRECOMPILED_HEADERS=OFF -D CMAKE_INSTALL_PREFIX=/usr/local ..
重新:
make -j8
sudo make install