opencv


原文链接: opencv

(嵌入式深度学习之NCNN交叉编译Arm Linux](https://blog.csdn.net/sanallen/article/details/79022669)

https://blog.csdn.net/qq_33485434/article/details/80820393

用命令查看opencv版本:

pkg-config --modversion opencv
3.4.8

安装opencv2

sudo apt-get install libopencv-dev


ubuntu 18.04 安装 opencv2

aria2c https://github.com/opencv/opencv/archive/2.4.13.7.zip

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 libopenexr-dev libdc1394-22-dev

  1. cmake编译OpenCV源码,安装所有的lib文件都会被安装到/usr/local目录下

mkdir build && cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX="/usr/local/opencv2/" ..

  1. 安装

make -j8
sudo make install

环境变量

安装成功后还需要设置opencv的环境变量

  1. 配置 pkg-config
    export PKG_CONFIG_PATH=/usr/local/opencv2/lib/pkgconfig:$PKG_CONFIG_PATH
    查看配置是否生效
    pkg-config --libs opencv

打开文件

sudo gedit /etc/profile ##个人比较喜欢把环境变量放在/etc/profile里面,'~/.bashrc'一样
在文件最后添加

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
执行下列命令, 使环境变量立即生效

source /etc/profile

  1. 配置 ld

echo '/usr/local/opencv2/lib'> /etc/ld.so.conf.d/opencv.conf
sudo ldconfig

示例代码

对opencv的sample进行编译并运行

cd opencv_dir/samples/c
./build_all.sh
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg

OpenCV-3编译安装方法及常见错误解决(Ubuntu平台) - AskuaSen - CSDN博客

opencv3

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 libtiff5-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 -y libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

cmake -D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX="/usr/local/opencv3/" ..

########### opencv3-gstreamer1.0-Dockerfile

FROM ubuntu:14.04
MAINTAINER Junjue Wang <junjuew@cs.cmu.edu>

# Install gstreamer and opencv dependencies
RUN \ 
    apt-get update && apt-get upgrade -y && \
    apt-get install -y libgstreamer1.0-0 \
            gstreamer1.0-plugins-base \
            gstreamer1.0-plugins-good \
            gstreamer1.0-plugins-bad \
            gstreamer1.0-plugins-ugly \
            gstreamer1.0-libav \
            gstreamer1.0-doc \
            gstreamer1.0-tools \
            libgstreamer1.0-dev \
            libgstreamer-plugins-base1.0-dev && \

    apt-get install -y \
        wget \
        unzip \
        libtbb2 \
        libtbb-dev && \
    apt-get install -y \
        build-essential \
        cmake \
        git \
        pkg-config \
        libjpeg8-dev \
        libtiff4-dev \
        libjasper-dev \
        libpng12-dev \
        libgtk2.0-dev \
        libavcodec-dev \
        libavformat-dev \
        libswscale-dev \
        libv4l-dev \
        libatlas-base-dev \
        gfortran \
        libhdf5-dev \
        python2.7 \
        python2.7-dev && \

    wget https://bootstrap.pypa.io/get-pip.py && \
    python get-pip.py && \
    pip install numpy && \

    apt-get autoclean && apt-get clean && \

    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*


# Download OpenCV 3.2.0 and install
RUN \
    cd ~ && \
    wget https://github.com/Itseez/opencv/archive/3.2.0.zip && \
    unzip 3.2.0.zip && \
    mv ~/opencv-3.2.0/ ~/opencv/ && \
    rm -rf ~/3.2.0.zip && \

    cd /root/opencv && \
    mkdir build && \
    cd build && \
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
        -D CMAKE_INSTALL_PREFIX=/usr/local \
        -D INSTALL_C_EXAMPLES=OFF \
        -D INSTALL_PYTHON_EXAMPLES=ON \
        -D BUILD_EXAMPLES=ON .. && \

    cd ~/opencv/build && \
    make -j $(nproc) && \
    make install && \
    ldconfig
`