ubuntu16.04,python2.7,opencv3.4.0,安装

啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊

直接 pip install opencv-python


参考:官方教程:https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

 
Ubuntu14.04 OpenCV编译安装:http://blog.csdn.net/honyniu/article/details/46390097

 Ubuntu 17.04系统下源码编译安装opencv的步骤详解:http://www.jb51.net/article/121882.htm


The followingsteps have been tested for Ubuntu 10.04 but should work with other distros aswell.

Required Packages

  • GCC 4.4.x or later
  • CMake 2.8.7 or higher
  • Git
  • GTK+2.x or higher, including headers (libgtk2.0-dev)
  • pkg-config
  • Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
  • ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
  • [optional] libtbb2 libtbb-dev
  • [optional] libdc1394 2.x
  • [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
  • [optional] CUDA Toolkit 6.5 or higher

The packages canbe installed using a terminal and the following commands or by using SynapticManager:

[compiler] sudo apt-get installbuild-essential

[required] sudo apt-get install cmake gitlibgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

[optional] sudo apt-get install python-devpython-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-devlibjasper-dev libdc1394-22-dev

检查numpy是否安装成功

Getting OpenCV Source Code

You can use thelatest stable OpenCV version or you can grab the latest snapshot from our Git repository.

Getting the Latest Stable OpenCV Version

Getting the Cutting-edge OpenCV from the GitRepository

Launch Git clientand clone OpenCVrepository. If you need modules from OpenCV contrib repository thenclone it as well.

For example

cd ~/<my_working_directory>

git clone https://github.com/opencv/opencv.git

git clonehttps://github.com/opencv/opencv_contrib.git

Building OpenCV from Source Using CMake

  1. Create a temporary directory, which we denote as <cmake_build_dir>, where you want to put the generated Makefiles, project files as well the object files and output binaries and enter there.

For example

cd ~/opencv

mkdir build

cd build

  1. Configuring. Run cmake [<some optional parameters>] <path to the OpenCV source directory>

For example

cmake-gui..

出现下面的界面,更改设置,

然后在 Whereis the source code中添加opencv 的目录路径,在where to build the binaries中添加刚才新建的build目录

然后点击下面的Configure,选择 UnixMakefiles,然后选择default ...。点击OK,从而处理 opencv目录下的CMakeLists.txt。并且在Build 目录下生成CMakeCache.txtMakefile 等相关文件。

Configure配置结束后,将会出现类似以下配置界面

以下是需要修改的部分

  1. CMAKE_BUILD_TYPE 修改为 RELEASE

2.   OPENCV_EXTRA_MODULES_PATH设为 opencv_contrib中的 modules 目录的路径(比如,/home/arvin/opencv_contrib/modules

3.    BUILD_EXAMPLES的复选框里打勾

4.   INSTALL_C_EXAMPLES的复选框里打勾

5.   INSTALL_PYTHON_EXAMPLES的复选框里打勾

6.    WITH_FFMPEG的复选框里打勾

7.    WITH_GTK的复选框里打勾

8.    WITH_V4L的复选框里打勾

9.    WITH_TIFF的复选框里打勾

10.  WITH_PNG 的复选框里打勾

11.  WITH_JPEG 的复选框里打勾

12.  WITH_JASPER 的复选框里打勾

13.  取消 WITH_CUDA 的复选框里的勾

14.  取消 WITH_CUFFT 的复选框里的勾

然后点击Configure,应用刚才的修改并且将修改内容更新至 build目录下的 CMakeCache.txt中。然后点击 Generate,更新 Makefile

 

Build. From builddirectory execute make, it is recommended to do this in severalthreads

For example

make -j7 # runs 7 jobs in parallel

 

Toinstall libraries, execute the following command from build directory

sudo make install

 

环境变量

安装成功后还需要设置opencv的环境变量 
打开文件

sudo gedit /etc/profile##个人比较喜欢把环境变量放在/etc/profile里面,'~/.bashrc'一样

·       1

在文件最后添加

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

·       1

执行下列命令, 使环境变量立即生效

source /etc/profile

·       1

lib库路径

打开文件

sudo gedit /etc/ld.so.conf.d/opencv.conf

·       1

一般是新建文件,opencv的库一般安装在’/usr/local/lib’文件夹下,在文件内添加

/usr/local/lib

·       1

执行下列命令使之立刻生效

sudo ldconfig

 

测试环境是否配置成功

# 在命令行打开你的python解释器,输入以下命令

import cv2

cv2.__version__

# 若看到类似以下输出,则表示配置成功

'3.4.0-dev'


 python3.5不行,怎么配置?


如果将默认的python先改成python3.5,再安装opencv,是不是opencv就装在python3.5里了呢?

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值