系统相关
首页 > 系统相关> > ubuntu+opencv安装

ubuntu+opencv安装

作者:互联网

一、前期准备

1、VMware:12.5.0 build-4352439

2、Ubuntu:ubuntu-16.04.7-desktop-amd64.iso

3、虚拟机配置:2GB内存、2个1核处理器、硬盘20GB、网络连接方式NAT

4、opencv:4.1.0

5、python:python3-3.5.2、python2-

二、安装opencv

1、安装环境

1.1安装cmake

sudo apt-get install cmake

1.2、其他安装环境:

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

2、下载opencv安装包

①进入/home/yy  文件夹,mkdir opencv4.1.0文件夹

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

3、安装

3.1 进入/opencv4.1.0/opencv文件夹中。创建build文件夹

mkdir build 
cd build

3.2 cmake

cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D PYTHON3_EXECUTABLE=/usr/bin/python3 \ -D PYTHON_INCLUDE_DIR=/usr/include/python3.5 \ -D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so \ -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.5/dist-packages/numpy/core/include \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D INSTALL_C_EXAMPLES=OFF \ -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \ -D PYTHON_EXECUTABLE=/usr/lib/python3 \ -D BUILD_opencv_xfeatures2d=OFF \ -D BUILD_EXAMPLES=ON ..

3.3 编译

sudo make -j1//-多少看你内核数

编译过程:

3.4 安装

安装完成界面:

4、配置环境

4.1添加库路径

用gedit打开id.so.conf文件。在文件下一行加入 /usr/local/lib

sudo gedit /etc/ld.so.conf

5、opencv.pc文件添加

5.1 打开/usr/local/lib目录,若没有pkgconfig文件夹自己新建一个

cd /usr/local/lib //打开lib目录
sudo mkdir pkgconfig   //一定要用sudo,不然新建不了

5.2 添加opencv.pc文件

在/home/yy 中新建一个opencv.pc文件

内容:

prefix=/home/hzh/opencv/mybuild/myInstall
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv4/opencv
includedir_new=${prefix}/include/opencv4

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.1.0
Libs: -L${exec_prefix}/lib -lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_quality -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_video -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir_old} -I${includedir_new}

在/home/yy/中将opencv.pc复制至/usr/local/lib/pkgconfig/

sudo cp ./opencv.pc /usr/local/lib/pkgconfig/

6、检查安装的opencv

pkg-config opencv --modversion

标签:lopencv,lib,sudo,dev,opencv,usr,ubuntu,安装
来源: https://blog.csdn.net/weixin_40130025/article/details/112344859