一、Ubuntu18.04——安装opencv3.4.16

 Opencv

1、opencv3.4.16

(1)准备材料(两个版本需要相对应):

wtj@i:~/Downloads$ sudo mv opencv-3.4.16 /opt/
wtj@i:~/Downloads$ sudo mv opencv_contrib-3.4.16 /opt/

(2)安装依赖库

sudo apt-get install build-essential
sudo apt-get install python-numpy python3-numpy  python-pandas python3-pandas
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-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

(3)编译安装opencv:cmake 、make 、sudo make install

wtj@i:/opt$ sudo mv opencv_contrib-3.4.16/ opencv-3.4.16/
wtj@i:/opt$ cd opencv-3.4.16/
wtj@i:/opt/opencv-3.4.16$ mkdir release
wtj@i:/opt/opencv-3.4.16$ cd release/

wtj@i:/opt/opencv-3.4.16/release$ cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.4.16/modules  .. 
wtj@i:/opt/opencv-3.4.16/release$ make -j8
wtj@i:/opt/opencv-3.4.16/release$ sudo make install

(4)opencv系统环境设置

wtj@i:~$ sudo gedit /etc/ld.so.conf.d/opencv.conf

wtj@i:~$ sudo ldconfig
wtj@i:~$ echo "export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" >>~/.bashrc
wtj@i:~$ source ~/.bashrc

(5)测试

#include
#include

using namespace std;
using namespace cv;
int main(){
    VideoCapture cap(0);//打开摄像头
    Mat edges;

    if(!cap.isOpened())
        return false;

    while(1){
        Mat frame;
        cap>>frame;
        cvtColor(frame,edges,COLOR_BGR2GRAY);
        Canny(edges,edges,0,30,3);
        if(frame.empty())
            break;
        imshow("video",edges);
        if(waitKey(20)>0)
          break;
    }
    cap.release();
    destroyAllWindows();
}
wtj@i:~$ g++ opencv_test.cpp  -o opencv_test `pkg-config opencv --cflags --libs`
wtj@i:~$./opencv_test 

一、Ubuntu18.04——安装opencv3.4.16_第1张图片

你可能感兴趣的:(ubuntu系统安装环境配置,opencv,计算机视觉)