ubuntu16.04上安装opencv3.3教程
安装准备
- 下载opencv3.3源码包
安装过程
安装依赖
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 libjasper-dev libdc1394-22-dev
安装opencv
## STEP2: 将opencv安装包拷贝进容器中
sudo docker cp /home/face/software/opencv-3.3.0 face-gpu:/root/
## STEP2:正式安装
unzip opencv-3.3.0.zip
cd opencv-3.3.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_prefix=/usr/local -D WITH_CUDA=OFF-D .. #别忘了cmake最后面的两个点,代表Cmak config的路径
make -j 10
sudo make install
添加python支持
如果上述步骤完成import cv2没问题,则这步阔以不做
cp /usr/local/lib/python2.7/site-packages/cv2.so /usr/lib/python2.7/site-packages/
# 如果是沙箱安装的话,~/programs/py2_env 这个以你实际的安装路径为准
cp /usr/local/lib/python2.7/site-packages/cv2.so ~/programs/py2_env/lib/python2.7/site-packages/
安装问题
1. 在ippicv_linux_20151201.tgz下载失败
问题如下
由于网络原因,下载ippicv_linux_20151201.tgz超时
fail download ippicv_linux_20151201.tgz
解决方案
手动下载ippicv_linux_20151201.tgz,并将其添加到/usr/face/software/opencv-3.3.0/.cache/ippicv/中,使其直接从这个文件夹中,不从网上下载。下载链接为:http://www.linuxfromscratch.org/blfs/view/8.1/general/opencv.html
# 必须给下载下来的ippicv_linux_20151201.tgz重命名为/usr/face/software/opencv-3.3.0/.cache/ippicv/已有的ippicv的文件名,每台电脑的文件名不一样。
mv ippicv_2017u2_lnx_intel64_20170418.tgz 87cbdeb627415d8e4bc811156289fa3a-ippicv_2017u2_lnx_intel64_20170418.tgz
2. numpy版本问题
问题如下
>>> import cv2
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import
解决方案
更新numpy版本
pip install -U numpy
3. opencv使用cuda进行编译错误
错误如下
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_cufft_LIBRARY (ADVANCED)
linked by target "opencv_cudev" in directory E:/opencv/sources/modules/cudev
linked by target "opencv_test_cudev" in directory E:/opencv/sources/modules/cudev/test
linked by target "opencv_core" in directory E:/opencv/sources/modules/core
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_cufft_LIBRARY (ADVANCED)
linked by target "opencv_cudev" in directory E:/opencv/sources/modules/cudev
linked by target "opencv_test_cudev" in directory E:/opencv/sources/modules/cudev/test
linked by target "opencv_core" in directory E:/opencv/sources/modules/core
解决方案
编译时,设置WITH_CUDA=OFF
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_prefix=/usr/local -D WITH_CUDA=OFF -D ..
4. 编译命令问题 No cmake script provided.
解决方案
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_prefix=/usr/local -D WITH_CUDA=OFF-D .. #最后一个-D不能有空格