本文转载自:<span id="profileBt"><a href="https://mp.weixin.qq.com/s/rIL8ic_rPgLIN4y42LrMNg"> 硬码农二毛哥微信公众号</a></span>
如何将Vitis AI Library应用加入Vitis进行编译,生成可执行文件?
<strong>Vitis AI Library应用编译</strong>
在不使用vitis的情况下,vitis ai library编译方法如下:
<pre>//以refinedet为例
$cd ~/Vitis-AI/Vitis-AI-Library/overview/samples/refinedet
$bash -x build.sh</pre>
运行上述指令后,生成可执行文件。
<strong>build.sh</strong>
build.sh中的内容
<pre>CXX=${CXX:-g++}
$CXX -std=c++11 -I. -o test_video_facedetect test_video_facedetect.cpp -lopencv_core -lopencv_video -lopencv_videoio -lopencv_imgproc -lopencv_imgcodecs -lopencv_highgui -lvitis_ai_library-refinedet -pthread -lglog</pre>
<strong>在Vitis中新建应用</strong>
使用之前创建好的platform新建应用。platform创建方式参考https://github.com/Xilinx/Vitis-Tutorials/tree/2020.1/Vitis_Platform_Cr…
1、 File -> New -> Application Project
<center><img src="http://xilinx.eetrend.com/files/2021-09/%E5%8D%9A%E5%AE%A2/100553894-22…; alt=""></center>
2、Click next
3、Select xx_custom as platform, click next,xx_custom为之前创建好的platform
<center><img src="http://xilinx.eetrend.com/files/2021-09/%E5%8D%9A%E5%AE%A2/100553894-22…; alt=""></center>
4、Name the project refinedet_dpu, click next
<center><img src="http://xilinx.eetrend.com/files/2021-09/%E5%8D%9A%E5%AE%A2/100553894-22…; alt=""></center>
5、在空白中依次选中如下内容
xx/pfm/sysroots/aarch64-xilinx-linux
xx/pfm/image/rootfs.ext4
xx/pfm/image/image.ub
<center><img src="http://xilinx.eetrend.com/files/2021-09/%E5%8D%9A%E5%AE%A2/100553894-22…; alt=""></center>
6、新建应用
<center><img src="http://xilinx.eetrend.com/files/2021-09/%E5%8D%9A%E5%AE%A2/100553894-22…; alt=""></center>
7、导入文件
导入文件xx_custom_pkg directory>/DPU-TRD/prj/Vitis/binary_container_1/dpu.xo
导入文件xx_custom_pkg directory>/DPU-TRD/prj/Vitis/config_file/prj_config
导入文件~/Vitis-AI/Vitis-AI-Library/overview/samples/refinedet/test_video_refinedet.cpp
导入文件~/Vitis-AI/Vitis-AI-Library/overview/samples/refinedet/process_result.hpp
8、加入Hardware Functions
点击refinedet_dpu工程,在Active build configuraton中选择Hardware
<center><img src="http://xilinx.eetrend.com/files/2021-09/%E5%8D%9A%E5%AE%A2/100553894-22…; alt=""></center>
<center><img src="http://xilinx.eetrend.com/files/2021-09/%E5%8D%9A%E5%AE%A2/100553894-22…; alt=""></center>
9、 加入库文件
将Vitis-AI-Library库 vitis_ai_2020.1-r1.2.0.tar.gz加入指定目录
<pre>sudo tar xzvf vitis_ai_2020.1-r1.2.0.tar.gz -C ../xx_custom_pkg/pfm/sysroots/aarch64-xilinx-linux/</pre>
右击refinedet_dpu,C/C++ Build Settings
<img src="http://xilinx.eetrend.com/files/2021-09/%E5%8D%9A%E5%AE%A2/100553894-22…; alt="">
C/C++ Build->Settings->Tool Settings->GCC Host Linker->Libraries中加入如下库文件
<pre>opencv_core
opencv_imgcodecs
opencv_highgui
opencv_imgproc
opencv_videoio
vitis_ai_library-refinedet
glog</pre>
C/C++ Build->Settings->Tool Settings->GCC Host Compiler->Includes中做如下修改。
<center><img src="http://xilinx.eetrend.com/files/2021-09/%E5%8D%9A%E5%AE%A2/100553894-22…; alt=""></center>
10、重新编译refinedet_dpu工程。
右键点击refinedet_dpu工程,选择Build Project。生成文件refinedet_dpu在如下目录
<pre>xx_custom_pkg/refinedet_dpu/Hardware/package/sd_card</pre>
<strong>验证</strong>
启动单板,拷贝文件
使用ssh,将refinedet_dpu拷贝到单板~/目录。
<pre>scp refinedet_dpu root@IP:~/</pre>
在单板中运行
<pre>mv refinedet_dpu Vitis-AI/vitis_ai_library/samples/refinedet/
export DISPLAY=:0.0
xrandr --output DP-1 --mode 640x480</pre>
运行程序
<pre>./refinedet_dpu refinedet_pruned_0_8 0</pre>