版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31119155/article/details/89680961
-
download
-
需要下载源码
可以直接去官网下载source code
也可以直接 git clone 下载最新版本git clone git clone https://github.com/opencv/opencv.git
git clone git clone https://github.com/opencv/opencv_contrib.git
install
-
安装 所需依赖
$ 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 # 处理图像所需的包 $ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev $ sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包 $ sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能 $ sudo apt-get install ffmpeg
-
源码安装
tar -zxvf opencv.zip tar -zxvf opencv-contrib.zip mv opencv-contib opencv cd opencv mkdir build cd build cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules/ .. # 最后的两点和空格不要忘记哦 ,时间可能需要一会 sudo make sudo make install
-
这样是 cmake 好了的标志
opencv 配置
sudo gedit /etc/ld.so.conf.d/opencv.conf 此时是空的,写进入 /usr/local/lib //将opencv库添加到路径,从而可以让系统找到
sudo ldconfig //使上述配置命令生效
sudo gedit /etc/bash.bashrc //配置bash 在末尾添加如下命令
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
source /etc/bash.bashrc //使bash配置生效
sudo updatedb //更新
测试安装是否成功
cd opencv-3.4.0/smaples/cpp/example_cmake
cmake .
make
./opencv_example # 测试demo,如果电脑上有摄像头会打开摄像头,如果没有则屏幕上会出现hello opencv的界面