Linux Opencv 环境搭建

Linux Opencv 环境搭建

1.换源:
cd /etc/apt
sudo gedit sources.list

将里面内容替换为阿里云的源:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
之后执行
sudo apt-get update
sudo apt upgrade
2.安装必要依赖库:
直接在命令行输入以下命令:
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

sudo apt-get install cmake-gui

上面命令执行会报错,错误说libjaster-dev无法安装,解决办法如下:
sudo add-apt-repository “deb http://security.ubuntu.com/ubuntu xenial-security main”
sudo apt update
sudo apt install libjasper1 libjasper-dev

3.若要安装 opencv_contrib 需要执行以下步骤:

将opencv_contrib 文件夹移动到 opencv文件夹中

4.将OpenCV_boostdesc_vgg_file-master.zip解压并将解压得到的文件复制在把目录
opencv_contrib/modules/xfeatures2d/src/下即可。
opencv安装包
Linux Opencv 环境搭建_第1张图片
5.进入opencv文件夹建立build文件夹cmake-gui(依次敲入以下命令)
mkdir build
cmake-gui
Linux Opencv 环境搭建_第2张图片

出现红框后,需要进行选择。

在OpenCV_EXTRA_MODULES_PATH处,选择输入目录(单击这一行后方空白处即可选中), 然后选择OpenCV_contrib-3.4.8文件夹中的modules文件夹。

选中“BUILD_OpenCV_world”选项旁边的复选框。
再次点击configure

点击generate,cake-gui的使命结束了

6.为了防止出现以下错误

/usr/local/arm/opencv-3.4.0/opencv_contrib-3.4.0/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp:42:10:
fatal error: /opencv2/xfeatures2d.hpp: No such file or directory
#include “/opencv2/xfeatures2d.hpp”
^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

进入相应的文件夹:

Linux Opencv 环境搭建_第3张图片
将相应的路径改为绝对路径,如上图

7.在build文件夹下

sudo make
sudo make install

你可能感兴趣的:(ubuntu,linux,运维)