一、简介
本文重点描述在树莓派中编译OpenCV3.4.1和OpenCvSharp,大家都知道OpenCVSharp是使用C#调用OpenCV最简洁的一个库。但是在Linux上或者树莓派上运行时,需要编译对应的Linux和CPU架构的版本。
二、编译过程
#树莓派3b安装OPENCV3.4.1 apt-get install -y build-essential cmake \ libgtkglext1-dev libvtk6-dev \ zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libopenexr-dev libgdal-dev && \ add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" && apt update && apt install libjasper1 libjasper-dev && \ apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev \ libtbb-dev libeigen3-dev \ python-dev python-tk python-numpy python3-dev python3-tk python3-numpy OPENCV_VERSION=3.4.1 wget ${OPENCV_VERSION}.zip && unzip ${OPENCV_VERSION}.zip && rm ${OPENCV_VERSION}.zip && mv opencv-${OPENCV_VERSION} OpenCV wget https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && unzip ${OPENCV_VERSION}.zip && rm ${OPENCV_VERSION}.zip && mv opencv_contrib-${OPENCV_VERSION} OpenCV_contrib #下列命令执行时,注意检测OPENCV_EXTRA_MODULES_PATH设置的路径为刚刚解压的OpenCV_contrib路径。 apt-get install libhdf5-dev apt-get install libtiff5-dev apt-get install libtiffxx0c2 cd OpenCV && mkdir build && cd build && \ cmake \ -D OPENCV_EXTRA_MODULES_PATH=/usr/local/opencv/OpenCV_contrib/modules \ -D CMAKE_BUILD_TYPE=RELEASE \ -D BUILD_EXAMPLES=OFF \ -D BUILD_DOCS=OFF \ -D BUILD_PERF_TESTS=OFF \ -D BUILD_TESTS=OFF \ -D BUILD_opencv_java=OFF \ -D BUILD_opencv_python=OFF \ .. && make -j4 && make install && ldconfig # Download OpenCvSharp OPENCVSHARP_VERSION=3.4.1.20180605 git clone https://github.com/shimat/opencvsharp.git cd opencvsharp && git fetch --all --tags --prune && git checkout ${OPENCVSHARP_VERSION} mkdir /opencvsharp/make cd /usr/local/opencv/OpenCvSharp/opencvsharp/make && cmake -D CMAKE_INSTALL_PREFIX=/usr/local/opencv/OpenCvSharp/opencvsharp/make /usr/local/opencv/OpenCvSharp/opencvsharp/src && make -j 4 && make install
三、效果