opencv笔记

环境搭建

Windows10下安装

1. 安装Python

2. 依次安装

pip install numpy
pip install matplotlib
pip install opencv-python
pip install opencv-contrib-python
  • 在IDLE中输入下列命令,没有报错就OK:
import cv2 as cv
print( cv.__version__ )

Ubuntu18.04下安装

1. 安装依赖包(Ubuntu18.04)

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
  • libjasper-dev 模块在Ubuntu18.04中无法安装,但不影响使用

  • 可以多安装 python3-devpython3-numpy 模块供python3使用

sudo apt-get install python3-dev python3-numpy

2. 下载 opencvopencv_contrib (以3.4.1版本为例)

3. 在 ~ 目录新建文件夹 opencv,把前面下载的opencv和opencv_contrib解压到opencv文件夹

  • opencv-3.4.1 //解压opencv得到的文件夹

  • opencv_contrib-3.4.1 //解压opencv_contrib得到的文件夹

4. 命令

cd opencv/opencv-3.4.1
mkdir build && cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib-3.4.1/modules -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make
sudo make install

5. 运行samples需要的模块

  • 运行有些python例子的时候会出现 Failed to load module "canberra-gtk-module" 报错
sudo apt-get install libcanberra-gtk-module
  • 运行opencv-3.4.1/samples/python/demo.py时,要安装下列模块
sudo apt-get install python-tk
sudo apt-get install python3-tk    //顺便安装python3版本
  • 运行opencv-3.4.1/samples/python/camera_calibration_show_extrinsics.py时,要安装下列模块
sudo apt-get install python-matplotlib
sudo apt-get install python3-matplotlib    //顺便按照python3版本

results matching ""

    No results matching ""