本文主要是介绍hi 平台 opencv4.8 交叉编译,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
echo "参数是 'arm_hi'"
current_path=$(pwd)
nproc=32
# arm-linux-gnueabihf-gcc, Cross-Toolchain PATH
export PATH="/opt/aarch64-v01c01-linux-musl-gcc/bin:$PATH"
# ------------------------------------------------------------------
# 参考文章 https://www.cnblogs.com/qq21497936/p/16051614.html
# https://blog.csdn.net/dashuo0501/article/details/133985172
# 设置工具链路径
TOOLCHAIN_PATH=/opt/aarch64-v01c01-linux-musl-gcc
GCC_COMPILER=${TOOLCHAIN_PATH}/bin/aarch64-linux-musleabi
# 设置x264安装路径
X264_INSTALL_DIR=${current_path}
# 不同版本的FFmpeg和x264有对应关系
# 不同版本的OpenCV3和ffmpeg有版本依赖
# OpenCV3.4.1+ffmpeg3.4.8交叉编译
# https://ffmpeg.org//releases/
# https://download.videolan.org/pub/videolan/x264/snapshots/
# https://blog.csdn.net/csdn_lovebqj/article/details/134829327
# make x264
cd "$current_path"/deps && tar -xvf x264-snapshot-20180101-2245.tar.bz2
cd "$current_path"/deps/x264-snapshot-20180101-2245
echo "$(pwd)"
# 配置交叉编译选项,直接指定 C 和 C++ 编译器
./configure --prefix=${X264_INSTALL_DIR} \
--cross-prefix=${GCC_COMPILER}- \
--host=aarch64-linux-gnu \
--enable-debug \
--enable-static \
--enable-pic \
--extra-cflags="-g -I${TOOLCHAIN_PATH}/include" \
--extra-ldflags="-L${TOOLCHAIN_PATH}/lib"
# # 编译并安装x264
sudo make
sudo make install
# make ffmpeg
cd "$current_path"/deps
echo "$(pwd)"
# 下载FFmpeg源码
# FFMPEG_VERSION=3.4.1
# wget https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2
sudo rm -rf ffmpeg-5.0.1 && tar -xjf ffmpeg-5.0.1.tar.bz2 && cd ffmpeg-5.0.1
# 设置FFmpeg安装路径
FFMPEG_INSTALL_DIR=${current_path}
# 配置交叉编译选项,直接指定 C 和 C++ 编译器
#
#--enable-shared \
#--disable-static \
./configure --prefix=${FFMPEG_INSTALL_DIR} \
--cc=${GCC_COMPILER}-gcc \
--cxx=${GCC_COMPILER}-g++ \
--target-os=linux \
--arch=aarch64 \
--enable-static \
--enable-cross-compile \
--disable-debug \
--disable-doc \
--enable-gpl \
--enable-libx264 \
--enable-pic \
--extra-cflags="-I${X264_INSTALL_DIR}/include -I${TOOLCHAIN_PATH}/include" \
--extra-ldflags="-L${X264_INSTALL_DIR}/lib -L${TOOLCHAIN_PATH}/lib" \
--strip=${GCC_COMPILER}-strip
# 编译并安装 FFmpeg
sudo make -j$(nproc)
sudo make install
echo "FFmpeg has been installed in ${FFMPEG_INSTALL_DIR}"
# make opencv
# arm-linux-gnueabihf-gcc, Cross-Toolchain PATH
sudo cp -r ${FFMPEG_INSTALL_DIR}/include/* ${TOOLCHAIN_PATH}/include
sudo cp -r ${FFMPEG_INSTALL_DIR}/lib/* ${TOOLCHAIN_PATH}/lib
export PKG_CONFIG_PATH=${TOOLCHAIN_PATH}/lib/pkgconfig:${PKG_CONFIG_PATH}
echo "PKG_CONFIG_PATH ${PKG_CONFIG_PATH}"
cd "$current_path"/deps/opencv-4.8.0
echo "$(pwd)"
sudo rm -rf build && mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake \
-D CMAKE_INSTALL_PREFIX=./ \
-D CMAKE_C_COMPILER=${GCC_COMPILER}-gcc \
-D CMAKE_CXX_COMPILER=${GCC_COMPILER}-g++ \
-D BUILD_SHARED_LIBS=OFF \
-D BUILD_opencv_world=ON \
-D CMAKE_CXX_FLAGS=-fPIC \
-D CMAKE_C_FLAGS=-fPIC \
-D CMAKE_EXE_LINKER_FLAGS=-lpthread \
-D ENABLE_PIC=ON \
-D WITH_1394=OFF \
-D WITH_ARAVIS=OFF \
-D WITH_ARITH_DEC=OFF \
-D WITH_ARITH_ENC=OFF \
-D WITH_CLP=OFF \
-D WITH_CUBLAS=OFF \
-D WITH_CUDA=OFF \
-D WITH_CUFFT=OFF \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=OFF \
-D WITH_GSTREAMER_0_10=OFF \
-D WITH_HALIDE=OFF \
-D WITH_HPX=OFF \
-D WITH_IMGCODEC_HDR=OFF \
-D WITH_IMGCODEC_PXM=OFF \
-D WITH_IMGCODEC_SUNRASTER=OFF \
-D WITH_INF_ENGINE=OFF \
-D WITH_IPP=OFF \
-D WITH_ITT=OFF \
-D WITH_JASPER=ON \
-D WITH_JPEG=ON \
-D WITH_LAPACK=ON \
-D WITH_LIBREALSENSE=OFF \
-D WITH_NVCUVID=OFF \
-D WITH_OPENCL=OFF \
-D WITH_OPENCLAMDBLAS=OFF \
-D WITH_OPENCLAMDFFT=OFF \
-D WITH_OPENCL_SVM=OFF \
-D WITH_OPENEXR=OFF \
-D WITH_OPENGL=OFF \
-D WITH_OPENMP=OFF \
-D WITH_OPENNNI=OFF \
-D WITH_OPENNNI2=OFF \
-D WITH_OPENVX=OFF \
-D WITH_PROTOBUF=OFF \
-D WITH_PTHREADS_PF=ON \
-D WITH_PVAPI=OFF \
-D WITH_QT=OFF \
-D WITH_QUIRC=OFF \
-D WITH_TBB=OFF \
-D WITH_VULKAN=OFF \
-D WITH_WEBP=ON \
-D WITH_XIMEA=OFF \
-D BUILD_ZLIB=ON \
-D OPENCV_ENABLE_PKG_CONFIG=ON \
-D WITH_PNG=ON \
-D WITH_TIFF=ON \
-D BUILD_opencv_highgui=OFF \
..
make -j8
make install
make -j$(nproc)
make install
cd "$current_path"
echo "返回后的目录: $(pwd)"
mkdir -p ./lib/opencv_hi/lib
mkdir ./include
cp -r ./deps/opencv-4.8.0/build/include/* ./include/
cp -r ./deps/opencv-4.8.0/build/lib/*.a ./lib/opencv_hi/lib
cp -r ./deps/opencv-4.8.0/build/3rdparty/lib/*.a ./lib/opencv_hi/lib
cp -r ./deps/opencv-4.8.0/build/share ./lib/opencv_hi
这篇关于hi 平台 opencv4.8 交叉编译的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!