Ubuntu卸载及安装opencv和报错处理

目录

卸载老版本OpenCV4.1.0

安装新版本OpenCV4.3.0以及OpenCV_contrib4.3.0

opencv缺失文件下载

问题及解决


 

卸载OpenCV4.1.0

1.查看版本

opencv_version

2.卸载opencv

cd /usr/local/opencv-4.1.0/build

sudo make uninstall

cd ..

sudo rm -r build

如果找不到 build 目录,可以重新建立 build 目录安装对应版本,再执行卸载步骤。

然后清理 /usr 中所有 opencv 相关项

sudo rm -r /usr/local/include/opencv4 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv4 /usr/local/share/opencv /usr/local/share/opencv4 /usr/share/opencv /usr/share/opencv /usr/local/bin/opencv* /usr/local/lib/libopencv*

cd /usr

find . -name "*opencv*" | xargs sudo rm -rf

cd /usr/local/

rm -r opencv-4.1.0/

3.移除 python 相关

apt-get remove opencv-data python-opencv

 

安装OpenCV4.3.0以及OpenCV_contrib4.3.0

1.下载两个安装包 opencv-4.3.0.zip 和 opencv_contrib-4.3.0.zip

https://github.com/opencv/opencv_contrib/releases

2.更新系统下载工具

sudo apt-get update

3.安装所需依赖项

sudo apt-get install build-essential

sudo apt-get install libopenblas-dev

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 ant

4.分别上传解压到目录/usr/local

sudo unzip opencv-4.3.0.zip 如果没有unzip则安装sudo apt-get install unzip zip

sudo unzip opencv_contrib-4.3.0.zip

将opencv_contrib文件夹mv到opencv-4.3.0目录下

sudo mv opencv_contrib-4.3.0 opencv-4.3.0/

5.编译

cd opencv-4.3.0

sudo mkdir build  #创建build目录

cd build/

sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.3.0/modules/ ..

(下载文件时间有点长,有两个文件下载比较慢,如果需可以先自己下载然后更改路径,下载地址见后面)

6.安装

sudo make -j8 (8线程编译)

sudo make install

7.查看版本号

opencv_version

8.动态链接库添加到系统

进入目录:cd /etc/ld.so.conf.d

创建: sudo vim opencv.conf

添加:/usr/local/opencv-4.3.0/build/lib

执行:sudo ldconfig

9.额外操作,方便java程序调用

将自己开发的so库和libopencv_java430.so移动到/usr/lib/下面

cp /usr/local/opencv-4.3.0/build/lib/libopencv_java430.so /usr/lib/

或者设置环境变量LD_LIBRARY_PATH指定libopencv_java430.so所在的目录

 

opencv缺失文件下载

ippicv_2020_lnx_intel64_20191018_general.tgz

face_landmark_model.dat

boostdesc_bgm.i

boostdesc_bgm_bi.i

boostdesc_bgm_hd.i

boostdesc_binboost_064.i

boostdesc_binboost_128.i

boostdesc_binboost_256.i

boostdesc_lbgm.i

vgg_generated_120.i

vgg_generated_48.i

vgg_generated_64.i

vgg_generated_80.i

下载地址:https://download.csdn.net/download/renzhehongyi/12636117 

 

问题及解决

问题:查看下载日志

原因:opencv在编译过程中需要下载额外的文件,下载日志是build目录中的CMakeDownloadLog.txt,如果遇到下载问题可以先查看该日志

 

问题:配置下载hosts

原因:CMakeDownloadLog.txt会列出无法访问的网站地址,raw.githubusercontent.com就经常连接失败

解决:用www.ipaddress.com去查raw.githubusercontent.com IP地址(比如185.199.108.133,ip经常变动根据实际情况查询),然后配置hosts文件 添加 185.199.108.133 raw.githubusercontent.com

 

问题:OpenCV - IPPICV 和 face_landmark_model.dat下载不下来的问题

解决:手动下载ippicv_2020_lnx_intel64_20191018_general.tgz文件和face_landmark_model.dat文件,放在/usr/local/opencv-4.3.0/downloads目录 "file:///usr/local/opencv-4.3.0/downloads/"

1、查看文件opencv-4.3.0/3rdparty/ippicv/ippicv.cmake,根据下载地址"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/"和文件名手动下载ippicv文件存放在本地,然后将下载地址改为文件所在位置,例如 "file:///usr/local/opencv-4.3.0/downloads/"。

2、查看文件opencv_contrib-4.3.0/modules/face/CMakeLists.txt,根据下载地址"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${__commit_hash}/"和文件名手动下载face_landmark_model.dat存放在本地,然后将下载地址改为文件所在位置,例如 "file:///usr/local/opencv-4.3.0/downloads/"。

 

问题:bulid报错

/usr/local/opencv-4.3.0/opencv_contrib-4.3.0/modules/xfeatures2d/src/vgg.cpp:490:41: fatal error: vgg_generated_120.i: No such file or directory

/usr/local/opencv-4.3.0/opencv_contrib-4.3.0/modules/xfeatures2d/src/boostdesc.cpp:654:37: fatal error: boostdesc_bgm.i: No such file or directory

解决:下载复制到opencv-4.3.0/opencv_contrib-4.3.0/modules/xfeatures2d/src目录

 

问题:/usr/local/opencv-4.3.0/build/modules/java_bindings_generator/gen/cpp/xfeatures2d.inl.hpp:12:35: fatal error: opencv2/xfeatures2d.hpp: No such file or directory

/usr/local/opencv-4.3.0/opencv_contrib-4.3.0/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp:7:82: fatal error: features2d/test/test_detectors_invariance.impl.hpp: No such file or directory

解决:查找报错的文件 然后将引用 改写为绝对路径:

root@iZbp19nj83ng3s5ypqg1lzZ:/usr/local/opencv-4.3.0/modules# find . -name "*test_detectors*"

vim /usr/local/opencv-4.3.0/opencv_contrib-4.3.0/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp

//#include "features2d/test/test_detectors_invariance.impl.hpp" // main OpenCV repo 改为如下:

#include "/usr/local/opencv-4.3.0/modules/features2d/test/test_detectors_invariance.impl.hpp" // main OpenCV repo

//#include "features2d/test/test_descriptors_invariance.impl.hpp" // main OpenCV repo 改为如下:

#include "/usr/local/opencv-4.3.0/modules/features2d/test/test_descriptors_invariance.impl.hpp" // main OpenCV repo

 

问题:cmake opencv的时候 提示没有探测到java 或者编译过后build/lib/目录下没有libopencv_java410.so文件

Unavailable: androidcamera dynamicuda java python viz

原因:可是我jdk环境已经配置了,java -version可以看到

解决:

1、安装ant sudo apt-get install ant后,重新cmake

2、明明有环境变量,可是还是探测不到java,

Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)

在root账户下去掉sudo后执行编译却可以探测到java了,确实奇怪

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.3.0/modules/ ..

你可能感兴趣的:(opencv,互联网,环境安装,opencv,c++)