Ubuntu20.04安装opencv4.4.0+opencv-contrib4.4.0
1.下载源文件
在OpenCV的官方网站下载OpenCV的4.4.0源文件
OpenCV源文件下载地址
并下载4.4.0版本的contrib包
OpenCV_contrib下载地址
2.解压
将opencv-contrib安装在opencv中
3.安装依赖
首先,更新一下
sudo apt-get update
sudo apt-get upgrade
然后安装依赖包
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 qt5-default ccache libv4l-dev libavresample-dev libgphoto2-dev libopenblas-base libopenblas-dev doxygen openjdk-8-jdk pylint libvtk6-dev
sudo apt-get install pkg-config
其中遇见无法安装libjasper-dev的问题
解决方案:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
然后再次安装
sudo apt install libjasper1 libjasper-dev
4. 安装CMake-gui, 并执行
4.1 安装CMake-gui
sudo apt-get install cmake-qt-gui
进入opencv文件夹,打开终端,然后输入以下指令:
mkdir build
cd build
4.2 进入CMake的图形化界面
继续输入以下指令:
cmake-gui ..
弹出以下对话框
点击左下方的Configure按钮,选择Unix Makefiles,选择Use default native compilers(默认),然后点击Finish:
确认源路径和构建路径无误,点击configure
4.3 针对个人需求进行修改
1)在CMAKE_BUILD_TYPE 值处输入Release
2)在OPENCV_EXTRA_MODULES_PATH处,选择输入目录(单击这一行后方空白处即可选中),选到我们刚才解压的opencv-contrib-4.4.0/modules文件夹
3)在OPENCV_ENABLE_NONFREE这个地方也要打上勾,SIFT、SURF算子
修改完以后,继续点configure,会有报错,根本原因是文件缺失。
点击configure后的错误显示在configure按钮上面的对话框中,紧挨着configure按钮。在对话框中有一些错误的红色语句(参考)
1、ippicv_2020_win_intel64_20191018_general.zip下载失败
2、opencv_videoio_ffmpeg_64.dll、opencv_videoio_ffmpeg.dll下载失败
3、boostdesc_bgm.i相关文件下载失败
4、vgg_generated_120.i相关文件下载失败
5、face_landmark_model.dat下载失败
我是直接替换隐藏文件“.cache”,在压缩包“opencv4.4.0确缺失文件.zip”中有一个隐藏文件“.cache”,将其替换opencv安装目录下的隐藏文件“.cache”,就可解决文件缺失问题
4.4 点击Generate生成配置文件在build目录下打开终端,输入
4.5 在build目录下打开终端,输入
make
sudo make install
5. OpenCV配置
打开文件
sudo gedit /etc/ld.so.conf.d/opencv.conf
在文档中添加
/usr/local/lib
配置库
sudo ldconfig
更改环境变量
sudo gedit /etc/bash.bashrc
在文件的最后添加
export PKG_CONFIG_PATH=/usr/local/opencv/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/opencv/lib
保存退出,执行下面生效,到此,安装和配置的整个过程都完成
source /etc/bash.bashrc
6. 由于OpenCV版本高导致的错误
error: ‘CV_LOAD_IMAGE_UNCHANGED’ was not declared in this scope
CV_LOAD_IMAGE_UNCHANGED 改为 cv::IMREAD_UNCHANGED
error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
CV_LOAD_IMAGE_GRAYSCALE 改为 cv::IMREAD_GRAYSCALE
error: ‘CV_MINMAX’ was not declared in this scope文章来源:https://www.toymoban.com/news/detail-613886.html
CV_MINMAX 改成 NORM_MINMAX
error: ‘CV_BGR2GRAY’ was not declared in this scope cvtColor文章来源地址https://www.toymoban.com/news/detail-613886.html
添加 #include <opencv2\imgproc\types_c.h>
到了这里,关于Ubuntu20.04安装opencv4.4.0+opencv-contrib4.4.0 及错误的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!