ubuntu16.04上安装opencv3.3教程

本文详细介绍了如何在Ubuntu16.04系统上安装OpenCV3.3,包括安装前的准备、安装过程及解决常见问题的方法。文中还特别提到了如何解决安装过程中可能遇到的依赖项、numpy版本以及CUDA编译等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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不能有空格
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值