Opencv编译安装教程(Linux)
一、安装环境一、安装环境虚拟机:opencv版本:二、编译和1、源码下载:opencv链接2github下载注意事项和opencv版本要对应2、安装前准备在自己虚拟机的主目录中创建一个,将两个源码包解压的文件夹放入其中:mkdircdmkdirbuildcdbuild安装依赖项安装sudo-yg++sudo-ycmakesudo-ymakesudo-ywgetsudo-yunzip安装opencv
一、安装环境
二、编译opencv和opencv_contrib
1、源码下载:
2、安装前准备
mkdir ~/opencv_build && cd ~/opencv_build/opencv-4.5.2/mkdir buildcd build
安装依赖项
sudo apt install -y g ++sudo apt install -y cmakesudo apt install -y makesudo apt install -y wgetsudo 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、编译安装
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 \..
sudo make -j8
编译完成后,安装
sudo make install
4、环境配置
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测试
cd ~/opencv_build/opencv-4.5.2/samples/cpp/example_cmakecmake .make./opencv_example
6、最后在qt的.pro中加入头文件路径和库就可以在qt中使用了
# 添加 opencv 头文件INCLUDEPATH += /usr/local/include/opencv4INCLUDEPATH += /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、源码下载:
2、编译安装
mkdir -p ~/cvui-2.9.0-beta/buildcmake .makesudo make install
3、查看是否安装成功
ls /usr/local/include
四、参考文章
更多推荐
所有评论(0)