ARM Android 交叉编译安装

· 1.下载Tengine源代码

 git clone https://github.com/OAID/Tengine.git

 cd Tengine


· 2.下载opencv/protobuf/openblas/android ndk

百度云盘(密码:wd77)下载下列文件:

· android-ndk-r16-linux-x86_64.zip

· openblas020_android.tgz

· Opencv-3.4.0-android-sdk.zip

· protobuf_lib.tgz

· ComputeLibrary.tgz 解压

 unzip android-ndk-r16-linux-x86_64.zip

 tar -zxvf protobuf_lib.tgz

 tar -zxvf openblas020_android.tgz

 tar -xzvf  ComputeLibrary.tgz

 unzip opencv-3.4.0-android-sdk.zip



·3. 配置

3.1 配置文件~/tengine/android_config.txt:

· 如果编译的android的cpu是armv7的,设置 CONFIG_ARCH_TYPE:ARMv7

· 如果编译的android的cpu是armv8的,设置 CONFIG_ARCH_TYPE:ARMv8

· 修改下列路径为你的真实路径:

ANDROID_NDK:/home/xxx/android/android-ndk-r16b

PROTOBUF_DIR:/home/xxx/android/protobuf_lib

BLAS_DIR:/home/xxx/android/Openblas020-android

ACL_ROOT:/home/xxx/android/ComputeLibrary


3.2 选择armv7/armv8/openblas

· 如果是armv7,在android_build_armv7.sh中打开DCONFIG_ARCH_ARM32=ON

· 如果是armv8,在android_build_armv8.sh中打开DCONFIG_ARCH_ARM64=ON

· 如果要使用Openblas,关闭CONFIG_ARCH_ARM32/64,开启-DCONFIG_ARCH_BLAS=ON,并在android_config.txt中配置BLAS_DIR


4.编译Tengine

mkdir build

 cd build

 ../android_build_armv7.sh 或者 ../android_build_armv8.sh

 make -j4

 make install


5.编译example 在example目录下配置文件android_build_armv7/8.sh,注意修改相应库的路径为实际路径

export ANDROID_NDK=/home/usr/android-ndk-r16b

 cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \

-DANDROID_ABI="armeabi-v7a" \

-DANDROID_PLATFORM=android-21 \

-DANDROID_STL=c++_shared \

-DTENGINE_DIR=/home/usr/tengine \

-DOpenCV_DIR=/home/usr/opencv/sdk/native/jni \

-DPROTOBUF_DIR=/home/usr/protobuf_lib \

..


编译example


cd ~/tengine/examples

 mkdir build

 cd build

 ../android_build_armv7.sh #or ../android_build_armv8.sh

 make -j4


6.通过adb 把文件从本机传到板子上,执行测试

adb root

 adb shell

 cd /data/local/tmp

 chmod u+x Classify

 export LD_LIBRARY_PATH=.

 ./Classify -i cat.jpg


测试输出


0.2763 - "n02123045 tabby, tabby cat"

 0.2673 - "n02123159 tiger cat"

 0.1766 - "n02119789 kit fox, Vulpes macrotis"

 0.0827 - "n02124075 Egyptian cat"

 0.0777 - "n02085620 Chihuahua"


测试成功