ubuntu下opencv4.6.0环境安装编译

目录

一.下载安装包

二.配制安装环境

三.开始安装opencv

四.添加路径

五、配制环境

六、.出现以下异常:

七.测试Opencv:


一.下载安装包

1.下载opencv
opencv-4.6.0.zip+opencv_contrib-4.x.zip

2.新建opencv文件夹将下载好的:opencv-4.6.0.zip解压到opencv文件夹里面;

3.将解压opencv_contrib-4.x.zip的文件放入opencv文件

二.配制安装环境

1.打开终端,进入root权限:

su root

2.输入环境安装包命令:(安装build-essential可以安装所有的依赖)

sudo apt-get install build-essential 

3.安装camke:

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

4.安装python库:

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

三.开始安装opencv

1.在刚才的opencv文件夹下新建build文件夹:再进入build文件夹

cd opencv
mkdir build
cd build

2.输入cmake命令:

sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

3.开始编译:

sudo make -j4

ubuntu下opencv4.6.0环境安装编译_第1张图片

4.开始安装:

sudo make install

ubuntu下opencv4.6.0环境安装编译_第2张图片

四.添加路径

1.打开文件ld.so:

sudo gedit /etc/ld.so.conf

2.在后面加入:(直接加在后面,不用换行)

/usr/loacal/lib

3.保存后关闭文件,输入命令:

sudo ldconfig

五、配制环境

1.打打.bashrc文件:

sudo gedit /etc/bash.bashrc 

2.在文件最后换行后加入代码后保存关闭:

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

3.输入命令:

source /etc/bash.bashrc

4.输入命令:查看opencv安装情况

pkg-config opencv --modversion

六、.出现以下异常:

Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

1.首先创建opencv.pc文件,要注意它的路径信息:

cd /usr/local/lib
sudo mkdir pkgconfig
cd pkgconfig
sudo touch opencv.pc

2.在opencv.pc中添加以下信息,注意这些信息需要与自己安装opencv时的库路径对应:

prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: opencv
Description: The opencv library
Version:4.0.1
Cflags: -I${includedir}/opencv4
Libs: -L${libdir} -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann  -lopencv_core
~                                               

3.保存退出,然后将文件导入到环境变量:

export  PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

七.测试Opencv:

进入opencv/samples/cpp/example_cmake目录下,终端打开,依次输入:

cmake .
make
./opencv_example

ubuntu下opencv4.6.0环境安装编译_第3张图片

你可能感兴趣的:(opencv,计算机视觉,python)