1.在安装了opencv4的基础上安装opencv3
opencv版本在这[Releases · opencv/opencv · GitHub],contrib版本在这[GitHub - opencv/opencv_contrib at 3.4.3]
环境依赖项
Ubuntu16.04安装配置opencv3.4.3+opencv_contrib3.4.3_林深时见鹿echo的博客-CSDN博客_ubuntu 安装opencv3
-D WITH_IPP=OFF, OPENCV_NON_FREE=ON
*编译中遇到的问题IPPICV下载失败
参考:源码编译opencv卡在IPPICV: Download: ippicv_2017u3_lnx_intel64_general_20170822.tgz解决办法_eternal_truth的博客-CSDN博客_ippicv
在Github上下载对应需要下载的文件,随便放在哪里,比如直接/home/xxx/opencv下
Github下载:
opencv_3rdparty/ippicv_2017u3_lnx_intel64_general_20180518.tgz at ippicv/master_20180518 · opencv/opencv_3rdparty · GitHub先自己手动(百度)下载ippicv 包,不过要在cmake 的最开头加上-D WITH_IPP=OFF (因为已经下载过了,相应的下载关掉即可) ,这样再cmake下就好了
*opencv3所缺少的boostdesc_bgm.i等文件
采用的是源码编译的方式,所以可以查看 build 文件夹下的日志文件 CMakeDownloadLog.txt,在日志文件CMakeDownloadLog.txt中搜索 boostdesc_bgm.i 关键词 (不是在文件夹中搜索),
发现这个文件下载失败了。日志文件里就有它的下载地址,直接复制其下载地址到网页可以看该到文件的源码,直接拷贝源码并生存同名文件,放在 opencv_contrib/modules/xfeatures2d/src/ 路径下即可。
*/stitching/include/opencv2/stitching/detail/matchers.hpp
fatal error: opencv2/xfeatures2d/cuda.hpp: 没有那个文件或目录
/home/tsingroo/Documents/3rdparty/opencv-3.4.3/modules/stitching/include/opencv2/stitching/detail/matchers.hpp打开,找到# include "opencv2/xfeatures2d/cuda.hpp"语句
改为绝对路径#include "/home/tsingroo/Documents/3rdparty/opencv-3.4.3/opencv_contrib-3.4.3/modules/xfeatures2d/include/opencv2/xfeatures2d/cuda.hpp"
第三步:编译安装
make -j11
make install
第四步:配置环境
sudo vi /etc/ld.so.conf.d/opencv.conf
输入:/home/tsingroo/Documents/package/opencv-3.4.3/lib
第五步:配置bashrc
vi ~/.bashrc,在最后添加:
#opencv-3.4.3
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/home/tsingroo/Documents/package/opencv-3.4.3/lib/pkgconfig
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/tsingroo/Documents/package/opencv-3.4.3/lib
保存后输入source ~/.bashrc
pkg-config --modversion opencv //显示版本
2.项目中区分使用
ubuntu 安装Opencv4版本后安装Opencv3,并在项目中区分使用__yuan_的博客-CSDN博客_opencv4兼容opencv3嘛
【解决方案】在已有OpenCV4的情况下安装OpenCV3_幻世至上的博客-CSDN博客
默认opencv4情况下,使用opencv3.4.3,编辑CMakeLists.txt
#set(OpenCV_DIR "/home/tsingroo/Documents/package/opencv-3.4.3/share/OpenCV"
set(${OpenCV_INCLUDE_DIRS}
"/home/tsingroo/Documents/package/opencv-3.4.3/include/opencv2" "/home/tsingroo/Documents/package/opencv-3.4.3/include/opencv" "/home/tsingroo/Documents/package/opencv-3.4.3/include") # set include path
set(${OpenCV_LIBS} "/home/tsingroo/Documents/package/opencv-3.4.3/lib") # set lib path
find_package(OpenCV 3.4.3 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
如果只依赖了opencv,或:
set(CMAKE_PREFIX_PATH "/home/tsingroo/Documents/package/opencv-3.4.3") # opencv3 install path
FIND_PACKAGE(OpenCV 3.4.3 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
或:
set(OpenCV_DIR "/home/tsingroo/Documents/package/opencv-3.4.3")
set(${OpenCV_LIBS} "/home/tsingroo/Documents/package/opencv-3.4.3/lib") # set lib path
find_package(OpenCV 3.4.3 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
默认opencv3情况下,使用opencv4.5.0,编辑CMakeLists.txt
set(${OpenCV_INCLUDE_DIRS}
"/home/tsingroo/Documents/package/opencv-3.4.3/include/opencv2") # set include path
set(${OpenCV_LIBS} "/home/tsingroo/Documents/package/opencv-3.4.3/lib") # set lib path
find_package(OpenCV 3.4.3 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
如果只依赖了opencv,或:
set(CMAKE_PREFIX_PATH "/home/tsingroo/Documents/package/opencv-3.4.3") # opencv3 install path
FIND_PACKAGE(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
3.安装opencv4
安装OpenCV4.5+OpenCV-contrib
ubuntu 20.04安装 opencv-4.5和opencv-contrib-4.5_路漫漫 修远兮的博客-CSDN博客
cmake ..替换为(路径修改)
sudo cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_PYTHON3_INSTALL_PATH=/usr/local/lib/python3.5/dist-packages \
-D OPENCV_EXTRA_MODULES_PATH=/home/tsingroo/Downloads/opencv-4.5.4/opencv_contrib/modules/ \
-DOPENCV_ENABLE_NONFREE=True ..
cmake-gui
ubuntu16.04+opencv4.1+opencv_contrib编译及安装(SIFT、SURF)_他们叫我一代大侠的博客-CSDN博客
Ubuntu下卸载opencv
Ubuntu下卸载opencv_花花少年的博客-CSDN博客_ubuntu卸载opencv
1. 自动卸载
# 如果删掉了build,再安装上面编译生成一个
cd /opt/opencv-3.4.3/build
sudo make uninstall
cd ..
sudo rm -r build
2. 手动删除相关文件
可能有些路径存在,可能不存在。
sudo rm -r \
/usr/include/opencv4 \
/usr/lib/cmake/opencv4 \
/usr/lib/python3.9/site-packages/cv2 \
/usr/share/licenses/opencv4 \
/usr/share/opencv4 \
/usr/share/java/opencv4 \
/usr/local/include/opencv4 \
/usr/local/share/opencv4 \
/usr/local/bin/opencv* \
/usr/local/lib/libopencv* \
/usr/local/lib/pkgconfig/opencv4.pc \
/usr/local/lib/cmake/opencv4
3. 卸载并清理配置
# 会删除python的opencv环境
sudo apt \
autoremove \
opencv-doc \
opencv-data \
libopencv-dev \
libopencv2.4-java \
libopencv2.4-jni \
python-opencv \
libopencv-core2.4 \
libopencv-gpu2.4 \
libopencv-ts2.4 \
libopencv-photo2.4 \
libopencv-contrib2.4 \
libopencv-imgproc2.4 \
libopencv-superres2.4 \
libopencv-stitching2.4 \
libopencv-ocl2.4 \
libopencv-legacy2.4 \
libopencv-ml2.4 \
libopencv-video2.4 \
libopencv-videostab2.4 \
libopencv-objdetect2.4 \
libopencv-calib3d2.4
4. 检查是否卸载完成
pkg-config opencv --libs
pkg-config opencv --modversion
pkg-config --cflags --libs opencv
sudo find / -iname "*opencv*"