opencv 编译linux和arm-linux

文章末尾有编译脚本

源码下载

Releases - OpenCV

Releases · opencv/opencv · GitHub

环境搭建

系统:ubuntu 16.04

cmake:3.10.2

ndk:r15c

sudo apt-get install cmake
sudo apt-get install gcc
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf

缺依赖自行安装

LINUX

动态库

cmake ../  -DCMAKE_BUILD_TYPE=RELEASE  -DCMAKE_INSTALL_PREFIX=../install/share/Linux   -DBUILD_ZLIB=ON  -DWITH_IPP=OFF

make -j8 && make install

静态库

cmake ../ -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=../install/static/Linux -DBUILD_SHARED_LIBS=FALSE -DBUILD_ZLIB=ON -DWITH_IPP=OFF

make -j8 && make install

ARM-LINUX

动态库

cmake ../ -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ -DCMAKE_INSTALL_PREFIX=../install/share/Arm-linux -DBUILD_ZLIB=ON -DBUILD_JPEG=ON -DBUILD_PNG=ON -DBUILD_JASPER=ON -DWITH_TIFF=OFF -DWITH_GTK=OFF -DWITH_CUDA=OFF -DWITH_1394=OFF -DWITH_GSTREAMER=OFF -DWITH_OPENEXR=OFF -DWITH_OPENCL=OF

make -j8 && make install

静态库

cmake ../ -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ -DCMAKE_INSTALL_PREFIX=../install/static/Arm-linux -DBUILD_SHARED_LIBS=FALSE -DBUILD_ZLIB=ON -DBUILD_JPEG=ON -DBUILD_PNG=ON -DBUILD_JASPER=ON -DWITH_TIFF=OFF -DWITH_GTK=OFF -DWITH_CUDA=OFF -DWITH_1394=OFF -DWITH_GSTREAMER=OFF -DWITH_OPENEXR=OFF -DWITH_OPENCL=OFF -DWITH_IPP=OFF

make -j8 && make install

辅助:可通过readelf -h libopencv_core.a 查看Machine属性,判断库运行平台

shell脚本

pushd build

THIS_PATH=$(cd `dirname $0`; pwd)

echo "build path : ${THIS_PATH}"

#linux 
rm -irf *
cmake ../  -DCMAKE_BUILD_TYPE=RELEASE  -DCMAKE_INSTALL_PREFIX=../install/share/Linux   -DBUILD_ZLIB=ON  -DWITH_IPP=OFF

make -j8 && make install

rm -irf *
cmake ../  -DCMAKE_BUILD_TYPE=RELEASE  -DCMAKE_INSTALL_PREFIX=../install/static/Linux  -DBUILD_SHARED_LIBS=FALSE  -DBUILD_ZLIB=ON   -DWITH_IPP=OFF

make -j8 && make install

#arm-linx
rm -irf *
cmake ../  -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc  -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++  -DCMAKE_INSTALL_PREFIX=../install/share/Arm-linux  -DBUILD_ZLIB=ON   -DBUILD_JPEG=ON  -DBUILD_PNG=ON  -DBUILD_JASPER=ON  -DWITH_TIFF=OFF -DWITH_GTK=OFF -DWITH_CUDA=OFF -DWITH_1394=OFF -DWITH_GSTREAMER=OFF -DWITH_OPENEXR=OFF -DWITH_OPENCL=OFF -DWITH_IPP=OFF

make -j8 && make install


rm -irf *
cmake ../  -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc  -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++  -DCMAKE_INSTALL_PREFIX=../install/static/Arm-linux -DBUILD_SHARED_LIBS=FALSE  -DBUILD_ZLIB=ON   -DBUILD_JPEG=ON  -DBUILD_PNG=ON  -DBUILD_JASPER=ON  -DWITH_TIFF=OFF -DWITH_GTK=OFF -DWITH_CUDA=OFF -DWITH_1394=OFF -DWITH_GSTREAMER=OFF -DWITH_OPENEXR=OFF -DWITH_OPENCL=OFF -DWITH_IPP=OFF

make -j8 && make install

pop

arm 编译错误处理方式

3rdparty/libpng/pngpriv.h

/*# if (defined(ARM_NEON) || defined(__ARM_NEON)) && */
 
# if defined(PNG_ARM_NEON) && (defined(ARM_NEON) || defined(__ARM_NEON)) && \

如果cmake下载ipp失败可在cmake参数中怎加如下指令

 -DWITH_IPP=OFF

你可能感兴趣的:(opencv,opencv,linux,arm)