1070安装opencv
sudo apt-get install python-dev
sudo apt-get install pip
sudo apt-get install python-opencv #保证Python接口import CV2可用
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 libdc1394-22-dev # 处理图像所需的包
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包
sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能
sudo apt-get install ffmpeg
sudo apt-get install libjasper-dev
最后一个报错:
Done E: Unable to locate package libjasper-dev
解决:
sudo add-apt-repository “deb http://security.ubuntu.com/ubuntu xenial-security main”
sudo apt update
sudo apt install libjasper1 libjasper-dev
下载地址
https://opencv.org/releases.html
并解压
cd opencv-3.4.1
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D PYTHON_INCLUDE_DIR=/usr/include/python2.7 -D PYTHON_LIBRARY=/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so ..
make -j32
sudo make install
make时间会比较长,20分钟
## 添加路径
sudo vim /etc/ld.so.conf.d/opencv.conf
写入
/usr/local/lib
配置bash
sudo vim /etc/bash.bashrc
写入
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
使生效
source /etc/bash.bashrc
sudo updatedb
结束后
c测试
进入opencv-3.4.1/samples/cpp/example_cmake目录下
sudo cmake .
sudo make
./opencv_example
python测试
pyhton
import cv2
ref
https://blog.csdn.net/JohinieLi/article/details/79885820
https://blog.csdn.net/u010801994/article/details/80682444
https://blog.csdn.net/lupengCSDN/article/details/80397000
下载opencv.zip
要提前安装依赖项。
sudo apt-get install liblapacke-dev checkinstall
先更新一下下载源。用17.04 的源可以解决在18.04中找不到libjasper.dev的问题。
ref
https://stackoverflow.com/questions/43484357/opencv-in-ubuntu-17-04
libjasper-dev无法安装
errorE: unable to locate libjasper-dev
解决方法
sudo add-apt-repository “deb http://security.ubuntu.com/ubuntu xenial-security main”
sudo apt update
sudo apt install libjasper1 libjasper-dev
报错:
-- Checking for module 'gstreamer-base-1.0'
-- No package 'gstreamer-base-1.0' found
-- Checking for module 'gstreamer-video-1.0'
-- No package 'gstreamer-video-1.0' found
-- Checking for module 'gstreamer-app-1.0'
-- No package 'gstreamer-app-1.0' found
-- Checking for module 'gstreamer-riff-1.0'
-- No package 'gstreamer-riff-1.0' found
-- Checking for module 'gstreamer-pbutils-1.0'
-- No package 'gstreamer-pbutils-1.0' found
-- Checking for module 'gstreamer-base-0.10'
-- No package 'gstreamer-base-0.10' found
-- Checking for module 'gstreamer-video-0.10'
-- No package 'gstreamer-video-0.10' found
-- Checking for module 'gstreamer-app-0.10'
-- No package 'gstreamer-app-0.10' found
-- Checking for module 'gstreamer-riff-0.10'
-- No package 'gstreamer-riff-0.10' found
-- Checking for module 'gstreamer-pbutils-0.10'
-- No package 'gstreamer-pbutils-0.10' found
解决方法
ref
https://stackoverflow.com/questions/37678324/compiling-opencv-with-gstreamer-cmake-not-finding-gstreamer
安装
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
报错
-- CUDA detected: 9.0
-- CUDA NVCC target flags: -gencode;arch=compute_20,code=sm_20;-gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_52,code=sm_52;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-D_FORCE_INLINES
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY Atlas_LAPACK_LIBRARY)
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
解决方法
https://blog.csdn.net/weixin_41896508/article/details/80795239?utm_source=blogxgwz0
JNI是用于java不需要就没有安装
报错
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:
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/dong/Downloads/opencv-3.2.0/modules/cudev
linked by target "opencv_cudev" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudev
linked by target "opencv_test_cudev" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudev/test
linked by target "opencv_test_core" in directory /home/dong/Downloads/opencv-3.2.0/modules/core
linked by target "opencv_core" in directory /home/dong/Downloads/opencv-3.2.0/modules/core
linked by target "opencv_core" in directory /home/dong/Downloads/opencv-3.2.0/modules/core
linked by target "opencv_perf_core" in directory /home/dong/Downloads/opencv-3.2.0/modules/core
linked by target "opencv_test_cudaarithm" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaarithm
linked by target "opencv_cudaarithm" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaarithm
linked by target "opencv_cudaarithm" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaarithm
linked by target "opencv_perf_cudaarithm" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaarithm
linked by target "opencv_flann" in directory /home/dong/Downloads/opencv-3.2.0/modules/flann
linked by target "opencv_flann" in directory /home/dong/Downloads/opencv-3.2.0/modules/flann
linked by target "opencv_test_flann" in directory /home/dong/Downloads/opencv-3.2.0/modules/flann
linked by target "opencv_test_imgproc" in directory /home/dong/Downloads/opencv-3.2.0/modules/imgproc
linked by target "opencv_imgproc" in directory /home/dong/Downloads/opencv-3.2.0/modules/imgproc
linked by target "opencv_imgproc" in directory /home/dong/Downloads/opencv-3.2.0/modules/imgproc
linked by target "opencv_perf_imgproc" in directory /home/dong/Downloads/opencv-3.2.0/modules/imgproc
linked by target "opencv_test_ml" in directory /home/dong/Downloads/opencv-3.2.0/modules/ml
linked by target "opencv_ml" in directory /home/dong/Downloads/opencv-3.2.0/modules/ml
linked by target "opencv_ml" in directory /home/dong/Downloads/opencv-3.2.0/modules/ml
linked by target "opencv_test_video" in directory /home/dong/Downloads/opencv-3.2.0/modules/video
linked by target "opencv_perf_video" in directory /home/dong/Downloads/opencv-3.2.0/modules/video
linked by target "opencv_video" in directory /home/dong/Downloads/opencv-3.2.0/modules/video
linked by target "opencv_video" in directory /home/dong/Downloads/opencv-3.2.0/modules/video
linked by target "opencv_test_cudabgsegm" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudabgsegm
linked by target "opencv_cudabgsegm" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudabgsegm
linked by target "opencv_cudabgsegm" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudabgsegm
linked by target "opencv_perf_cudabgsegm" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudabgsegm
linked by target "opencv_test_cudafilters" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudafilters
linked by target "opencv_perf_cudafilters" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudafilters
linked by target "opencv_cudafilters" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudafilters
linked by target "opencv_cudafilters" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudafilters
linked by target "opencv_perf_cudaimgproc" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaimgproc
linked by target "opencv_cudaimgproc" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaimgproc
linked by target "opencv_cudaimgproc" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaimgproc
linked by target "opencv_test_cudaimgproc" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaimgproc
linked by target "opencv_test_cudawarping" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudawarping
linked by target "opencv_cudawarping" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudawarping
linked by target "opencv_cudawarping" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudawarping
linked by target "opencv_perf_cudawarping" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudawarping
linked by target "opencv_test_imgcodecs" in directory /home/dong/Downloads/opencv-3.2.0/modules/imgcodecs
linked by target "opencv_imgcodecs" in directory /home/dong/Downloads/opencv-3.2.0/modules/imgcodecs
linked by target "opencv_imgcodecs" in directory /home/dong/Downloads/opencv-3.2.0/modules/imgcodecs
linked by target "opencv_perf_imgcodecs" in directory /home/dong/Downloads/opencv-3.2.0/modules/imgcodecs
linked by target "opencv_test_photo" in directory /home/dong/Downloads/opencv-3.2.0/modules/photo
linked by target "opencv_photo" in directory /home/dong/Downloads/opencv-3.2.0/modules/photo
linked by target "opencv_photo" in directory /home/dong/Downloads/opencv-3.2.0/modules/photo
linked by target "opencv_perf_photo" in directory /home/dong/Downloads/opencv-3.2.0/modules/photo
linked by target "opencv_shape" in directory /home/dong/Downloads/opencv-3.2.0/modules/shape
linked by target "opencv_shape" in directory /home/dong/Downloads/opencv-3.2.0/modules/shape
linked by target "opencv_test_shape" in directory /home/dong/Downloads/opencv-3.2.0/modules/shape
linked by target "opencv_test_videoio" in directory /home/dong/Downloads/opencv-3.2.0/modules/videoio
linked by target "opencv_videoio" in directory /home/dong/Downloads/opencv-3.2.0/modules/videoio
linked by target "opencv_videoio" in directory /home/dong/Downloads/opencv-3.2.0/modules/videoio
linked by target "opencv_perf_videoio" in directory /home/dong/Downloads/opencv-3.2.0/modules/videoio
linked by target "opencv_test_cudacodec" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudacodec
linked by target "opencv_cudacodec" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudacodec
linked by target "opencv_cudacodec" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudacodec
linked by target "opencv_perf_cudacodec" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudacodec
linked by target "opencv_highgui" in directory /home/dong/Downloads/opencv-3.2.0/modules/highgui
linked by target "opencv_highgui" in directory /home/dong/Downloads/opencv-3.2.0/modules/highgui
linked by target "opencv_test_highgui" in directory /home/dong/Downloads/opencv-3.2.0/modules/highgui
linked by target "opencv_test_objdetect" in directory /home/dong/Downloads/opencv-3.2.0/modules/objdetect
linked by target "opencv_perf_objdetect" in directory /home/dong/Downloads/opencv-3.2.0/modules/objdetect
linked by target "opencv_objdetect" in directory /home/dong/Downloads/opencv-3.2.0/modules/objdetect
linked by target "opencv_objdetect" in directory /home/dong/Downloads/opencv-3.2.0/modules/objdetect
linked by target "opencv_ts" in directory /home/dong/Downloads/opencv-3.2.0/modules/ts
linked by target "opencv_ts" in directory /home/dong/Downloads/opencv-3.2.0/modules/ts
linked by target "opencv_perf_features2d" in directory /home/dong/Downloads/opencv-3.2.0/modules/features2d
linked by target "opencv_test_features2d" in directory /home/dong/Downloads/opencv-3.2.0/modules/features2d
linked by target "opencv_features2d" in directory /home/dong/Downloads/opencv-3.2.0/modules/features2d
linked by target "opencv_features2d" in directory /home/dong/Downloads/opencv-3.2.0/modules/features2d
linked by target "opencv_calib3d" in directory /home/dong/Downloads/opencv-3.2.0/modules/calib3d
linked by target "opencv_calib3d" in directory /home/dong/Downloads/opencv-3.2.0/modules/calib3d
linked by target "opencv_test_calib3d" in directory /home/dong/Downloads/opencv-3.2.0/modules/calib3d
linked by target "opencv_perf_calib3d" in directory /home/dong/Downloads/opencv-3.2.0/modules/calib3d
linked by target "opencv_cudafeatures2d" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudafeatures2d
linked by target "opencv_cudafeatures2d" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudafeatures2d
linked by target "opencv_test_cudafeatures2d" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudafeatures2d
linked by target "opencv_perf_cudafeatures2d" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudafeatures2d
linked by target "opencv_test_cudalegacy" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudalegacy
linked by target "opencv_cudalegacy" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudalegacy
linked by target "opencv_cudalegacy" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudalegacy
linked by target "opencv_perf_cudalegacy" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudalegacy
linked by target "opencv_perf_cudaobjdetect" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaobjdetect
linked by target "opencv_cudaobjdetect" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaobjdetect
linked by target "opencv_cudaobjdetect" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaobjdetect
linked by target "opencv_test_cudaobjdetect" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaobjdetect
linked by target "opencv_test_cudaoptflow" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaoptflow
linked by target "opencv_perf_cudaoptflow" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaoptflow
linked by target "opencv_cudaoptflow" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaoptflow
linked by target "opencv_cudaoptflow" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudaoptflow
linked by target "opencv_test_cudastereo" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudastereo
linked by target "opencv_cudastereo" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudastereo
linked by target "opencv_cudastereo" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudastereo
linked by target "opencv_perf_cudastereo" in directory /home/dong/Downloads/opencv-3.2.0/modules/cudastereo
linked by target "opencv_test_stitching" in directory /home/dong/Downloads/opencv-3.2.0/modules/stitching
linked by target "opencv_stitching" in directory /home/dong/Downloads/opencv-3.2.0/modules/stitching
linked by target "opencv_stitching" in directory /home/dong/Downloads/opencv-3.2.0/modules/stitching
linked by target "opencv_perf_stitching" in directory /home/dong/Downloads/opencv-3.2.0/modules/stitching
linked by target "opencv_perf_superres" in directory /home/dong/Downloads/opencv-3.2.0/modules/superres
linked by target "opencv_superres" in directory /home/dong/Downloads/opencv-3.2.0/modules/superres
linked by target "opencv_superres" in directory /home/dong/Downloads/opencv-3.2.0/modules/superres
linked by target "opencv_test_superres" in directory /home/dong/Downloads/opencv-3.2.0/modules/superres
linked by target "opencv_videostab" in directory /home/dong/Downloads/opencv-3.2.0/modules/videostab
linked by target "opencv_videostab" in directory /home/dong/Downloads/opencv-3.2.0/modules/videostab
linked by target "opencv_traincascade" in directory /home/dong/Downloads/opencv-3.2.0/apps/traincascade
linked by target "opencv_createsamples" in directory /home/dong/Downloads/opencv-3.2.0/apps/createsamples
linked by target "opencv_annotation" in directory /home/dong/Downloads/opencv-3.2.0/apps/annotation
linked by target "opencv_visualisation" in directory /home/dong/Downloads/opencv-3.2.0/apps/visualisation
linked by target "opencv_version" in directory /home/dong/Downloads/opencv-3.2.0/apps/version
解决方法
ref
https://blog.csdn.net/u014613745/article/details/78310916
1).找到FindCUDA.cmake文件
找到行
find_cuda_helper_libs(nppi)
改为
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).找到行
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}")
3).找到行
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)
4).找到文件OpenCVDetectCUDA.cmake
修改以下几行
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")
就是把Fermi架构的if分支选项删除。
5)
将头文件cuda_fp16.h添加至 opencv\modules\cudev\include\opencv2\cudev\common.hpp
打开common.hpp
加入
#include
在opencv-3.2.0下新建build
mkdir build
在build内执行:
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local …cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Auto …
其中CUDA_GENERATION=Auto 为了自动选择cuda框架。否则报错nvcc fatal : Unsupported gpu architecture ‘compute_20’
sudo cmake
make遇到问题:
/home/july/software/opencv-3.2.0/build/opencv_lapack.h:2:45:fatalerror:LAPACKE_H_PATH-NOTFOUND/lapacke.h: 没有那个文件或目录
解决方法:
sudo apt-get install liblapacke-dev checkinstall
还是提示不行的话,
编辑build 当中的opencv_lapack.h
第二行换成
#include “/usr/include/lapacke.h”
设置Python(for build)
更改默认编译Python版本2.7->3.6
-- Python 2:
-- Interpreter: /home/ryu/anaconda2/bin/python2.7 (ver 2.7.11)
-- Python 3:
-- Interpreter: /usr/bin/python3 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m (ver 3.4.3)
-- numpy: /home/ryu/.local/lib/python3.4/site-packages/numpy/core/include (ver 1.11.0)
-- packages path: lib/python3.4/dist-packages
--
-- **Python (for build): /home/ryu/anaconda2/bin/python2.7**
找到’~/opencv-3.2.0/cmake’
‘OpenCVDetectPython.cmake’ 最后的一段代码。
原来的代码:
if(PYTHON_DEFAULT_EXECUTABLE)
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
elseif(PYTHON2INTERP_FOUND) # Use Python 2 as default Python interpreter
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}")
elseif(PYTHON3INTERP_FOUND) # Use Python 3 as fallback Python interpreter (if there is no Python 2)
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON3_EXECUTABLE}")
endif()
改顺序
if(PYTHON_DEFAULT_EXECUTABLE)
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
elseif(PYTHON3INTERP_FOUND) # Use Python 3 as fallback Python interpreter (if there is no Python 2)
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON3_EXECUTABLE}")
elseif(PYTHON2INTERP_FOUND) # Use Python 2 as default Python interpreter
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}")
endif()