当前位置:首页 » 《关注互联网》 » 正文

Opencv编译安装教程(Linux)

8 人参与  2024年09月21日 17:20  分类 : 《关注互联网》  评论

点击全文阅读


一、安装环境

虚拟机: Ubuntu 22.04 opencv 版本: opencv-4.5.2 、 opencv_contrib-4.5.2 、 cvui-2.9.0-beta

二、编译opencvopencv_contrib

1、源码下载:

opencv : https://github.com/opencv/opencv 链接 2 : https://opencv.org/releases/ github下载 opencv_contrib : https://github.com/opencv/opencv_contrib 注意事项 :opencv_contrib 和 opencv 版本 要对应

2、安装前准备

在自己虚拟机的主目录中创建一个 opencv_build ,将两个源码包解压的文件夹放入 其中: mkdir ~/opencv_build && cd ~/opencv_build/opencv-4.5.2/ mkdir build cd build

安装依赖项 

安装 g++, cmake, make ,wget, unzip sudo apt install -y g ++ sudo apt install -y cmake sudo apt install -y make sudo apt install -y wget sudo apt install -y unzip

安装opencv依赖的基本库

sudo apt-get install build-essential libgtk2.0-dev libgtk-3-devlibavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev

3、编译安装 

cmake 配置 sudo cmake -DCMAKE_BUILD_TYPE = RELEASE \- DCMAKE_INSTALL_PREFIX = /usr/local \- DOPENCV_EXTRA_MODULES_PATH = /home/pjy/opencv_build/opencv_contrib- 4.5.2/modules .. \- DWITH_CUDA = 1 \- DWITH_GTK = ON \- DENABLE_FAST_MATH = 1 \- DCUDA_FAST_MATH = 1 \- DWITH_CUBLAS = 1 \- DOPENCV_GENERATE_PKGCONFIG = ON \- DWITH_GSTREAMER = ON \.. -DOPENCV_EXTRA_MODULES_PATH= /home/pjy/opencv_build/ opencv_contrib-4.5.2/modules 加粗部分换成自己的路径 -DOPENCV_EXTRA_MODULES_PATH= /home/pjy/opencv_build/opencv_contrib- 4.5.2 /modules 指明 opencv_contrib 路径,这样好一起编译 如下图就成功:

 

make 编译 opencv 和 opencv_contrib 版本号一定要对应,不然编译会报错 sudo make -j8

编译完成后,安装

sudo make install  

4、环境配置

配置 pkg-config 环境 sudo gedit /etc/profile.d/pkgconfig.sh

 可能为空文件,在文件中加入

export PKG_CONFIG_PATH = /usr/local/lib/pkgconfig: $PKG_CONFIG_PATH

保存并退出,source激活

source /etc/profile  

验证是否成功

// 查看版本,有输出 4.5.2 就成功 pkg-config --modversion opencv4 // 查看库 pkg-config --libs opencv4

输出类似下面这样即为成功

配置动态库环境 sudo gedit /etc/ld.so.conf.d/opencv4.conf

文件末尾加上

/usr/local/lib 

使配置生效

sudo ldconfig  

5、demo测试  

打开新终端,进入到 example_cmake 目录 cd ~/opencv_build/opencv-4.5.2/samples/cpp/example_cmake cmake . make ./opencv_example

6、最后在qt的.pro中加入头文件路径和库就可以在qt中使用了  

# 添加 opencv 头文件 INCLUDEPATH += /usr/local/include/opencv4 INCLUDEPATH += /usr/local/include/opencv4/opencv2 # 添加 opencv 库文件 LIBS += -L /home/geclab/buildroot-2016.11/output/host/usr/arm-none- linux-gnueabi/sysroot/usr/local/lib -lopencv_gapi - lopencv_stitching -lopencv_aruco -lopencv_bgsegm - lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect - lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_fuzzy - lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform - lopencv_line_descriptor -lopencv_mcc -lopencv_quality - lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency - lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching - lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text - lopencv_plot -lopencv_videostab -lopencv_videoio - lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_shape - lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_dnn - lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d - lopencv_imgcodecs -lopencv_features2d -lopencv_flann - lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core

我一般都是这样写

 #添加opencv 的头文件 ARM-OpenCV 环境
INCLUDEPATH += /opencv4-arm/include
INCLUDEPATH += /opencv4-arm/include/opencv4
INCLUDEPATH += /opencv4-arm/include/opencv4/opencv2
#添加OpenCV库文件
LIBS += -L/opencv4-arm/lib -lopencv_world

#Windows OpenCV 环境
#添加头文件
INCLUDEPATH += E:\OpenCV\include
INCLUDEPATH += E:\OpenCV\include\opencv2
#添加库文件
LIBS += E:\OpenCV\x64\mingw\lib\libopencv_*.a

三、cvui的安装  

1、源码下载:

https://github.com/Dovyski/cvui

2、编译安装

mkdir -p ~/cvui-2.9.0-beta/build cmake . make sudo make install

3、查看是否安装成功 

ls /usr/local/include

四、参考文章

参考博客: https://blog.csdn.net/weixin_73378881/article/details/132167614?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-132167614-blog-125799361.235 https://blog.csdn.net/bjh123hxhdhd/article/details/134608662?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-2-134608662-blog-132167614.235%5Ev43%5Econtrol&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-2-134608662-blog-132167614.235%5Ev43%5Econtrol&utm_relevant_index=5

 


点击全文阅读


本文链接:http://zhangshiyu.com/post/162856.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1