环境配置4-Ubuntu下安装openCV

1-安装依赖项(需联网)

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 --assume-yes libopencv-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip

sudo apt-get install ffmpeg libopencv-dev libgtk-3-dev python-numpy python3-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libv4l-dev libtbb-dev qtbase5-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev

 

可能会报错Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)

执行sodo rm /var/lib/dpkg/lock再重新安装依赖项

2-下载openCV,解压缩

    unzip opencv-3.4.0.zip

3-进入到解压后的文件包中,创建文件夹并进入

    cd opencv-3.4.0

    mkdir build

    cd build

4-进行cmake操作,期间会下载内容,需等待

sudo cmake \
    -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=OFF \
    -D WITH_CUDA=ON \
    -D WITH_CUBLAS=ON \
    -D DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" \
    -D CUDA_ARCH_BIN="6.1" \
    -D CUDA_ARCH_PTX="" \
    -D WITH_TBB=ON \
    -D WITH_V4L=ON \
    -D WITH_GTK=ON \
    -D WITH_OPENGL=ON \
    -D BUILD_EXAMPLES=ON \
    ..

cmake中有默认开启的选项,可以查看一下,那上面一些开关可以省略

5-执行编译,并在多核cpu上进行加速

    sudo make -j6

6-执行 sudo make install

7-环境配置

    sudo gedit ~/.bashrc

    在文件末尾添加如下

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

    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

    保存后退出

    source ~/.bashrc        

8-测试

    cd到opencv-3.4.0/samples/cpp/example_cmake目录下,依次执行如下,如果看到摄像头打开并有hello opencv表示成功

    cmake .

    make

    ./opencv_example



9-卸载

到openCV的build目录下

cd /opencv-3.4.0/build
sudo make uninstall
现在可以将整个opencv-3.4.0的目录删除,再执行
sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv

将系统里的openCV删除干净

 

你可能感兴趣的:(环境配置)