This is a guide to run YuNet demo and benchmark from OpenCV Zoo on the Allwinnner D1 (RISC-V-based). Since the Python support is very limited, demo and benchmark for YuNet is rewritten in C++ and attached.
Tested environment:
- OS: Ubuntu 20.04
- SHELL: bash
Visit this link to get the RISC-V toolchain from Allwinner: [CN] [EN]. Follow the official guide to download the toolchain, then you will have the following directories:
$ tree repo # repo is the root directory of TinaLinux-SDK
repo
|-- ...
|-- tina-d1-open
|-- ...
Run the following command to initialize environments before any cross-compilings:
cd $repo/tina-d1-open
source build/envsetup.sh
lunch d1_nezha-tina
Follow this guide (Chinese) step by step and you can compile successfully.
Assume you have install prefix set to $opencv/build/install
, you need to manually copy libatomic from the SDK directory to $opencv/build/install/lib
.
The C++ demo detect.cpp
and benchmark benchmark.cpp
for YuNet from OpenCV Zoo are attached. CMakeLists.txt
for building is also attached. Create a directory $yunet
and save these files.
You can download the model face_detection_yunet_2021sep.onnx
from opencv_zoo/face_detection_yunet, and the test data from opencv_zoo/benchmarks. NOTICE: Since the above guide compiling OpenCV turns off openjpeg when compiling, you need to port jpg images into png.
Ensure you have already initialized the environment for the RISC-V toolchain. Then run the following command to build the demo and benchmark:
cd $yunet
mkdir build && cd build
# replace $repo and $opencv with your actual absolute paths
cmake -D CMAKE_C_COMPILER=$repo/tina-d1-open/prebuilt/gcc/linux-x86/riscv/toolchain-thead-glibc/riscv64-glibc-gcc-thead_20200702/bin/riscv64-unknown-linux-gnu-gcc \
-D CMAKE_CXX_COMPILER=$repo/tina-d1-open/prebuilt/gcc/linux-x86/riscv/toolchain-thead-glibc/riscv64-glibc-gcc-thead_20200702/bin/riscv64-unknown-linux-gnu-g++ \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_PREFIX_PATH=$opencv/build/install ..
make
Push $opencv/build/install
, $yunet
, face_detection_yunet_2021sep.onnx
and test data to D1 using ADB:
# make sure you replace $opencv and $yunet with your actual absolute path
adb push $opencv/build/install/. /root/opencv-install
adb push $yunet/. /root/opencv_zoo/yunet
adb push face_detection_yunet_2021sep.onnx /root/opencv_zoo/yunet
adb push /path/to/test_data /root/opencv_zoo/data
Run demo and benchmark on D1:
export LD_LIBRARY_PATH=/root/opencv-install/lib
cd /root/opencv_zoo/yunet/build
# run demo
./detect -m=/root/opencv_zoo/yunet/face_detection_yunet_2021sep.onnx -i=/root/opencv_zoo/data/image_name.png
# run benchmark
./benchmark -m=/root/opencv_zoo/yunet/face_detection_yunet_2021sep.onnx -i=/root/opencv_zoo/data/image_name.png