diff --git a/AIOT/10274_Intelligent AD Analysis System/README.md b/AIOT/10274_Intelligent AD Analysis System/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..43d7c4a0582af9ec90b09650f258282d4b7211ba
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/README.md
@@ -0,0 +1,20 @@
+## 作品简介
+
+本作品使用Taurus套件,基于YoloV2目标检测算法和改进的SORT目标跟踪算法,实现了以下功能:
+
+- 将Taurus套件部署在电子广告屏、海报等商业广告正上方的位置,它可以实时统计并且分析画面中人群的注意力分布,具体而言,它可以检测、跟踪画面中的行人,并把他们分为两类:正在看广告的人与没有在看广告的人;检测+跟踪可以粗略地统计人流量;对于一个被跟踪的人,我们可以统计他出现在画面中的这段时间里看了多长时间的广告,这段时间称为注意力时长;我们定义了一个**广告吸引度**的评价指标,可以用来评估广告的宣传效果,它是一个人均的概念,与从广告前路过的人流量无关
+- PC端的UI界面可以与Taurus通过有线/无线网络进行交互,PC可以控制Taurus启动、停止分析算法,可以选择某张广告进行投放并设置投放时长;启动算法后,Taurus将人群注意力分析模型AD Analysis的实时数据,包括当前帧注意人数、非注意人数、广告吸引度、总的人群注意力时长通过网络传输到PC端,在PC端上利用这些回传数据的实时更新变化曲线,从而实现了实时可视化;PC端UI程序可以保存历史记录,以便于对每次投放的广告进行后续的数据分析处理
+
+我们认为本作品的主要用途有两点:
+
+- 针对同一厂家的不同产品,商家可以根据它们的广告吸引度来分配投放时长,提高广告投资宣传的性价比
+- 针对同一厂家同一产品的不同广告设计,可以评估不同广告设计的宣传效果,选出最优的广告设计方案,为商家制作更具宣传力的广告提供借鉴
+
+## 代码介绍
+
+`code`目录下
+
+- `Iot2023UI_WithCon`:PC端UI界面的C++ QT源代码
+- `mpp_help`:修改了一些默认参数值
+- `nnie`:实现了YoloV2目标检测算法,SORT目标跟踪算法,Taurus与PC进行通信、交互等功能
+- `sort.py`:改进的SORT算法的python实现
\ No newline at end of file
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/.qmake.stash b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/.qmake.stash
new file mode 100644
index 0000000000000000000000000000000000000000..3293aeb3356207c22fdb75729d285d5d0466ffce
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/.qmake.stash
@@ -0,0 +1,21 @@
+QMAKE_CXX.QT_COMPILER_STDCXX = 199711L
+QMAKE_CXX.QMAKE_MSC_VER = 1935
+QMAKE_CXX.QMAKE_MSC_FULL_VER = 193532217
+QMAKE_CXX.COMPILER_MACROS = \
+ QT_COMPILER_STDCXX \
+ QMAKE_MSC_VER \
+ QMAKE_MSC_FULL_VER
+QMAKE_CXX.INCDIRS = \
+ "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.35.32215\\include" \
+ "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.35.32215\\ATLMFC\\include" \
+ "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\VS\\include" \
+ "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22621.0\\ucrt" \
+ "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\um" \
+ "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\shared" \
+ "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\winrt" \
+ "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\cppwinrt"
+QMAKE_CXX.LIBDIRS = \
+ "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.35.32215\\ATLMFC\\lib\\x64" \
+ "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.35.32215\\lib\\x64" \
+ "C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.22621.0\\ucrt\\x64" \
+ "C:\\Program Files (x86)\\Windows Kits\\10\\\\lib\\10.0.22621.0\\\\um\\x64"
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/1.JPG b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/1.JPG
new file mode 100644
index 0000000000000000000000000000000000000000..b3e26eb65e8c676d33505c5e5aadbb4bddc8ea6f
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/1.JPG differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/2.JPG b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/2.JPG
new file mode 100644
index 0000000000000000000000000000000000000000..06c8f5bf66a59db25fd9a552050e3419d5e5208f
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/2.JPG differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/3.JPG b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/3.JPG
new file mode 100644
index 0000000000000000000000000000000000000000..5ed38bef3327da9ce74083bdc55fc6a63158f5d0
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/3.JPG differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/4.JPG b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/4.JPG
new file mode 100644
index 0000000000000000000000000000000000000000..df89c7379fb3042d6d1b6695d7b96f7f49700d7b
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/4.JPG differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/5.JPG b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/5.JPG
new file mode 100644
index 0000000000000000000000000000000000000000..79fd930e4d2da97b878d74c9a79ee9a70c0e42cf
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Advertisement/5.JPG differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Image.qrc b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Image.qrc
new file mode 100644
index 0000000000000000000000000000000000000000..078fce69fcf92b7ab3ffaf60ec3e4ab5e7e9c701
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Image.qrc
@@ -0,0 +1,25 @@
+
+
+ Img/exit.png
+ Img/ad_checked.png
+ Img/ad.png
+ Img/keshihua_checked.png
+ Img/keshihua.png
+ Img/lishijilu_checked.png
+ Img/lishijilu.png
+ Img/xiangyou_diable.png
+ Img/xiangyou.png
+ Img/xiangzuo_diable.png
+ Img/xiangzuo.png
+ Img/shezhi_checked.png
+ Img/shezhi.png
+ Img/avatar.jpg
+
+
+ Advertisement/1.JPG
+ Advertisement/2.JPG
+ Advertisement/3.JPG
+ Advertisement/4.JPG
+ Advertisement/5.JPG
+
+
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/ad.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/ad.png
new file mode 100644
index 0000000000000000000000000000000000000000..25ab25f14a63900e941eb3f29f861ac467924133
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/ad.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/ad_checked.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/ad_checked.png
new file mode 100644
index 0000000000000000000000000000000000000000..84a81c1eb9eaeac26480b2c8c03d36cc6cf7cb8f
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/ad_checked.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/avatar.jpg b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/avatar.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..d24628262fe44bc716d2739a61601fb83496c578
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/avatar.jpg differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/exit.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/exit.png
new file mode 100644
index 0000000000000000000000000000000000000000..2b5f26ab4e18f43db619bb368e372b5a70df5e5d
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/exit.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/keshihua.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/keshihua.png
new file mode 100644
index 0000000000000000000000000000000000000000..9b7c18cee2a466446067b6391ef8435dbc719121
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/keshihua.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/keshihua_checked.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/keshihua_checked.png
new file mode 100644
index 0000000000000000000000000000000000000000..04ecbe4a42aada417f822caf0df83ef4a504882e
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/keshihua_checked.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/lishijilu.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/lishijilu.png
new file mode 100644
index 0000000000000000000000000000000000000000..b0ce8e6fe70d301d6115b3126ac58dabc4e66dd9
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/lishijilu.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/lishijilu_checked.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/lishijilu_checked.png
new file mode 100644
index 0000000000000000000000000000000000000000..1ddcc071b87d6a24e5b29ca2deef6dae57109671
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/lishijilu_checked.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/shezhi.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/shezhi.png
new file mode 100644
index 0000000000000000000000000000000000000000..542c8c615848f3407a6073bf1aa772893f771d07
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/shezhi.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/shezhi_checked.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/shezhi_checked.png
new file mode 100644
index 0000000000000000000000000000000000000000..370ae254559a9264c7db5ad75ee8166fd3ca4cf2
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/shezhi_checked.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangyou.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangyou.png
new file mode 100644
index 0000000000000000000000000000000000000000..55e54e1814609fc3f98f976a5ee462042a877e86
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangyou.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangyou_diable.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangyou_diable.png
new file mode 100644
index 0000000000000000000000000000000000000000..2a4296b7568452a00d004b3ba675218bc602cc3a
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangyou_diable.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangzuo.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangzuo.png
new file mode 100644
index 0000000000000000000000000000000000000000..ffa727baafbe750232d2f466c60b9a0a51aa1b13
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangzuo.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangzuo_diable.png b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangzuo_diable.png
new file mode 100644
index 0000000000000000000000000000000000000000..2cce5afe4efca387d3f45be353b01cda9c010289
Binary files /dev/null and b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Img/xiangzuo_diable.png differ
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.pro b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.pro
new file mode 100644
index 0000000000000000000000000000000000000000..7a0ecf235580dbf6c73d932caf15da8e0538d94b
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.pro
@@ -0,0 +1,50 @@
+QT += core gui charts
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+CONFIG += c++11
+
+# You can make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+ UDPSocket.cpp \
+ adpage.cpp \
+ chartspage.cpp \
+ framelesswindow.cpp \
+ historypage.cpp \
+ imageviewer.cpp \
+ interface.cpp \
+ iot_frameless.cpp \
+ linechart.cpp \
+ listchart.cpp \
+ main.cpp \
+ iotui.cpp \
+ settingpage.cpp
+
+HEADERS += \
+ MThread.hpp \
+ UDPSocket.h \
+ adpage.h \
+ chartspage.h \
+ framelesswindow.h \
+ historypage.h \
+ imageviewer.h \
+ interface.h \
+ iot_frameless.h \
+ iotui.h \
+ linechart.h \
+ listchart.h \
+ settingpage.h
+
+FORMS += \
+ iotui.ui
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+RESOURCES += \
+ Image.qrc
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.pro.user b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.pro.user
new file mode 100644
index 0000000000000000000000000000000000000000..7a42298ace0584b3418a267481f7d192c5baa223
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.pro.user
@@ -0,0 +1,587 @@
+
+
+
+
+
+ EnvironmentId
+ {85b4b67f-a479-4c60-86e9-70956253a84b}
+
+
+ ProjectExplorer.Project.ActiveTarget
+ 0
+
+
+ ProjectExplorer.Project.EditorSettings
+
+ true
+ false
+ true
+
+ Cpp
+
+ CppGlobal
+
+
+
+ QmlJS
+
+ QmlJSGlobal
+
+
+ 2
+ UTF-8
+ false
+ 4
+ false
+ 80
+ true
+ true
+ 1
+ false
+ true
+ false
+ 0
+ true
+ true
+ 0
+ 8
+ true
+ false
+ 1
+ true
+ true
+ true
+ *.md, *.MD, Makefile
+ false
+ true
+
+
+
+ ProjectExplorer.Project.PluginSettings
+
+
+ true
+ false
+ true
+ true
+ true
+ true
+
+
+ 0
+ true
+
+ -fno-delayed-template-parsing
+
+ true
+ Builtin.BuildSystem
+
+ true
+ true
+ Builtin.DefaultTidyAndClazy
+ 8
+
+
+
+ true
+
+
+
+
+ ProjectExplorer.Project.Target.0
+
+ Desktop
+ Desktop Qt 5.12.12 MSVC2017 64bit
+ Desktop Qt 5.12.12 MSVC2017 64bit
+ qt.qt5.51212.win64_msvc2017_64_kit
+ 0
+ 0
+ 0
+
+ 0
+ C:\WorkSpace\Iot2023UI\build-Iot2023-Desktop_Qt_5_12_12_MSVC2017_64bit-Debug
+ C:/WorkSpace/Iot2023UI/build-Iot2023-Desktop_Qt_5_12_12_MSVC2017_64bit-Debug
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+
+ Debug
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+
+
+ C:\WorkSpace\Iot2023UI\build-Iot2023-Desktop_Qt_5_12_12_MSVC2017_64bit-Release
+ C:/WorkSpace/Iot2023UI/build-Iot2023-Desktop_Qt_5_12_12_MSVC2017_64bit-Release
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ true
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+
+ Release
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ 0
+
+
+ 0
+ C:\WorkSpace\Iot2023UI\build-Iot2023-Desktop_Qt_5_12_12_MSVC2017_64bit-Profile
+ C:/WorkSpace/Iot2023UI/build-Iot2023-Desktop_Qt_5_12_12_MSVC2017_64bit-Profile
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+
+ Profile
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ 0
+ 0
+
+ 3
+
+
+ 0
+ Deploy
+ Deploy
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+
+ false
+ ProjectExplorer.DefaultDeployConfiguration
+
+ 1
+
+ true
+ true
+ true
+
+ 2
+
+ Qt4ProjectManager.Qt4RunConfiguration:C:/WorkSpace/Iot2023UI/Iot2023/Iot2023.pro
+ C:/WorkSpace/Iot2023UI/Iot2023/Iot2023.pro
+ false
+ true
+ true
+ false
+ true
+ C:/WorkSpace/Iot2023UI/build-Iot2023-Desktop_Qt_5_12_12_MSVC2017_64bit-Debug
+
+ 1
+
+
+
+ ProjectExplorer.Project.Target.1
+
+ Desktop
+ Desktop Qt 5.12.12 MinGW 64-bit
+ Desktop Qt 5.12.12 MinGW 64-bit
+ qt.qt5.51212.win64_mingw73_kit
+ 1
+ 0
+ 0
+
+ 0
+ C:\WorkSpace\Iot2023UI\build-Iot2023-Desktop_Qt_5_12_12_MinGW_64_bit-Debug
+ C:/WorkSpace/Iot2023UI/build-Iot2023-Desktop_Qt_5_12_12_MinGW_64_bit-Debug
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+
+ Debug
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+
+
+ C:\WorkSpace\Iot2023UI\build-Iot2023-Desktop_Qt_5_12_12_MinGW_64_bit-Release
+ C:/WorkSpace/Iot2023UI/build-Iot2023-Desktop_Qt_5_12_12_MinGW_64_bit-Release
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ 8
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+
+ Release
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ 0
+
+
+ 0
+ C:\WorkSpace\Iot2023UI\build-Iot2023-Desktop_Qt_5_12_12_MinGW_64_bit-Profile
+ C:/WorkSpace/Iot2023UI/build-Iot2023-Desktop_Qt_5_12_12_MinGW_64_bit-Profile
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+
+ Profile
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ 0
+ 0
+
+ 3
+
+
+ 0
+ Deploy
+ Deploy
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+
+ false
+ ProjectExplorer.DefaultDeployConfiguration
+
+ 1
+
+ true
+ true
+ true
+
+ 2
+
+ Qt4ProjectManager.Qt4RunConfiguration:C:/WorkSpace/Iot2023UI/Iot2023/Iot2023.pro
+ C:/WorkSpace/Iot2023UI/Iot2023/Iot2023.pro
+ false
+ true
+ true
+ false
+ true
+
+ 1
+
+
+
+ ProjectExplorer.Project.Target.2
+
+ Desktop
+ 111111
+ 111111
+ {981463f3-2698-4354-b2df-45c39be252df}
+ 1
+ 0
+ 0
+
+ 0
+ C:\WorkSpace\Iot2023UI\build-Iot2023-111111-Debug
+ C:/WorkSpace/Iot2023UI/build-Iot2023-111111-Debug
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+
+ Debug
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+
+
+ C:\WorkSpace\Iot2023UI\build-Iot2023-111111-Release
+ C:/WorkSpace/Iot2023UI/build-Iot2023-111111-Release
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+
+ Release
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ 0
+
+
+ 0
+ C:\WorkSpace\Iot2023UI\build-Iot2023-111111-Profile
+ C:/WorkSpace/Iot2023UI/build-Iot2023-111111-Profile
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+
+ Profile
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ 0
+ 0
+
+ 3
+
+
+ 0
+ Deploy
+ Deploy
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+
+ false
+ ProjectExplorer.DefaultDeployConfiguration
+
+ 1
+
+ true
+ true
+ true
+
+ 2
+
+ Qt4ProjectManager.Qt4RunConfiguration:C:/WorkSpace/Iot2023UI/Iot2023/Iot2023.pro
+ C:/WorkSpace/Iot2023UI/Iot2023/Iot2023.pro
+ false
+ true
+ true
+ false
+ true
+
+ 1
+
+
+
+ ProjectExplorer.Project.TargetCount
+ 3
+
+
+ ProjectExplorer.Project.Updater.FileVersion
+ 22
+
+
+ Version
+ 22
+
+
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.pro.user.3aa0dd1 b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.pro.user.3aa0dd1
new file mode 100644
index 0000000000000000000000000000000000000000..b888d82c526914706bdc406ab0cef180ab3b606a
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.pro.user.3aa0dd1
@@ -0,0 +1,264 @@
+
+
+
+
+
+ EnvironmentId
+ {3aa0dd16-5ce6-4783-8417-0dc49cc50bee}
+
+
+ ProjectExplorer.Project.ActiveTarget
+ 0
+
+
+ ProjectExplorer.Project.EditorSettings
+
+ true
+ false
+ true
+
+ Cpp
+
+ CppGlobal
+
+
+
+ QmlJS
+
+ QmlJSGlobal
+
+
+ 2
+ UTF-8
+ false
+ 4
+ false
+ 80
+ true
+ true
+ 1
+ false
+ true
+ false
+ 0
+ true
+ true
+ 0
+ 8
+ true
+ false
+ 1
+ true
+ true
+ true
+ *.md, *.MD, Makefile
+ false
+ true
+
+
+
+ ProjectExplorer.Project.PluginSettings
+
+
+ true
+ false
+ true
+ true
+ true
+ true
+
+
+ 0
+ true
+
+ true
+ Builtin.BuildSystem
+
+ true
+ true
+ Builtin.DefaultTidyAndClazy
+ 8
+
+
+
+ true
+
+
+
+
+ ProjectExplorer.Project.Target.0
+
+ Desktop
+ 桌面
+ 桌面
+ {a81473be-aff3-4c95-a12f-cac960feb269}
+ 0
+ 0
+ 0
+
+ 0
+ /home/joey/WorkSpace/Iot2023UI/build_debug
+ /home/joey/WorkSpace/Iot2023UI/build_debug
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ false
+
+ Debug
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+
+
+ /home/joey/WorkSpace/build-Iot2023-unknown-Release
+ /home/joey/WorkSpace/build-Iot2023-unknown-Release
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ false
+
+ Release
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+
+
+ 0
+ /home/joey/WorkSpace/build-Iot2023-unknown-Profile
+ /home/joey/WorkSpace/build-Iot2023-unknown-Profile
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+
+ 2
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Qt4ProjectManager.MakeStep
+ clean
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ false
+
+ Profile
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ 0
+
+ 3
+
+
+ 0
+ Deploy
+ Deploy
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+
+ false
+ ProjectExplorer.DefaultDeployConfiguration
+
+ 1
+
+ true
+ true
+ true
+
+ 2
+
+ Iot20232
+ Qt4ProjectManager.Qt4RunConfiguration:/home/joey/WorkSpace/Iot2023UI/Iot2023/Iot2023.pro
+ /home/joey/WorkSpace/Iot2023UI/Iot2023/Iot2023.pro
+ false
+ true
+ true
+ false
+ true
+ /home/joey/WorkSpace/Iot2023UI/build_debug
+
+ 1
+
+
+
+ ProjectExplorer.Project.TargetCount
+ 1
+
+
+ ProjectExplorer.Project.Updater.FileVersion
+ 22
+
+
+ Version
+ 22
+
+
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.sln b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.sln
new file mode 100644
index 0000000000000000000000000000000000000000..46614db47bcfed6fd4e0cb6372e79c9aae847187
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.33627.172
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Iot2023", "Iot2023.vcxproj", "{95CD2448-92A8-36D3-8528-3D73A63B13B5}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Release|x64 = Release|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {95CD2448-92A8-36D3-8528-3D73A63B13B5}.Debug|x64.ActiveCfg = Debug|x64
+ {95CD2448-92A8-36D3-8528-3D73A63B13B5}.Debug|x64.Build.0 = Debug|x64
+ {95CD2448-92A8-36D3-8528-3D73A63B13B5}.Release|x64.ActiveCfg = Release|x64
+ {95CD2448-92A8-36D3-8528-3D73A63B13B5}.Release|x64.Build.0 = Release|x64
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {324C158E-D600-48A6-8811-B0CAF89BD395}
+ EndGlobalSection
+EndGlobal
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.vcxproj b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.vcxproj
new file mode 100644
index 0000000000000000000000000000000000000000..e19854c4586decf649a1b1310b8725adc00295da
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.vcxproj
@@ -0,0 +1,290 @@
+
+
+
+
+ Release
+ x64
+
+
+ Debug
+ x64
+
+
+
+ {95CD2448-92A8-36D3-8528-3D73A63B13B5}
+ Iot2023
+ QtVS_v304
+ 10.0
+ 10.0.22621.0
+ $(MSBuildProjectDirectory)\QtMsBuild
+
+
+
+ v143
+ release\
+ false
+ NotSet
+ Application
+ release\
+ Iot2023
+
+
+ v143
+ debug\
+ false
+ NotSet
+ Application
+ debug\
+ Iot2023
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ debug\
+ debug\
+ Iot2023
+ true
+
+
+ release\
+ release\
+ Iot2023
+ true
+ false
+
+
+ 5.12.12_msvc2017_64
+ core;gui;widgets;charts
+
+
+ 5.12.12_msvc2017_64
+ core;gui;widgets;charts
+
+
+
+
+
+
+ GeneratedFiles\$(ConfigurationName);GeneratedFiles;.;release;/include;%(AdditionalIncludeDirectories)
+ -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 %(AdditionalOptions)
+ release\
+ false
+ None
+ 4577;4467;%(DisableSpecificWarnings)
+ Sync
+ release\
+ MaxSpeed
+ _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;WIN64;QT_NO_DEBUG;NDEBUG;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)
+ false
+
+
+ MultiThreadedDLL
+ true
+ true
+ Level3
+ true
+
+
+ shell32.lib;%(AdditionalDependencies)
+ C:\openssl\lib;C:\Utils\my_sql\mysql-5.6.11-winx64\lib;C:\Utils\postgresql\pgsql\lib;%(AdditionalLibraryDirectories)
+ "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions)
+ true
+ false
+ true
+ false
+ $(OutDir)\Iot2023.exe
+ true
+ Console
+ true
+
+
+ Unsigned
+ None
+ 0
+
+
+ _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;WIN64;QT_NO_DEBUG;%(PreprocessorDefinitions)
+
+
+ msvc
+ ./$(Configuration)/moc_predefs.h
+ Moc'ing %(Identity)...
+ output
+ $(Configuration)
+ moc_%(Filename).cpp
+
+
+ Image
+ default
+ Rcc'ing %(Identity)...
+ $(Configuration)
+ qrc_%(Filename).cpp
+
+
+ Uic'ing %(Identity)...
+ $(ProjectDir)
+ ui_%(Filename).h
+
+
+
+
+
+
+
+
+ GeneratedFiles\$(ConfigurationName);GeneratedFiles;.;debug;/include;%(AdditionalIncludeDirectories)
+ -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 %(AdditionalOptions)
+ debug\
+ false
+ ProgramDatabase
+ 4577;4467;%(DisableSpecificWarnings)
+ Sync
+ debug\
+ Disabled
+ false
+ MultiThreadedDebugDLL
+ true
+ true
+ Level3
+ true
+ WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)
+
+
+ shell32.lib;%(AdditionalDependencies)
+ C:\openssl\lib;C:\Utils\my_sql\mysql-5.6.11-winx64\lib;C:\Utils\postgresql\pgsql\lib;%(AdditionalLibraryDirectories)
+ "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions)
+ true
+ true
+ true
+ $(OutDir)\Iot2023.exe
+ true
+ Console
+ true
+ AsInvoker
+
+
+ Unsigned
+ None
+ 0
+
+
+ _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;WIN64;_DEBUG;%(PreprocessorDefinitions)
+
+
+ msvc
+ ./$(Configuration)/moc_predefs.h
+ Moc'ing %(Identity)...
+ output
+ $(Configuration)
+ moc_%(Filename).cpp
+
+
+ Image
+ default
+ Rcc'ing %(Identity)...
+ $(Configuration)
+ qrc_%(Filename).cpp
+
+
+ Uic'ing %(Identity)...
+ $(ProjectDir)
+ ui_%(Filename).h
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Document
+ true
+ $(QTDIR)\mkspecs\features\data\dummy.cpp;%(AdditionalInputs)
+ cl -Bx"$(QTDIR)\bin\qmake.exe" -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -Zi -MDd -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -E $(QTDIR)\mkspecs\features\data\dummy.cpp 2>NUL >debug\moc_predefs.h
+ Generate moc_predefs.h
+ debug\moc_predefs.h;%(Outputs)
+
+
+ Document
+ $(QTDIR)\mkspecs\features\data\dummy.cpp;%(AdditionalInputs)
+ cl -Bx"$(QTDIR)\bin\qmake.exe" -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -E $(QTDIR)\mkspecs\features\data\dummy.cpp 2>NUL >release\moc_predefs.h
+ Generate moc_predefs.h
+ release\moc_predefs.h;%(Outputs)
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.vcxproj.filters b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.vcxproj.filters
new file mode 100644
index 0000000000000000000000000000000000000000..635ae9b9bb7e6512bac48cf15be53acf17b7ddcf
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.vcxproj.filters
@@ -0,0 +1,193 @@
+
+
+
+
+ {99349809-55BA-4b9d-BF79-8FDBB0286EB3}
+ ui
+ false
+
+
+ {99349809-55BA-4b9d-BF79-8FDBB0286EB3}
+ ui
+ false
+
+
+ {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11}
+ cpp;c;cxx;moc;h;def;odl;idl;res;
+
+
+ {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11}
+ cpp;c;cxx;moc;h;def;odl;idl;res;
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hpp;hxx;hm;inl;inc;xsd
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hpp;hxx;hm;inl;inc;xsd
+
+
+ {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E}
+ qrc;*
+ false
+
+
+ {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E}
+ qrc;*
+ false
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+
+
+ Generated Files
+
+
+ Generated Files
+
+
+
+
+ Form Files
+
+
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+
+
+ Header Files
+
+
+
\ No newline at end of file
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.vcxproj.user b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.vcxproj.user
new file mode 100644
index 0000000000000000000000000000000000000000..d5983fb51641aa55b0d70770ef76424f7edd8753
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/Iot2023.vcxproj.user
@@ -0,0 +1,10 @@
+
+
+
+
+ 2023-07-17T17:18:26.5240672Z
+
+
+ 2023-07-17T17:18:26.6574054Z
+
+
\ No newline at end of file
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/MThread.hpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/MThread.hpp
new file mode 100644
index 0000000000000000000000000000000000000000..944fa441fbf92e7068d1cbd0d6b4333b48604624
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/MThread.hpp
@@ -0,0 +1,145 @@
+// ******************************************************
+// Author : Joey Qiu
+// Last modified: 2023-06-08 16:13
+// Email : 2650982628@qq.com
+// Filename : MThread.hpp
+// Description :
+// ******************************************************
+
+#ifndef MTHREAD_H
+#define MTHREAD_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+// gettid 实现
+//#include
+//#include
+//#define gettid() syscall(__NR_gettid)
+#include
+#define gettid() GetCurrentThreadId()
+
+class MThread{
+ public:
+ MThread(){
+ m_if_run = false;
+ m_if_exit = true;
+ m_flag_if_stop = true;
+ m_tID = 0;
+ }
+
+ bool Start(void){
+ if(m_if_run) {
+ std::cout << "The thread is already running !" < lock(m_mutex);
+ m_if_exit = false;
+ m_tID = 0;
+ std::thread thr(std::bind(&MThread::func,this));
+ __mthread = std::move(thr);
+ __mthread.detach();
+ return true;
+ }
+
+ bool wait(std::chrono::milliseconds waitTime){
+ std::unique_lock lock(m_mutex);
+ if(!m_if_run) {
+ return true;
+ }
+ while (!m_if_exit) {
+ if(m_cv.wait_for(lock, waitTime) == std::cv_status::timeout){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ void wait(){
+ std::unique_lock lock(m_mutex);
+ if(!m_if_run) {
+ return;
+ }
+ while (!m_if_exit) {
+ m_cv.wait(lock);
+ }
+ }
+
+ void func(void){
+ try {
+ {
+ std::lock_guard lock(m_mutex);
+ m_if_run = true;
+ m_tID = gettid();
+ }
+
+ run();
+ }
+ catch (...) {
+ std::cerr << "Exception caught in thread " << m_tID << std::endl;
+ }
+
+ {
+ std::lock_guard lock(m_mutex);
+ m_if_run = false;
+ m_if_exit = true;
+ }
+ m_cv.notify_all();
+ }
+
+ virtual void run(void){
+// usleep(1000*1000);
+ }
+
+ virtual void stop(){
+ m_flag_if_stop = true;
+ wait();
+ }
+
+ void quit(){
+ if(m_if_exit) return;
+ stop();
+ // {
+ // std::lock_guard lock(m_mutex);
+ // m_if_run = false;
+ // m_if_exit = true;
+ // }
+ // m_cv.notify_all();
+ }
+
+ virtual ~MThread(){
+ quit();
+ if(__mthread.joinable()) {
+ __mthread.join();
+ }
+ std::cout << "----------Thread " << m_tID << " exiting----------" <
+#include
+#include
+#include
+#include
+
+#if defined(_MSC_VER)
+typedef SSIZE_T ssize_t;
+#endif
+
+UDPSocket::UDPSocket(const std::string& addr) : m_addr(addr), m_func(nullptr), m_flag_if_init(false)
+{
+ static WSADATA wsaData;
+ if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
+ std::cerr << "Failed to initialize Winsock." << std::endl;
+ exit(EXIT_FAILURE);
+ }
+}
+
+bool UDPSocket::InitUdp(uint16_t port) {
+ if (m_flag_if_init) return true;
+ m_addr._port = port;
+ // Create UDP socket
+ m_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (m_sockfd == INVALID_SOCKET) {
+ std::cerr << "Failed to create socket: " << WSAGetLastError() << std::endl;
+ WSACleanup();
+ exit(EXIT_FAILURE);
+ }
+
+ // Set receive timeout to 1 second
+ DWORD timeout = 1000;
+ if (setsockopt(m_sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)) == SOCKET_ERROR) {
+ std::cerr << "Failed to set socket receive timeout: " << WSAGetLastError() << std::endl;
+ closesocket(m_sockfd);
+ WSACleanup();
+ exit(EXIT_FAILURE);
+ }
+
+ bool bOpt = true;
+ //㲥ѡ
+ setsockopt(m_sockfd, SOL_SOCKET, SO_BROADCAST, (char*)&bOpt, sizeof(bOpt));
+
+
+ struct sockaddr_in Addr;
+ // Set server address
+ Addr.sin_family = AF_INET;
+ Addr.sin_port = htons(m_addr._port); // Let the system automatically assign a available port
+ // Addr.sin_addr.s_addr = inet_addr(m_addr._ip.c_str());
+ Addr.sin_addr.s_addr = INADDR_ANY;
+
+ // Bind socket to address
+ if (bind(m_sockfd, (struct sockaddr*)&Addr, sizeof(Addr)) == SOCKET_ERROR) {
+ std::cerr << "Failed to bind socket: " << WSAGetLastError() << std::endl;
+ closesocket(m_sockfd);
+ WSACleanup();
+ exit(EXIT_FAILURE);
+ }
+ Start();
+ m_flag_if_init = true;
+ return true;
+}
+
+
+void UDPSocket::DeInitUdp() {
+ if (!m_flag_if_init) return;
+ quit();
+ closesocket(m_sockfd);
+ m_flag_if_init = false;
+}
+
+int UDPSocket::sendTo(int socketfd, const std::string& addr, int port, const std::string& message) {
+ if (!m_flag_if_init) return -1;
+ struct sockaddr_in destAddr;
+ destAddr.sin_family = AF_INET;
+ destAddr.sin_port = htons(port);
+ destAddr.sin_addr.s_addr = inet_addr(addr.c_str());
+ // Send message
+ int bytesSent = sendto(socketfd, message.c_str(), message.length(),
+ 0, (struct sockaddr*)&destAddr, sizeof(destAddr));
+ if (bytesSent == SOCKET_ERROR) {
+ std::cerr << "Failed to send message: " << WSAGetLastError() << std::endl;
+ // closesocket(socketfd);
+ // WSACleanup();
+ return -1;
+ }
+ else {
+ // std::cout << "Sent " << bytesSent << " bytes to "
+ // << addr << ":" << port << std::endl;
+ // closesocket(socketfd);
+ // WSACleanup();
+ return 0;
+ }
+}
+
+std::string UDPSocket::receive() {
+ char buffer[BUFFER_SIZE];
+ sockaddr_in srcAddr{ 0 };
+ int addrlen = sizeof(srcAddr);
+
+ // Receive message
+ ssize_t bytesReceived = recvfrom(m_sockfd, buffer, BUFFER_SIZE - 1, 0, (sockaddr*)&srcAddr, &addrlen);
+ if (bytesReceived == SOCKET_ERROR) {
+ int errorCode = WSAGetLastError();
+ if (errorCode == WSAETIMEDOUT) {
+ // std::cerr << "Receive timeout" << std::endl;
+ return "";
+ }
+ else {
+ std::cerr << "Failed to receive data: " << errorCode << std::endl;
+ }
+ return "";
+ }
+
+ buffer[bytesReceived] = '\0';
+ std::string receivedMessage(buffer);
+ // std::cout << "Received " << bytesReceived << " bytes from " << inet_ntoa(srcAddr.sin_addr) << ":" << ntohs(srcAddr.sin_port) << std::endl;
+ return receivedMessage;
+}
+
+void UDPSocket::run() {
+ if (!m_flag_if_init) return;
+ m_flag_if_stop = false;
+ while (!m_flag_if_stop) {
+ auto msg = receive();
+ if (m_func && !msg.empty()) {
+ m_func(msg);
+ }
+ }
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/UDPSocket.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/UDPSocket.h
new file mode 100644
index 0000000000000000000000000000000000000000..f2f5d1b66d9a69c8798eba5bac43b61a1cb8e2d0
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/UDPSocket.h
@@ -0,0 +1,78 @@
+// ******************************************************
+// Author : Joey Qiu
+// Last modified: 2023-07-06 17:55
+// Email : 2650982628@qq.com
+// Filename : UDPSocket.h
+// Description :
+// ******************************************************
+
+#ifndef UDPSOCKET_H
+#define UDPSOCKET_H
+
+#include
+#include
+#include
+#include
+//#include
+//#include
+//#include
+//#include
+#include "MThread.hpp"
+
+#ifdef _WIN32
+#include
+#include
+#pragma comment(lib, "ws2_32.lib")
+#define close closesocket
+#define socklen_t int
+// 其他需要替换的宏和函数
+#else
+#include
+#include
+// 其他Linux特有的头文件
+#endif
+
+
+
+#define BUFFER_SIZE 1024
+
+typedef struct Addr{
+ Addr(const std::string& addr,uint16_t ip = 0):_ip(addr),_port(ip){};
+ const std::string _ip;
+ uint16_t _port;
+}AddrStruct;
+
+
+class UDPSocket: public MThread {
+
+private:
+ int m_sockfd;
+ AddrStruct m_addr;
+ std::function m_func;
+ bool m_flag_if_init;
+
+public:
+ UDPSocket(const std::string & addr);
+ ~UDPSocket(){
+ //终止 DLL 的使用
+ WSACleanup();
+ }
+
+public:
+ bool InitUdp(uint16_t port);
+ void DeInitUdp();
+
+public:
+ int sendTo(int socketfd,const std::string& addr, int port, const std::string& message);
+ std::string receive();
+
+ int getSokcetfd(){return m_sockfd;}
+ std::string getIp(){return m_addr._ip;}
+ uint16_t getPort(){return m_addr._port;}
+
+ void setFunction(std::function func){
+ m_func = func;
+ }
+ virtual void run();
+};
+#endif
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/adpage.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/adpage.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a287c6bf0e2a76f66b0e1d47949f057674e8e41c
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/adpage.cpp
@@ -0,0 +1,128 @@
+#include "adpage.h"
+#include "imageviewer.h"
+#include
+#include
+#include
+#include "interface.h"
+
+ADPage::ADPage(QWidget* parent)
+ : QWidget{ parent }, m_layout(new QVBoxLayout(this)), m_flag_if_start(false)
+{
+ InitStyle();
+ m_layout->setAlignment(Qt::AlignHCenter);
+ ImageViewer *viewer = new ImageViewer();
+ viewer->setFixedSize(1120,560);
+ m_layout->addWidget(viewer);
+ m_layout->setSpacing(5);
+
+
+ QHBoxLayout * form_hlay = new QHBoxLayout();
+ form_hlay->setContentsMargins(260, 20, 0,0);
+ form_hlay->setAlignment(Qt::AlignHCenter);
+ m_layout->addLayout(form_hlay);
+
+ QFormLayout *form = new QFormLayout();
+ form->setAlignment(Qt::AlignCenter);
+ QLineEdit*lined = new QLineEdit();
+ lined->setMinimumHeight(60);
+ lined->setMaximumWidth(300);
+ lined->setAlignment(Qt::AlignCenter);
+ form_hlay->addLayout(form);
+// QPalette palette = lined->palette();
+// palette.setColor(QPalette::Normal,QPalette::PlaceholderText,QColor(128,128,128));
+// lined->setPalette(palette);
+ lined->setPlaceholderText("In Seconds");
+
+ form->addRow("Advertising Schedule",lined);
+ form->setHorizontalSpacing(20);
+ // m_layout->addLayout(form);
+
+ QGridLayout *vlay = new QGridLayout();
+ vlay->setContentsMargins(0, 0, 0, 30);
+ vlay->setAlignment(Qt::AlignCenter);
+ //vlay->setContentsMargins(450,0,10,0);
+ vlay->setSpacing(20);
+
+ QPushButton * but = new QPushButton("Start Push AD");
+ but->setObjectName("funcbut");
+ but->setFixedSize(230, 70);
+ vlay->addWidget(but,0,0);
+ connect(but,&QPushButton::clicked,this,[viewer](){
+ sendMsg("StartPush:"+QString::number(viewer->getCurrentIndex()));
+ });
+
+ but = new QPushButton("Stop Push AD");
+ but->setObjectName("funcbut");
+ but->setFixedSize(230, 70);
+ vlay->addWidget(but,0,1);
+ connect(but,&QPushButton::clicked,this,[](){
+ sendMsg("StopPush");
+ });
+
+ but = new QPushButton("Start Analysis");
+ but->setObjectName("funcbut");
+ but->setFixedSize(230, 70);
+ vlay->addWidget(but,1,0);
+ connect(but,&QPushButton::clicked,this,[this](){
+ if (this->m_flag_if_start) return;
+ UpdateChartDir();
+ sendMsg("start_yolov2");
+ m_flag_if_start = true;
+ });
+
+ but = new QPushButton("Stop Analysis");
+ but->setObjectName("funcbut");
+ but->setFixedSize(230,70);
+ vlay->addWidget(but,1,1);
+ connect(but,&QPushButton::clicked,this,[this](){
+ if (!this->m_flag_if_start) return;
+ sendMsg("stop_yolov2");
+ EndSaveChart();
+ UpdateHistoryPage();
+ m_flag_if_start = false;
+ });
+
+ m_layout->addLayout(vlay);
+ //vlay->addWidget(but);
+
+ viewer->setImages({ ":/Advertisement/Advertisement/1.JPG",
+ ":/Advertisement/Advertisement/2.JPG",
+ ":/Advertisement/Advertisement/3.JPG",
+ ":/Advertisement/Advertisement/4.JPG",
+ ":/Advertisement/Advertisement/5.JPG"
+ });
+
+}
+
+
+void ADPage::InitStyle(){
+ this->setStyleSheet("QLineEdit{"
+ "color: #C0C0C0;"
+ "background-color:#405361;"
+ "font-size:25px;"
+ "border-style:outset;"
+ "border-radius:10px;"
+ "font-style:MingLiU-ExtB;"
+ "}"
+ // "QLineEdit::placeholder{ color: red; }"
+ "QLabel{"
+ "background:rgba(85,170,255,0);"
+ "color:white;"
+ "font-style:MingLiU-ExtB;"
+ "font-size:30px;"
+ "}"
+ "QPushButton#funcbut{"
+ "background:#ced1d8;"
+ "border-style:outset;"
+ "border-radius:15px;"
+ "font-style:MingLiU-ExtB;"
+ "font-size:18px;"
+ "}"
+ "QPushButton#funcbut:hover{"
+ "background-color:#F08080;"
+ "border-style:inset;"
+ "font-size:18px;"
+ "font-style:MingLiU-ExtB;"
+ "}"
+ );
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/adpage.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/adpage.h
new file mode 100644
index 0000000000000000000000000000000000000000..4310c33702793319390d45b2433dd70fb3ff49b8
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/adpage.h
@@ -0,0 +1,21 @@
+#ifndef ADPAGE_H
+#define ADPAGE_H
+
+#include
+#include
+
+class ADPage : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit ADPage(QWidget *parent = nullptr);
+
+private:
+ void InitStyle();
+
+private:
+ QVBoxLayout *m_layout;
+ bool m_flag_if_start;
+};
+
+#endif // ADPAGE_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/chartspage.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/chartspage.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bbf5b393fdeb43a652dba709ecee0ddcaab5ab27
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/chartspage.cpp
@@ -0,0 +1,148 @@
+#include "chartspage.h"
+#include
+#include
+#include
+#include
+
+ChartsPage::ChartsPage(QWidget *parent)
+ : QWidget{parent},m_layout(new QVBoxLayout(this)),m_chart_layout(new QHBoxLayout()),
+ m_stackedLayout(new QStackedLayout()),m_current_index(0)
+{
+ m_layout->setAlignment(Qt::AlignCenter);
+
+ QHBoxLayout *title_lay = new QHBoxLayout();
+ title_lay->setAlignment(Qt::AlignHCenter);
+ QLabel *title = new QLabel("Visual Interface");
+ title_lay->addWidget(title);
+ m_layout->addLayout(title_lay);
+ m_layout->addLayout(m_chart_layout);
+
+ m_chart_layout->setContentsMargins(0, 0, 0, 0);
+
+ previousButton = new QPushButton();
+ previousButton->setFixedSize(40,40);
+ // previousButton->setMinimumSize(50,50);
+ previousButton->setEnabled(false);
+ m_chart_layout->addWidget(previousButton);
+
+ m_chart_layout->addLayout(m_stackedLayout);
+
+ nextButton = new QPushButton();
+ nextButton->setFixedSize(40,40);
+ m_chart_layout->addWidget(nextButton);
+
+ connect(previousButton, &QPushButton::clicked, this, &ChartsPage::showPreviousChart);
+ connect(nextButton, &QPushButton::clicked, this, &ChartsPage::showNextChart);
+
+ // QDateTime currentDateTime = QDateTime::currentDateTime();
+ // QString formattedDateTime = currentDateTime.toString("yyMMdd_hhmmss");
+ // QString pre_dir = QCoreApplication::applicationDirPath() + "/../../saveData/"+formattedDateTime;
+ // QDir dir;
+ // if (dir.mkdir(pre_dir)) {
+ // qDebug() << "Folder " << pre_dir << " created successfully";
+ // } else {
+ // qDebug() << "Failed to create folder";
+ // }
+
+ LineChart *chart = new LineChart(nullptr,400,10,"Time","Focus Num","Focus");
+ m_Charts.insert("Focus",qMakePair(0,chart));
+ m_stackedLayout->addWidget(chart);
+
+ chart = new LineChart(nullptr,400,10,"Time","UnFocus Num","UnFocus");
+ m_Charts.insert("UnFocus",qMakePair(0,chart));
+ m_stackedLayout->addWidget(chart);
+
+ chart = new LineChart(nullptr,400,100,"Time","Total Attention","Total");
+ m_Charts.insert("Total",qMakePair(0,chart));
+ m_stackedLayout->addWidget(chart);
+
+ chart = new LineChart(nullptr,400,1.1,"Time","Advertising Attractiveness",
+ "Attractiveness");
+ m_Charts.insert("Attractiveness",qMakePair(0,chart));
+ m_stackedLayout->addWidget(chart);
+
+ m_stackedLayout->setCurrentIndex(0);
+ InitStyle();
+}
+
+
+void ChartsPage::addPoint(const QString &name, qreal value){
+ auto& item = m_Charts[name];
+ LineChart *chart = item.second;
+// item.first = int(item.first) % int(chart->getMaxX());
+ long point_num = item.first++;
+ chart->addPoint(point_num,value);
+}
+
+void ChartsPage::ChangeSaveFile(const QString& date) {
+
+ for (auto& item: m_Charts.keys()) {
+ LineChart* chart = m_Charts[item].second;
+ chart->setSavefile(date +"/" + item + ".txt");
+ }
+}
+
+void ChartsPage::EndSaveChart() {
+ for (auto& item : m_Charts) {
+ LineChart* chart = item.second;
+ chart->EndSavePoint();
+ auto& num = item.first;
+ num = 0;
+ }
+}
+
+void ChartsPage::showPreviousChart(){
+ --m_current_index;
+ showImage(m_current_index);
+
+ updateButtons();
+}
+
+void ChartsPage::showNextChart(){
+ ++m_current_index;
+ showImage(m_current_index);
+
+ updateButtons();
+}
+
+void ChartsPage::showImage(int index) {
+ if (index >= 0 && index < m_stackedLayout->count()) {
+ m_stackedLayout->setCurrentIndex(index);
+
+ }
+}
+
+void ChartsPage::updateButtons() {
+ previousButton->setEnabled(m_current_index > 0);
+ nextButton->setEnabled(m_current_index < m_stackedLayout->count() - 1);
+}
+
+void ChartsPage::InitStyle(){
+ this->setStyleSheet(
+ "QLabel{"
+ // "background:rgba(85,170,255,0);"
+ "color:white;"
+ "font-style:MingLiU-ExtB;"
+ "font-size:35px;"
+ "}"
+ );
+ previousButton->setStyleSheet("QPushButton{"
+ "border-image: url(:/Image/Img/xiangzuo.png);"
+ "}"
+ "QPushButton:disabled {"
+ " border-image: url(:/Image/Img/xiangzuo_diable.png);"
+ "}");
+ nextButton->setStyleSheet("QPushButton{"
+ " border-image: url(:/Image/Img/xiangyou.png);"
+ "}"
+ "QPushButton:disabled {"
+ " border-image: url(:/Image/Img/xiangyou_diable.png);"
+ "}");
+}
+
+ChartsPage::~ChartsPage(){
+ for (auto& item : m_Charts) {
+ delete item.second;
+ item.second = nullptr;
+ }
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/chartspage.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/chartspage.h
new file mode 100644
index 0000000000000000000000000000000000000000..da8d135fa96880ef41b369a17c954f561ad85b5a
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/chartspage.h
@@ -0,0 +1,44 @@
+#ifndef CHARTSPAGE_H
+#define CHARTSPAGE_H
+
+#include
+#include
+#include "linechart.h"
+#include
+#include
+
+class ChartsPage : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit ChartsPage(QWidget *parent = nullptr);
+
+ void addPoint(const QString& name,qreal value);
+ void ChangeSaveFile(const QString& date);
+ void EndSaveChart();
+
+ virtual ~ChartsPage();
+
+private slots:
+ void showPreviousChart();
+
+ void showNextChart();
+
+private:
+ void showImage(int index);
+
+ void updateButtons();
+
+ void InitStyle();
+
+private:
+ QVBoxLayout *m_layout;
+ QHBoxLayout *m_chart_layout;
+ QStackedLayout *m_stackedLayout;
+ QMap> m_Charts;
+ QPushButton *previousButton;
+ QPushButton *nextButton;
+ int m_current_index;
+};
+
+#endif // CHARTSPAGE_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/framelesswindow.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/framelesswindow.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c96b3284b6282f9f57967f01b80a0f426aa943d6
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/framelesswindow.cpp
@@ -0,0 +1,61 @@
+#include "framelesswindow.h"
+#include
+#include
+#include
+
+//struct FramelessWindowPrivate {
+// FramelessWindowPrivate(QWidget *contentWidget) : contentWidget(contentWidget) {}
+
+// QWidget *contentWidget;
+// QPoint mousePressedPosition; // 鼠标按下时的坐标
+// QPoint windowPositionAsDrag; // 鼠标按小时窗口左上角的坐标
+//};
+
+struct FramelessWindowPrivate {
+ QPoint mousePressedPosition; // 鼠标按下时的坐标
+ QPoint windowPositionAsDrag; // 鼠标按小时窗口左上角的坐标
+};
+
+FramelessWindow::FramelessWindow(QWidget *contentWidget, QWidget *parent) : QWidget(parent) {
+ setWindowFlags(Qt::FramelessWindowHint); // 去掉边框
+ setAttribute(Qt::WA_TranslucentBackground); // 背景透明
+
+ d = new FramelessWindowPrivate();
+
+ // 添加阴影
+ QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(contentWidget);
+ shadowEffect->setColor(Qt::lightGray);
+ shadowEffect->setBlurRadius(4); // 阴影的大小
+ shadowEffect->setOffset(0, 0);
+ contentWidget->setGraphicsEffect(shadowEffect);
+
+ // 添加到窗口中
+ QGridLayout *lo = new QGridLayout();
+ lo->addWidget(contentWidget, 0, 0);
+ lo->setContentsMargins(4, 4, 4, 4); // 注意和阴影大小的协调
+ setLayout(lo);
+}
+
+FramelessWindow::~FramelessWindow() {
+ delete d;
+}
+
+void FramelessWindow::mousePressEvent(QMouseEvent *e) {
+ // 记录鼠标按下时全局的位置和窗口左上角的位置
+ d->mousePressedPosition = e->globalPos();
+ d->windowPositionAsDrag = pos();
+}
+
+void FramelessWindow::mouseReleaseEvent(QMouseEvent *e) {
+ Q_UNUSED(e)
+ // 鼠标放开始设置鼠标按下的位置为 null,表示鼠标没有被按下
+ d->mousePressedPosition = QPoint();
+}
+
+void FramelessWindow::mouseMoveEvent(QMouseEvent *e) {
+ if (!d->mousePressedPosition.isNull()) {
+ // 鼠标按下并且移动时,移动窗口, 相对于鼠标按下时的位置计算,是为了防止误差累积
+ QPoint delta = e->globalPos() - d->mousePressedPosition;
+ move(d->windowPositionAsDrag + delta);
+ }
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/framelesswindow.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/framelesswindow.h
new file mode 100644
index 0000000000000000000000000000000000000000..7b2cb65581017fcc87b53e28abbcaae2d9445f81
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/framelesswindow.h
@@ -0,0 +1,24 @@
+#ifndef FRAMELESSWINDOW_H
+#define FRAMELESSWINDOW_H
+
+#include
+
+struct FramelessWindowPrivate;
+
+class FramelessWindow : public QWidget {
+ Q_OBJECT
+public:
+ explicit FramelessWindow(QWidget *contentWidget, QWidget *parent = 0);
+ ~FramelessWindow();
+
+protected:
+ void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+
+private:
+ FramelessWindowPrivate *d;
+};
+
+
+#endif // FRAMELESSWINDOW_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/historypage.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/historypage.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1b91720b5d0a5cfa551236432c06b5666ee44c50
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/historypage.cpp
@@ -0,0 +1,99 @@
+#include "historypage.h"
+#include
+#include
+#include
+#include
+#include "listchart.h"
+
+HistoryPage::HistoryPage(QWidget *parent)
+ : QWidget{parent},m_vlay(new QVBoxLayout(this)),m_hlay(new QHBoxLayout()),m_listView(new QListView()),m_model()
+{
+ this->setLayout(m_vlay);
+
+ m_vlay->setSpacing(40);
+ QHBoxLayout *title_lay = new QHBoxLayout();
+ title_lay->setAlignment(Qt::AlignHCenter);
+ QLabel *title = new QLabel("History Interface");
+ title_lay->addWidget(title);
+
+
+ m_vlay->addLayout(title_lay);
+
+ m_hlay->setAlignment(Qt::AlignHCenter);
+ // m_hlay->setContentsMargins(210,10,10,0);
+ m_hlay->addWidget(m_listView);
+ m_vlay->addLayout(m_hlay);
+
+ // 设置item的对齐方式为居中对齐
+ m_listView->setModel(&m_model);
+ m_listView->setItemDelegate(new CenteredItemDelegate(m_listView));
+ m_listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ m_listView->setSpacing(10);
+ m_listView->setContentsMargins(50,10,10,50);
+
+ UpdateList();
+
+ // 处理点击事件的槽函数
+ QObject::connect(m_listView, &QListView::clicked, [this](const QModelIndex& index)
+ {
+ auto dir = this->m_model.data(index).toString();
+ auto item = new ListChart(nullptr,dir);
+ item->setGeometry(200,300,this->width(),this->height());
+ item->setWindowTitle(dir);
+ item->show();
+ });
+
+ InitStyle();
+}
+
+
+void HistoryPage::UpdateList() {
+ QString pre_dir = QCoreApplication::applicationDirPath() + "/../../saveData/";
+ QStringList subfolders = getSubfolders(pre_dir);
+ m_model.clear();
+ for (const QString& subfolder : subfolders)
+ {
+ QStandardItem* item = new QStandardItem(subfolder);
+ m_model.appendRow(item);
+ }
+}
+
+QStringList HistoryPage::getSubfolders(const QString& folderPath)
+{
+ QDir folder(folderPath);
+ QStringList subfolders;
+
+ QFileInfoList folderList = folder.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
+
+ for (const QFileInfo& folderInfo : folderList)
+ {
+ subfolders.append(folderInfo.fileName());
+ }
+
+ return subfolders;
+}
+
+void HistoryPage::InitStyle(){
+ this->setStyleSheet(
+ "QLabel{"
+ // "background:rgba(85,170,255,0);"
+ "color:white;"
+ "font-style:MingLiU-ExtB;"
+ "font-size:35px;"
+ "}"
+ );
+
+ m_listView->setStyleSheet(
+ "QListView{"
+ "color:#DCDCDC;"
+ "font-style:MingLiU-ExtB;"
+ "font-size:25px;"
+ // "border-top: 1px solid #C0C0C0;"
+ "text-align: center;"
+ "}"
+ "QListView::item{"
+ "border-top: 2px solid #A9A9A9;"
+// "border-bottom: 2px solid #C0C0C0;"
+ "}"
+ );
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/historypage.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/historypage.h
new file mode 100644
index 0000000000000000000000000000000000000000..ebc80c0dcfeae058a7c532c7145873b193be58c7
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/historypage.h
@@ -0,0 +1,49 @@
+#ifndef HISTORYPAGE_H
+#define HISTORYPAGE_H
+
+#include
+#include
+#include
+#include
+#include
+
+class CenteredItemDelegate : public QStyledItemDelegate
+{
+public:
+ CenteredItemDelegate(QObject* parent = nullptr) : QStyledItemDelegate(parent) {}
+
+ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override
+ {
+ QStyleOptionViewItem centeredOption = option;
+ centeredOption.displayAlignment = Qt::AlignCenter;
+
+ // 调整上下边距
+ int topMargin = 10;
+ int bottomMargin = 10;
+ centeredOption.rect.adjust(0, -topMargin, 0, bottomMargin);
+
+ QStyledItemDelegate::paint(painter, centeredOption, index);
+ }
+};
+
+
+class HistoryPage : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit HistoryPage(QWidget *parent = nullptr);
+ void UpdateList();
+
+private:
+ QStringList getSubfolders(const QString& folderPath);
+ void InitStyle();
+
+private:
+ QVBoxLayout *m_vlay;
+ QHBoxLayout *m_hlay;
+ QListView *m_listView;
+ QStandardItemModel m_model;
+
+};
+
+#endif // HISTORYPAGE_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/imageviewer.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/imageviewer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c62c19e85e65c56a2375d074c312b1075821cb64
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/imageviewer.cpp
@@ -0,0 +1,78 @@
+#include "imageviewer.h"
+
+ImageViewer::ImageViewer(QWidget *parent) : QWidget(parent) {
+ QHBoxLayout *layout = new QHBoxLayout(this);
+ layout->setContentsMargins(0, 0, 0, 0);
+
+ previousButton = new QPushButton( this);
+ previousButton->setFixedSize(50,50);
+ // previousButton->setMinimumSize(50,50);
+ previousButton->setEnabled(false);
+ layout->addWidget(previousButton);
+
+ imageLabel = new QLabel(this);
+ imageLabel->setAlignment(Qt::AlignCenter);
+ layout->addWidget(imageLabel);
+
+ nextButton = new QPushButton(this);
+ nextButton->setFixedSize(50,50);
+ // nextButton->setMinimumSize(50,50);
+ layout->addWidget(nextButton);
+
+ connect(previousButton, &QPushButton::clicked, this, &ImageViewer::showPreviousImage);
+ connect(nextButton, &QPushButton::clicked, this, &ImageViewer::showNextImage);
+
+ previousButton->setStyleSheet("QPushButton{"
+ "border-image: url(:/Image/Img/xiangzuo.png);"
+ "}"
+ "QPushButton:disabled {"
+ " border-image: url(:/Image/Img/xiangzuo_diable.png);"
+ "}"
+ "QPushButton::hover{"
+ "}"
+ "QPushButton::!hover{"
+ "}");
+ nextButton->setStyleSheet("QPushButton{"
+ " border-image: url(:/Image/Img/xiangyou.png);"
+ "}"
+ "QPushButton:disabled {"
+ " border-image: url(:/Image/Img/xiangyou_diable.png);"
+ "}"
+ "QPushButton::hover{"
+ "}"
+ "QPushButton::!hover{"
+ "}");
+}
+
+void ImageViewer::setImages(const QStringList &imagePaths) {
+ images = imagePaths;
+ currentIndex = 0;
+ imageLabel->resize(this->width() - 120,this->height());
+ showImage(currentIndex);
+}
+
+void ImageViewer::showPreviousImage() {
+ currentIndex--;
+ showImage(currentIndex);
+
+ updateButtons();
+}
+
+void ImageViewer::showNextImage() {
+ currentIndex++;
+ showImage(currentIndex);
+
+ updateButtons();
+}
+
+void ImageViewer::showImage(int index) {
+ if (index >= 0 && index < images.size()) {
+ QImage image(images[index]);
+ imageLabel->setPixmap(QPixmap::fromImage(image).scaled(imageLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ }
+}
+
+void ImageViewer::updateButtons() {
+ previousButton->setEnabled(currentIndex > 0);
+ nextButton->setEnabled(currentIndex < images.size() - 1);
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/imageviewer.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/imageviewer.h
new file mode 100644
index 0000000000000000000000000000000000000000..2749fbbed67e9aeb86375c32f8614ac1d9fefd19
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/imageviewer.h
@@ -0,0 +1,35 @@
+#ifndef IMAGEVIEWER_H
+#define IMAGEVIEWER_H
+
+
+#include
+
+class ImageViewer : public QWidget {
+public:
+ ImageViewer(QWidget *parent = nullptr);
+
+ void setImages(const QStringList &imagePaths);
+
+ int getCurrentIndex(){
+ return currentIndex;
+ }
+
+private slots:
+ void showPreviousImage();
+
+ void showNextImage();
+
+private:
+ void showImage(int index);
+
+ void updateButtons();
+
+private:
+ QLabel *imageLabel;
+ QPushButton *previousButton;
+ QPushButton *nextButton;
+ QStringList images;
+ int currentIndex;
+};
+
+#endif // IMAGEVIEWER_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/interface.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/interface.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..19cdcd26b57a2446e2514af2058873f4ef5cb6e5
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/interface.cpp
@@ -0,0 +1,100 @@
+#include "interface.h"
+#include "UDPSocket.h"
+#include
+#include
+#include
+
+static QString Ip_Addr = "";
+static uint16_t Ip_port = 0;
+
+static UDPSocket UdpSocket("127.0.0.1");
+
+static ChartsPage* chart_ = nullptr;
+static HistoryPage* history_ = nullptr;
+
+void setChart(ChartsPage *chart){
+ chart_ = chart;
+}
+
+void setHistory(HistoryPage* history) {
+ history_ = history;
+}
+
+
+void UpdateChartDir() {
+ if (!chart_) return;
+ QDateTime currentDateTime = QDateTime::currentDateTime();
+ QString formattedDateTime = currentDateTime.toString("yyMMdd_hhmmss");
+ QString pre_dir = QCoreApplication::applicationDirPath() + "/../../saveData/" + formattedDateTime;
+ QDir dir;
+ if (dir.mkdir(pre_dir)) {
+ qDebug() << "Folder " << pre_dir << " created successfully";
+ }
+ else {
+ qDebug() << "Failed to create folder";
+ }
+ chart_->ChangeSaveFile(pre_dir);
+}
+
+void EndSaveChart() {
+ if (!chart_) return;
+ chart_->EndSaveChart();
+}
+
+void UpdateHistoryPage() {
+ history_->UpdateList();
+}
+
+void InitUdpSocket(uint16_t port) {
+ UdpSocket.InitUdp(port);
+}
+
+void DeInitUdpSocket() {
+ UdpSocket.DeInitUdp();
+}
+
+static void RecvProcess(const std::string& msg) {
+ QString qmsg = QString::fromStdString(msg).trimmed();
+ // qDebug() << qmsg;
+ QStringList msg_list = qmsg.split(",", QString::SkipEmptyParts);
+ if (msg_list.isEmpty() || msg_list.size() < 0)
+ return;
+ for (auto& item : msg_list) {
+ QStringList item_list = item.split(":", QString::SkipEmptyParts);
+ if (item_list.size() == 2) {
+ QString key = item_list[0];
+ QString value = item_list[1];
+ bool conversionOk = false;
+ double numericValue = value.toDouble(&conversionOk);
+ if (conversionOk) {
+ try {
+ chart_->addPoint(key, numericValue);
+ }
+ catch (...) {
+ qDebug() << "addPoint Error";
+ }
+ }
+ else {
+ qDebug() << "Convert to Double Error";
+ }
+ }
+ }
+}
+
+void InitUdpFunction(){
+ UdpSocket.setFunction(RecvProcess);
+}
+
+bool sendMsg(const QString & msg){
+ if (Ip_Addr.isEmpty() && msg.isEmpty())
+ return false;
+ return UdpSocket.sendTo(UdpSocket.getSokcetfd(),Ip_Addr.toStdString()
+ ,Ip_port,msg.toStdString());
+}
+
+void setSendAddr(const QString& ip, uint16_t port){
+ Ip_Addr = ip;
+ Ip_port = port;
+}
+
+
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/interface.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/interface.h
new file mode 100644
index 0000000000000000000000000000000000000000..9dbb7401f87b9a226bca27518676dfdcbc5c0635
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/interface.h
@@ -0,0 +1,20 @@
+#ifndef INTERFACE_H
+#define INTERFACE_H
+
+#include
+#include "chartspage.h"
+#include "historypage.h"
+
+
+bool sendMsg(const QString & msg);
+void setSendAddr(const QString& ip, uint16_t port);
+void setChart(ChartsPage *chart);
+void setHistory(HistoryPage* history);
+void UpdateChartDir();
+void EndSaveChart();
+void UpdateHistoryPage();
+void InitUdpFunction();
+void InitUdpSocket(uint16_t port);
+void DeInitUdpSocket();
+
+#endif // INTERFACE_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iot_frameless.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iot_frameless.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3ee780ad4feb5a663bc291288b4a7f72fd534850
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iot_frameless.cpp
@@ -0,0 +1,31 @@
+#include "iot_frameless.h"
+
+Iot_frameless::Iot_frameless(QWidget *parent)
+ : QWidget{parent}
+{
+ m_iot_ui = new IotUI();
+ m_frameless_win = new FramelessWindow(m_iot_ui);
+ QPushButton* temp = m_iot_ui->getExitBut();
+ connect(temp,&QPushButton::clicked,this,&Iot_frameless::CloseFrameless);
+ // m_frameless_win->resize(m_login->width(),m_login->height());
+ m_frameless_win->setGeometry(1000,200,m_iot_ui->width(),m_iot_ui->height());
+}
+
+
+void Iot_frameless::ShowFrameless(){
+ m_frameless_win->show();
+}
+
+void Iot_frameless::CloseFrameless(){
+ m_frameless_win->close();
+}
+
+IotUI* Iot_frameless::getLogin(){
+ return m_iot_ui;
+}
+
+Iot_frameless::~Iot_frameless(){
+ delete m_frameless_win;
+}
+
+
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iot_frameless.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iot_frameless.h
new file mode 100644
index 0000000000000000000000000000000000000000..361a24632e6582bb5ce9fdf86351e093e7345d67
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iot_frameless.h
@@ -0,0 +1,28 @@
+#ifndef IOT_FRAMELESS_H
+#define IOT_FRAMELESS_H
+
+#include
+#include "iotui.h"
+#include "framelesswindow.h"
+
+class Iot_frameless : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit Iot_frameless(QWidget *parent = nullptr);
+ ~Iot_frameless();
+ void ShowFrameless();
+ IotUI* getLogin();
+
+public slots:
+ void CloseFrameless();
+
+private:
+ IotUI * m_iot_ui = nullptr;
+ FramelessWindow *m_frameless_win = nullptr;
+
+signals:
+
+};
+
+#endif // IOT_FRAMELESS_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iotui.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iotui.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5ee5f3ff1faa0b84742bb8cc3de427d4ad736650
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iotui.cpp
@@ -0,0 +1,97 @@
+#include "iotui.h"
+#include "ui_iotui.h"
+#include "historypage.h"
+#include
+#include
+#include "settingpage.h"
+#include "interface.h"
+
+IotUI::IotUI(QWidget *parent)
+ : QWidget(parent)
+ , ui(new Ui::IotUI),m_buttonGroup(nullptr)
+{
+ ui->setupUi(this);
+ InitUI();
+
+ connect(ui->pushButton_2,&QPushButton::clicked,this,[this](){
+ this->m_stack_lay->setCurrentIndex(0);
+ });
+ connect(ui->pushButton_3,&QPushButton::clicked,this,[this](){
+ this->m_stack_lay->setCurrentIndex(1);
+ });
+ connect(ui->pushButton_4,&QPushButton::clicked,this,[this](){
+ this->m_stack_lay->setCurrentIndex(2);
+ });
+ connect(ui->pushButton_5,&QPushButton::clicked,this,[this](){
+ this->m_stack_lay->setCurrentIndex(3);
+ });
+
+// int count = 0;
+// static QTimer timer;
+// QObject::connect(&timer, &QTimer::timeout, [this,count]()mutable{
+// qreal y = qreal(count) /3;
+// count = (count +1)%80;
+// auto item =static_cast(this->m_stack_lay->itemAt(1)->widget());
+// item->addPoint("Focus",y);
+// });
+// timer.start(40);
+
+ InitUdpFunction();
+}
+
+
+void IotUI::InitUI(){
+ InitButton();
+ InitShowWin();
+}
+
+void IotUI::InitButton(){
+ m_buttonGroup = new QButtonGroup(this);
+ m_buttonGroup->setExclusive(true);
+
+ ui->pushButton_2->setCheckable(true);
+ ui->pushButton_3->setCheckable(true);
+ ui->pushButton_4->setCheckable(true);
+ ui->pushButton_5->setCheckable(true);
+ ui->pushButton_2->setChecked(true);
+ m_buttonGroup->addButton(ui->pushButton_2);
+ m_buttonGroup->addButton(ui->pushButton_3);
+ m_buttonGroup->addButton(ui->pushButton_4);
+ m_buttonGroup->addButton(ui->pushButton_5);
+}
+
+void IotUI::InitShowWin(){
+ auto win = ui->widget;
+ m_stack_lay = new QStackedLayout(win);
+ win->setLayout(m_stack_lay);
+ auto ad_viewer = new ADPage();
+ ad_viewer->setGeometry((win->width()- 1160)/2,(win->height() - 980)/2,1160,980);
+ m_stack_lay->addWidget(ad_viewer);
+
+ auto chart_viewer = new ChartsPage();
+ setChart(chart_viewer);
+ chart_viewer->setGeometry((win->width() - 1160) / 2, (win->height() - 980) / 2, 1160, 980);
+ m_stack_lay->addWidget(chart_viewer);
+
+ auto history_viewer = new HistoryPage();
+ setHistory(history_viewer);
+ chart_viewer->setGeometry((win->width() - 1160) / 2, (win->height() - 980) / 2, 1160, 980);
+ m_stack_lay->addWidget(history_viewer);
+
+ auto setpage = new SettingPage();
+ setpage->setGeometry((win->width()-680)/2,(win->height() - 720)/2,680,700);
+ m_stack_lay->addWidget(setpage);
+ m_stack_lay->setCurrentIndex(0);
+ win->show();
+}
+
+IotUI::~IotUI()
+{
+ delete m_buttonGroup;
+ delete ui;
+}
+
+QPushButton* IotUI::getExitBut(){
+ return ui->pushButton;
+}
+
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iotui.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iotui.h
new file mode 100644
index 0000000000000000000000000000000000000000..811e71096f6911488091e4debd530832135fd3ce
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iotui.h
@@ -0,0 +1,35 @@
+#ifndef IOTUI_H
+#define IOTUI_H
+
+#include
+#include
+#include
+#include "adpage.h"
+#include "chartspage.h"
+#include
+
+QT_BEGIN_NAMESPACE
+namespace Ui { class IotUI; }
+QT_END_NAMESPACE
+
+class IotUI : public QWidget
+{
+ Q_OBJECT
+
+public:
+ IotUI(QWidget *parent = nullptr);
+ ~IotUI();
+ QPushButton* getExitBut();
+
+private:
+ void InitUI();
+ void InitButton();
+ void InitShowWin();
+
+private:
+ Ui::IotUI *ui;
+ QButtonGroup *m_buttonGroup;
+ QStackedLayout *m_stack_lay;
+
+};
+#endif // IOTUI_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iotui.ui b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iotui.ui
new file mode 100644
index 0000000000000000000000000000000000000000..25043ad30a0a54cc638f2f395c6561fa116dbc4c
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/iotui.ui
@@ -0,0 +1,214 @@
+
+
+ IotUI
+
+
+
+ 0
+ 0
+ 1220
+ 1020
+
+
+
+ IotUI
+
+
+ *{
+background:rgb(255, 255, 255);
+font-size:15px;
+font-style:MingLiU-ExtB;
+}
+QWidget{
+border:sold 10px rgba(0,0,0);
+background:transparent;
+}
+#frame{
+border-radius:30;
+border:sold 10px rgba(0,0,0);
+background-color: #696969;
+}
+
+
+
+
+ 10
+ 10
+ 1200
+ 1000
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
+
+ 20
+ 50
+ 1161
+ 931
+
+
+
+ -
+
+
+
+ 660
+ 780
+
+
+
+
+ -
+
+
+ 100
+
+
+ 50
+
+
+ 50
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 40
+
+
+
+
+ 40
+ 40
+
+
+
+ QPushButton {
+ border-image: url(:/Image/Img/ad.png);
+}
+
+QPushButton:checked {
+ border-image: url(:/Image/Img/ad_checked.png);
+}
+
+
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 40
+ 40
+
+
+
+ QPushButton {
+ border-image: url(:/Image/Img/keshihua.png);
+}
+
+QPushButton:checked {
+ border-image: url(:/Image/Img/keshihua_checked.png);
+}
+
+
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 40
+ 40
+
+
+
+ QPushButton {
+ border-image: url(:/Image/Img/lishijilu.png);
+}
+
+QPushButton:checked {
+ border-image: url(:/Image/Img/lishijilu_checked.png);
+}
+
+
+
+
+
+
+ -
+
+
+
+ 40
+ 40
+
+
+
+ QPushButton {
+ border-image: url(:/Image/Img/shezhi.png);
+}
+
+QPushButton:checked {
+ border-image: url(:/Image/Img/shezhi_checked.png);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 20
+ 10
+ 35
+ 35
+
+
+
+ border-image: url(:/Image/Img/exit.png);
+
+
+
+
+
+
+
+
+
+
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/linechart.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/linechart.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0a8840aab5d3919df8163c77ccee652fe85959a5
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/linechart.cpp
@@ -0,0 +1,125 @@
+#include "linechart.h"
+#include
+#include
+
+
+LineChart::LineChart(QWidget* parent, qreal xMax, qreal yMax,
+ const QString& xName, const QString& yName,
+ const QString& title, const QString& saveFile)
+ : QWidget{ parent }, m_chart(new QChart()), m_series(new QLineSeries()),
+ m_axisX(new QValueAxis), m_axisY(new QValueAxis()), m_chartView(new QChartView(m_chart, this)),
+ m_timer(this), m_filename(saveFile), m_save_points(0), m_xMax(xMax),m_yCurrMax(yMax),m_yMax(yMax), m_num_iter(0)
+{
+
+ m_chart->setTitle(title);
+ m_chart->addSeries(m_series);
+ // 设置坐标轴名称
+ m_axisX->setTitleText(xName);
+ m_axisY->setTitleText(yName);
+
+ // 设置坐标轴刻度范围
+ m_axisX->setRange(0, xMax);
+ m_axisY->setRange(0, yMax);
+
+ // 添加坐标轴到折线图
+ m_chart->addAxis(m_axisX, Qt::AlignBottom);
+ m_chart->addAxis(m_axisY, Qt::AlignLeft);
+
+ // 将折线系列关联到坐标轴
+ m_series->attachAxis(m_axisX);
+ m_series->attachAxis(m_axisY);
+
+ // 创建折线图视图,抗锯齿
+ m_chartView->setRenderHint(QPainter::Antialiasing);
+
+ // 将折线图视图设置为该QWidget的子部件
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ layout->addWidget(m_chartView);
+ setLayout(layout);
+
+ m_save_points.clear();
+ connect(&m_timer, &QTimer::timeout, this, &LineChart::saveData);
+ m_timer.setInterval(20 * 1000);
+ m_timer.start();
+}
+
+
+// 添加点到折线图
+void LineChart::addPoint(qreal x, qreal y)
+{
+ if (y > m_yCurrMax)
+ setMaxXY(m_xMax, y);
+ if (m_series->count() >= m_xMax)
+ {
+ ++m_num_iter;
+ m_save_points += m_series->pointsVector();
+ m_series->clear();
+ m_axisX->setRange(m_num_iter * m_xMax, m_xMax * (m_num_iter + 1));
+ }
+ m_series->append(x, y);
+}
+
+
+void LineChart::saveData()
+{
+ if (m_filename.isEmpty() || m_save_points.empty())
+ return;
+
+ QFile file(m_filename);
+ if (!file.open(QIODevice::Append | QIODevice::Text))
+ return;
+
+ QTextStream out(&file);
+
+ for (const QPointF& point : m_save_points) {
+ out << point.x() << " " << point.y() << "\n";
+ }
+ m_save_points.clear();
+ file.close();
+}
+
+void LineChart::restoreData(const QString& name) {
+ if (name.isEmpty())
+ return;
+
+ QFile file(name);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return;
+
+ QTextStream in(&file);
+ QVector points;
+ while (!in.atEnd()) {
+ QString line = in.readLine();
+ QStringList values = line.split(" ");
+ if (values.size() != 2)
+ continue;
+
+ bool ok;
+ qreal x = values[0].toDouble(&ok);
+ if (!ok)
+ continue;
+
+ qreal y = values[1].toDouble(&ok);
+ if (!ok)
+ continue;
+
+ points.append(QPointF(x, y));
+ }
+
+ file.close();
+
+ auto max_point = std::max_element(points.constBegin(), points.constEnd()
+ , [](const QPointF& point1, const QPointF& point2) {
+ return point1.y() < point2.y();
+ });
+
+
+ m_series->replace(points);
+ setMaxXY(points.size(), max_point->y());
+}
+
+LineChart::~LineChart() {
+ EndSavePoint();
+}
+
+
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/linechart.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/linechart.h
new file mode 100644
index 0000000000000000000000000000000000000000..4bb7fcbdc77fb0752fc0b4591c1c3fa51936385e
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/linechart.h
@@ -0,0 +1,72 @@
+#ifndef LINECHART_H
+#define LINECHART_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+QT_CHARTS_USE_NAMESPACE
+
+class LineChart : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit LineChart(QWidget* parent = nullptr, qreal xMax = 0, qreal yMax = 0,
+ const QString& xName = "x", const QString& yName = "y",
+ const QString& title = "title", const QString& saveFile = "");
+
+ virtual ~LineChart();
+ // 添加点到折线图
+ void addPoint(qreal x, qreal y);
+ qreal getMaxX() { return m_xMax; }
+ void restoreData(const QString& name);
+ void setSavefile(const QString& name) {
+ if (name.isEmpty())
+ return;
+ m_filename = name;
+ }
+ void EndSavePoint() {
+ m_save_points += m_series->pointsVector();
+ m_series->clear();
+ saveData();
+ setMaxXY(m_xMax,m_yMax);
+ m_num_iter = 0;
+ }
+
+public slots:
+ void saveData();
+
+private:
+ void setMaxXY(qreal x, qreal y) {
+ m_xMax = x;
+ m_yCurrMax = y;
+ m_axisX->setRange(0, x);
+ m_axisY->setRange(0, y);
+ }
+
+ void setXYName(const QString& xName, const QString& yName) {
+ m_axisX->setTitleText(xName);
+ m_axisY->setTitleText(yName);
+ }
+
+private:
+ QChart* m_chart;
+ QLineSeries* m_series;
+ QValueAxis* m_axisX;
+ QValueAxis* m_axisY;
+ QChartView* m_chartView;
+
+ QTimer m_timer;
+ QString m_filename;
+ QVector m_save_points;
+ qreal m_xMax, m_yCurrMax,m_yMax;
+ int m_num_iter;
+};
+
+
+#endif // LINECHART_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/listchart.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/listchart.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8317b7531ec90c42265df099982961d7547f710a
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/listchart.cpp
@@ -0,0 +1,89 @@
+#include "listchart.h"
+#include
+#include "linechart.h"
+
+ListChart::ListChart(QWidget *parent,const QString& dir)
+ : QWidget{parent},m_stackedLayout(new QStackedLayout()),
+ m_previousButton(new QPushButton()),m_nextButton(new QPushButton()),
+ m_current_index(0)
+{
+ QString pre_dir = QCoreApplication::applicationDirPath() + "/../../saveData/"+dir;
+ QHBoxLayout* hlay = new QHBoxLayout(this);
+ this->setLayout(hlay);
+
+ hlay->setContentsMargins(0, 0, 0, 0);
+
+ m_previousButton->setFixedSize(40,40);
+ // previousButton->setMinimumSize(50,50);
+ m_previousButton->setEnabled(false);
+ hlay->addWidget(m_previousButton);
+
+ hlay->addLayout(m_stackedLayout);
+
+ m_nextButton->setFixedSize(40,40);
+ hlay->addWidget(m_nextButton);
+
+ LineChart *chart = new LineChart(nullptr,400,30,"Time","Focus Num","Focus","");
+ m_stackedLayout->addWidget(chart);
+ chart->restoreData(pre_dir+"/Focus.txt");
+
+ chart = new LineChart(nullptr,400,30,"Time","UnFocus Num","UnFocus","");
+ m_stackedLayout->addWidget(chart);
+ chart->restoreData(pre_dir+"/UnFocus.txt");
+
+ chart = new LineChart(nullptr,400,100,"Time","Total Attention","Total","");
+ m_stackedLayout->addWidget(chart);
+ chart->restoreData(pre_dir+"/Total.txt");
+
+ chart = new LineChart(nullptr,400,1.1,"Time","Advertising Attractiveness",
+ "Attractiveness","");
+ chart->restoreData(pre_dir+"/Attractiveness.txt");
+ m_stackedLayout->addWidget(chart);
+
+ m_stackedLayout->setCurrentIndex(0);
+ InitStyle();
+
+ connect(m_previousButton, &QPushButton::clicked, this, &ListChart::showPreviousChart);
+ connect(m_nextButton, &QPushButton::clicked, this, &ListChart::showNextChart);
+}
+
+void ListChart::showPreviousChart(){
+ --m_current_index;
+ showImage(m_current_index);
+
+ updateButtons();
+}
+
+void ListChart::showNextChart(){
+ ++m_current_index;
+ showImage(m_current_index);
+
+ updateButtons();
+}
+
+void ListChart::showImage(int index) {
+ if (index >= 0 && index < m_stackedLayout->count()) {
+ m_stackedLayout->setCurrentIndex(index);
+
+ }
+}
+
+void ListChart::updateButtons() {
+ m_previousButton->setEnabled(m_current_index > 0);
+ m_nextButton->setEnabled(m_current_index < m_stackedLayout->count() - 1);
+}
+
+void ListChart::InitStyle(){
+ m_previousButton->setStyleSheet("QPushButton{"
+ "border-image: url(:/Image/Img/xiangzuo.png);"
+ "}"
+ "QPushButton:disabled {"
+ " border-image: url(:/Image/Img/xiangzuo_diable.png);"
+ "}");
+ m_nextButton->setStyleSheet("QPushButton{"
+ " border-image: url(:/Image/Img/xiangyou.png);"
+ "}"
+ "QPushButton:disabled {"
+ " border-image: url(:/Image/Img/xiangyou_diable.png);"
+ "}");
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/listchart.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/listchart.h
new file mode 100644
index 0000000000000000000000000000000000000000..493f4b7ffadd3be0d378a5f99f95d2a167aad9bf
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/listchart.h
@@ -0,0 +1,48 @@
+#ifndef LISTCHART_H
+#define LISTCHART_H
+
+#include
+#include
+#include
+#include
+
+
+class ListChart : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit ListChart(QWidget *parent = nullptr,const QString& dir = "");
+
+private:
+ void Destory()
+ {
+ deleteLater();
+ }
+
+private slots:
+ void showPreviousChart();
+
+ void showNextChart();
+
+private:
+ void showImage(int index);
+
+ void updateButtons();
+
+ void InitStyle();
+
+protected:
+ void closeEvent(QCloseEvent *event) override
+ {
+ Destory();
+ QWidget::closeEvent(event);
+ }
+
+private:
+ QStackedLayout *m_stackedLayout;
+ QPushButton *m_previousButton;
+ QPushButton *m_nextButton;
+ int m_current_index;
+};
+
+#endif // LISTCHART_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/main.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/main.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3e90bec214fe0f55d3d76e065e9c5a09eeb777bb
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/main.cpp
@@ -0,0 +1,11 @@
+#include "iot_frameless.h"
+
+#include
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ Iot_frameless w;
+ w.ShowFrameless();
+ return a.exec();
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/settingpage.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/settingpage.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..2b24950fabd3a771ab741771930c186b0249ab77
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/settingpage.cpp
@@ -0,0 +1,137 @@
+#include "settingpage.h"
+#include
+#include
+#include
+#include (
+#include "interface.h"
+
+SettingPage::SettingPage(QWidget* parent)
+ : QWidget{ parent }, m_vlay(new QVBoxLayout(this)),
+ m_ipLineEdit(new QLineEdit()), m_portLineEdit(new QLineEdit()), m_localportLineEdit(new QLineEdit())
+{
+ m_vlay->setAlignment(Qt::AlignCenter);
+ m_vlay->setSpacing(20);
+ // 创建标题标签
+ QLabel *titleLabel = new QLabel("IotSmartVision");
+ titleLabel->setObjectName("title");
+ titleLabel->setAlignment(Qt::AlignCenter);
+ m_vlay->addWidget(titleLabel);
+
+ // 创建圆形头像
+ QHBoxLayout *h_lay = new QHBoxLayout();
+ h_lay->setContentsMargins(0,50,10,0);
+ h_lay->setAlignment(Qt::AlignHCenter);
+ CircleLabel *avatarLabel = new CircleLabel(nullptr,":Image/Img/avatar.jpg");
+ avatarLabel->setFixedSize(150, 150); // 设置固定大小,以显示圆形效果
+ h_lay->addWidget(avatarLabel);
+ m_vlay->addLayout(h_lay);
+
+ QLabel *userLabel = new QLabel("Enjoy It");
+ userLabel->setObjectName("user");
+ userLabel->setAlignment(Qt::AlignCenter);
+ m_vlay->addWidget(userLabel);
+ userLabel->setContentsMargins(0,0,10,0);
+
+ // 创建登录表单
+ QFormLayout *formLayout = new QFormLayout();
+ formLayout->setSpacing(20);
+ m_vlay->addLayout(formLayout);
+ formLayout->setContentsMargins(320,20,10,50);
+
+
+ // 创建 bind port 输入框
+ m_localportLineEdit->setAlignment(Qt::AlignCenter);
+ QLabel* LocalPortLabel = new QLabel("Local Port ");
+ LocalPortLabel->setObjectName("login");
+ formLayout->addRow(LocalPortLabel, m_localportLineEdit);
+ m_localportLineEdit->setFixedSize(300, 60);
+
+ // 创建IP输入框
+ m_ipLineEdit->setAlignment(Qt::AlignCenter);
+ QLabel *ipLabel = new QLabel("IP ");
+ ipLabel->setObjectName("login");
+ formLayout->addRow(ipLabel, m_ipLineEdit);
+ m_ipLineEdit->setFixedSize(300,60);
+
+
+ // 创建port输入框
+ m_portLineEdit->setAlignment(Qt::AlignCenter);
+ QLabel *portLabel = new QLabel("Port ");
+ portLabel->setObjectName("login");
+ formLayout->addRow(portLabel, m_portLineEdit);
+ m_portLineEdit->setFixedSize(300,60);
+
+ QHBoxLayout* h_butlay = new QHBoxLayout();
+ h_butlay->setAlignment(Qt::AlignHCenter);
+ h_butlay->setSpacing(30);
+
+
+ // 创建绑定按钮
+ QPushButton* bindButton = new QPushButton("Bind");
+ bindButton->setFixedSize(260, 60);
+ h_butlay->addWidget(bindButton);
+ m_vlay->addLayout(h_butlay);
+
+ // 创建登录按钮
+ QPushButton *loginButton = new QPushButton("Login");
+ loginButton->setFixedSize(260,60);
+ h_butlay->addWidget(loginButton);
+
+ // 连接按钮的点击信号到相应的槽函数
+ connect(loginButton, &QPushButton::clicked, this, [this](){
+ QString ip = this->m_ipLineEdit->text();
+ uint16_t port = this->m_portLineEdit->text().toUShort();
+ setSendAddr(ip,port);
+ });
+
+ connect(bindButton, &QPushButton::clicked, this, [this]() {
+ uint16_t port = this->m_localportLineEdit->text().toUShort();
+ DeInitUdpSocket();
+ InitUdpSocket(port);
+ });
+
+ InitStyle();
+}
+
+
+void SettingPage::InitStyle(){
+ this->setStyleSheet("QLineEdit{"
+ "color: #C0C0C0;"
+ "background-color:#405361;"
+ "font-size:25px;"
+ "border-style:outset;"
+ "border-radius:10px;"
+ "font-style:MingLiU-ExtB;"
+ "}"
+ // "QLineEdit::placeholder{ color: red; }"
+ "QLabel#title{"
+ "color:white;"
+ "font-style:MingLiU-ExtB;"
+ "font-size:35px;"
+ "}"
+ "QLabel#user{"
+ "color: #E1FFFF;"
+ "font-style:italic;"
+ "font-size:25px;"
+ "}"
+ "QLabel#login{"
+ "background:rgba(85,170,255,0);"
+ "color:white;"
+ "font-style:MingLiU-ExtB;"
+ "font-size:30px;"
+ "}"
+ "QPushButton{"
+ "background:#ced1d8;"
+ "border-style:outset;"
+ "border-radius:15px;"
+ "font-style:MingLiU-ExtB;"
+ "font-size:22px;"
+ "}"
+ "QPushButton:hover{"
+ "background-color:#F08080;"
+ "border-style:inset;"
+ "font-size:22px;"
+ "font-style:MingLiU-ExtB;"
+ "}"
+ );
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/settingpage.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/settingpage.h
new file mode 100644
index 0000000000000000000000000000000000000000..b52908ed81aca59c0525712e8dc80e3634d97172
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/settingpage.h
@@ -0,0 +1,57 @@
+#ifndef SETTINGPAGE_H
+#define SETTINGPAGE_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+class CircleLabel : public QLabel
+{
+public:
+ CircleLabel(QWidget *parent = nullptr,const QString &path = "")
+ : QLabel(parent),m_imgPath(path){}
+
+protected:
+ void paintEvent(QPaintEvent *event) override
+ {
+ QLabel::paintEvent(event);
+
+ // 获取头像图片
+ QPixmap pixmap = QPixmap(m_imgPath);
+ if (pixmap.isNull())
+ return;
+
+ // 绘制圆形头像
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing, true);
+ painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
+ QPainterPath path;
+ path.addEllipse(QRectF(0, 0, width(), height()));
+ painter.setClipPath(path);
+ painter.drawPixmap(0, 0, width(), height(), pixmap.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ }
+
+private:
+ QString m_imgPath;
+};
+
+class SettingPage : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit SettingPage(QWidget *parent = nullptr);
+
+private:
+ void InitStyle();
+
+private:
+ QVBoxLayout *m_vlay;
+ QLineEdit *m_ipLineEdit,*m_portLineEdit,*m_localportLineEdit;
+};
+
+#endif // SETTINGPAGE_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpfunction.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpfunction.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9e13094e97526d2703b713277827c368da703a46
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpfunction.cpp
@@ -0,0 +1,39 @@
+#include "udpfunction.h"
+
+UDPFunction::UDPFunction(QObject *parent) : QObject(parent),m_func(nullptr)
+{
+ m_udpSocket = new QUdpSocket(this);
+ m_udpSocket->bind(QHostAddress::LocalHost,3000);
+ connect(m_udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()));
+}
+
+void UDPFunction::setProcess(UDPProcess func){
+ m_func = func;
+}
+
+void UDPFunction::processPendingDatagrams()
+{
+ while (m_udpSocket->hasPendingDatagrams())
+ {
+ QByteArray datagram;
+ datagram.resize(m_udpSocket->pendingDatagramSize());
+ QHostAddress sender;
+ quint16 senderPort;
+
+ m_udpSocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
+ QString msg = QString::fromUtf8(datagram);
+ if(m_func)
+ m_func(msg);
+ qDebug() << msg;
+ }
+}
+
+bool UDPFunction::SendMsg(const QString& msg,const QString& ip,uint16_t port){
+
+ QByteArray datagram = msg.toUtf8();
+ qint64 sentBytes = m_udpSocket->writeDatagram(datagram,QHostAddress(ip),port);
+ if(sentBytes < 0)
+ return false;
+ else
+ return true;
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpfunction.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpfunction.h
new file mode 100644
index 0000000000000000000000000000000000000000..787c1c256efe8fb0724cb1d3eafcc2106d842d89
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpfunction.h
@@ -0,0 +1,29 @@
+#ifndef UDPFUNCTION_H
+#define UDPFUNCTION_H
+
+#include
+#include
+
+using UDPProcess = std::function;
+
+class UDPFunction : public QObject
+{
+ Q_OBJECT
+
+public:
+ UDPFunction(QObject *parent = nullptr);
+
+ void setProcess(UDPProcess func);
+
+ bool SendMsg(const QString& msg,const QString& ip,uint16_t port);
+
+public slots:
+ void processPendingDatagrams();
+
+private:
+ QUdpSocket *m_udpSocket;
+ UDPProcess m_func;
+};
+
+
+#endif // UDPFUNCTION_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpglobal.cpp b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpglobal.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c52d56328b31d3fd060e0cd6c9f6d5b4230578ea
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpglobal.cpp
@@ -0,0 +1,6 @@
+#include "udpglobal.h"
+
+UDPGlobal::UDPGlobal()
+{
+
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpglobal.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpglobal.h
new file mode 100644
index 0000000000000000000000000000000000000000..a9dd5775561e72768305831faa2ba2bffb3934fa
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/udpglobal.h
@@ -0,0 +1,11 @@
+#ifndef UDPGLOBAL_H
+#define UDPGLOBAL_H
+
+
+class UDPGlobal
+{
+public:
+ UDPGlobal();
+};
+
+#endif // UDPGLOBAL_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/ui_iotui.h b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/ui_iotui.h
new file mode 100644
index 0000000000000000000000000000000000000000..2571167c191f292f84fc58892122931f76ec0243
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/Iot2023UI_WithCon/Iot2023/ui_iotui.h
@@ -0,0 +1,169 @@
+/********************************************************************************
+** Form generated from reading UI file 'iotui.ui'
+**
+** Created by: Qt User Interface Compiler version 5.12.12
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef UI_IOTUI_H
+#define UI_IOTUI_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+QT_BEGIN_NAMESPACE
+
+class Ui_IotUI
+{
+public:
+ QFrame *frame;
+ QWidget *verticalLayoutWidget;
+ QVBoxLayout *verticalLayout;
+ QWidget *widget;
+ QHBoxLayout *horizontalLayout_2;
+ QPushButton *pushButton_2;
+ QPushButton *pushButton_3;
+ QPushButton *pushButton_4;
+ QPushButton *pushButton_5;
+ QPushButton *pushButton;
+
+ void setupUi(QWidget *IotUI)
+ {
+ if (IotUI->objectName().isEmpty())
+ IotUI->setObjectName(QString::fromUtf8("IotUI"));
+ IotUI->resize(1220, 1020);
+ IotUI->setStyleSheet(QString::fromUtf8("*{\n"
+"background:rgb(255, 255, 255);\n"
+"font-size:15px;\n"
+"font-style:MingLiU-ExtB;\n"
+"}\n"
+"QWidget{\n"
+"border:sold 10px rgba(0,0,0);\n"
+"background:transparent;\n"
+"}\n"
+"#frame{\n"
+"border-radius:30;\n"
+"border:sold 10px rgba(0,0,0);\n"
+"background-color: #696969;\n"
+"}"));
+ frame = new QFrame(IotUI);
+ frame->setObjectName(QString::fromUtf8("frame"));
+ frame->setGeometry(QRect(10, 10, 1200, 1000));
+ frame->setFrameShape(QFrame::StyledPanel);
+ frame->setFrameShadow(QFrame::Raised);
+ verticalLayoutWidget = new QWidget(frame);
+ verticalLayoutWidget->setObjectName(QString::fromUtf8("verticalLayoutWidget"));
+ verticalLayoutWidget->setGeometry(QRect(20, 50, 1161, 931));
+ verticalLayout = new QVBoxLayout(verticalLayoutWidget);
+ verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
+ verticalLayout->setContentsMargins(0, 0, 0, 0);
+ widget = new QWidget(verticalLayoutWidget);
+ widget->setObjectName(QString::fromUtf8("widget"));
+ widget->setMinimumSize(QSize(660, 780));
+
+ verticalLayout->addWidget(widget);
+
+ horizontalLayout_2 = new QHBoxLayout();
+ horizontalLayout_2->setSpacing(100);
+ horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
+ horizontalLayout_2->setContentsMargins(50, -1, 50, -1);
+ pushButton_2 = new QPushButton(verticalLayoutWidget);
+ pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
+ QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
+ sizePolicy.setHorizontalStretch(0);
+ sizePolicy.setVerticalStretch(0);
+ sizePolicy.setHeightForWidth(pushButton_2->sizePolicy().hasHeightForWidth());
+ pushButton_2->setSizePolicy(sizePolicy);
+ pushButton_2->setMinimumSize(QSize(0, 40));
+ pushButton_2->setMaximumSize(QSize(40, 40));
+ pushButton_2->setStyleSheet(QString::fromUtf8("QPushButton {\n"
+" border-image: url(:/Image/Img/ad.png);\n"
+"}\n"
+"\n"
+"QPushButton:checked {\n"
+" border-image: url(:/Image/Img/ad_checked.png);\n"
+"}"));
+
+ horizontalLayout_2->addWidget(pushButton_2);
+
+ pushButton_3 = new QPushButton(verticalLayoutWidget);
+ pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
+ sizePolicy.setHeightForWidth(pushButton_3->sizePolicy().hasHeightForWidth());
+ pushButton_3->setSizePolicy(sizePolicy);
+ pushButton_3->setMaximumSize(QSize(40, 40));
+ pushButton_3->setStyleSheet(QString::fromUtf8("QPushButton {\n"
+" border-image: url(:/Image/Img/keshihua.png);\n"
+"}\n"
+"\n"
+"QPushButton:checked {\n"
+" border-image: url(:/Image/Img/keshihua_checked.png);\n"
+"}"));
+
+ horizontalLayout_2->addWidget(pushButton_3);
+
+ pushButton_4 = new QPushButton(verticalLayoutWidget);
+ pushButton_4->setObjectName(QString::fromUtf8("pushButton_4"));
+ sizePolicy.setHeightForWidth(pushButton_4->sizePolicy().hasHeightForWidth());
+ pushButton_4->setSizePolicy(sizePolicy);
+ pushButton_4->setMaximumSize(QSize(40, 40));
+ pushButton_4->setStyleSheet(QString::fromUtf8("QPushButton {\n"
+" border-image: url(:/Image/Img/lishijilu.png);\n"
+"}\n"
+"\n"
+"QPushButton:checked {\n"
+" border-image: url(:/Image/Img/lishijilu_checked.png);\n"
+"}"));
+
+ horizontalLayout_2->addWidget(pushButton_4);
+
+ pushButton_5 = new QPushButton(verticalLayoutWidget);
+ pushButton_5->setObjectName(QString::fromUtf8("pushButton_5"));
+ pushButton_5->setMaximumSize(QSize(40, 40));
+ pushButton_5->setStyleSheet(QString::fromUtf8("QPushButton {\n"
+" border-image: url(:/Image/Img/shezhi.png);\n"
+"}\n"
+"\n"
+"QPushButton:checked {\n"
+" border-image: url(:/Image/Img/shezhi_checked.png);\n"
+"}"));
+
+ horizontalLayout_2->addWidget(pushButton_5);
+
+
+ verticalLayout->addLayout(horizontalLayout_2);
+
+ pushButton = new QPushButton(frame);
+ pushButton->setObjectName(QString::fromUtf8("pushButton"));
+ pushButton->setGeometry(QRect(20, 10, 35, 35));
+ pushButton->setStyleSheet(QString::fromUtf8("border-image: url(:/Image/Img/exit.png);"));
+
+ retranslateUi(IotUI);
+
+ QMetaObject::connectSlotsByName(IotUI);
+ } // setupUi
+
+ void retranslateUi(QWidget *IotUI)
+ {
+ IotUI->setWindowTitle(QApplication::translate("IotUI", "IotUI", nullptr));
+ pushButton_2->setText(QString());
+ pushButton_3->setText(QString());
+ pushButton_4->setText(QString());
+ pushButton_5->setText(QString());
+ pushButton->setText(QString());
+ } // retranslateUi
+
+};
+
+namespace Ui {
+ class IotUI: public Ui_IotUI {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_IOTUI_H
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/ive_img.h b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/ive_img.h
new file mode 100644
index 0000000000000000000000000000000000000000..435193085db75a88fb3981174cee5e45d62c434f
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/ive_img.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IVE_IMG_H
+#define IVE_IMG_H
+
+#include
+#include
+
+#include "hi_common.h"
+#include "hi_comm_ive.h"
+#include "hi_comm_video.h"
+#include "hi_comm_venc.h"
+#include "hi_ive.h"
+#include "mpi_ive.h"
+#include "ai_infer_process.h"
+
+#if __cplusplus
+extern "C" {
+#endif
+
+/*
+ * 常量
+ * Constant
+ */
+#define IMG_FULL_CHN 3 // Full channel / three channel, for YUV444, RGB888
+#define IMG_HALF_CHN 2 // Half channel, for YUV420/422
+#define THREE_TIMES 3
+#define TWO_TIMES 2
+
+/*
+ * 字节对齐计算
+ * Byte alignment calculation
+ */
+HI_U32 HiAlign16(HI_U32 num);
+HI_U32 HiAlign32(HI_U32 num);
+
+/*
+ * 对齐类型
+ * Alignment type
+ */
+typedef enum AlignType {
+ ALIGN_TYPE_2 = 2, // Align by 2 bytes
+ ALIGN_TYPE_16 = 16, // Align by 16 bytes
+ ALIGN_TYPE_32 = 32, // Align by 32 bytes
+} AlignType;
+
+/*
+ * 根据类型和大小创建缓存
+ * Create ive image buffer based on type and size
+ */
+int IveImgCreate(IVE_IMAGE_S* img,
+ IVE_IMAGE_TYPE_E enType, uint32_t width, uint32_t height);
+
+/*
+ * VIDEO_FRAME_INFO_S格式转换成IVE_IMAGE_S格式
+ * 复制数据指针,不复制数据
+ *
+ * video frame to ive image.
+ * Copy the data pointer, do not copy the data.
+ */
+int FrmToOrigImg(const VIDEO_FRAME_INFO_S* frm, IVE_IMAGE_S *img);
+
+/*
+ * 对yuv格式进行裁剪
+ * yuv file crop
+ */
+int ImgYuvCrop(const IVE_IMAGE_S *src, IVE_IMAGE_S *dst, const RectBox* origBox);
+
+/*
+ * 销毁ive image
+ * Destory ive image
+ */
+void IveImgDestroy(IVE_IMAGE_S* img);
+
+int OrigImgToFrm(const IVE_IMAGE_S *img, VIDEO_FRAME_INFO_S* frm);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/osd_img.h b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/osd_img.h
new file mode 100644
index 0000000000000000000000000000000000000000..b406dfd9a80b84c24e0bec809344479157de86ad
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/osd_img.h
@@ -0,0 +1,287 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OSD_IMG_H
+#define OSD_IMG_H
+
+#include
+#include
+#include
+#include "hi_comm_region.h"
+#include "hi_common.h"
+
+#if __cplusplus
+extern "C" {
+#endif
+
+#define HI_OSD_MAX_CNT (33) // Maximum OSD Count
+#define HI_OSD_MAX_DISP_CNT (2) // Maximum Display Count for Each OSD
+#define HI_OSD_MAX_STR_LEN (64) // String OSD Maximum Length
+
+typedef HI_S32 HI_ERRNO;
+
+/*
+ * 常见的错误码
+ * Common error code
+ */
+#define HI_ERRNO_COMMON_BASE 0
+#define HI_ERRNO_COMMON_COUNT 256
+
+#define HI_EUNKNOWN (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 1)
+#define HI_EOTHER (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 2)
+#define HI_EINTER (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 3)
+#define HI_EVERSION (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 4)
+#define HI_EPAERM (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 5)
+#define HI_EINVAL (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 6)
+#define HI_ENOINIT (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 7)
+#define HI_ENOTREADY (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 8)
+#define HI_ENORES (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 9)
+#define HI_EEXIST (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 10)
+#define HI_ELOST (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 11)
+#define HI_ENOOP (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 12)
+#define HI_EBUSY (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 13)
+#define HI_EIDLE (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 14)
+#define HI_EFULL (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 15)
+#define HI_EEMPTY (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 16)
+#define HI_EUNDERFLOW (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 17)
+#define HI_EOVERFLOW (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 18)
+#define HI_EACCES (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 19)
+#define HI_EINTR (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 20)
+#define HI_ECONTINUE (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 21)
+#define HI_EOVER (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 22)
+#define HI_ERRNO_COMMON_BOTTOM (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 23)
+
+/*
+ * 自定义错误码
+ * Custom error code
+ */
+#define HI_ERRNO_BASE (HI_ERRNO)(HI_ERRNO_COMMON_BASE + HI_ERRNO_COMMON_COUNT)
+#define HI_EINITIALIZED (HI_ERRNO)(HI_ERRNO_BASE + 1) // Repeated initialization
+#define HI_ERRNO_CUSTOM_BOTTOM (HI_ERRNO)(HI_ERRNO_BASE + 2) // Number of error numbers that have been defined
+
+/*
+ * pthread互斥锁
+ * pthread mutex lock
+ */
+static inline void MutexLock(pthread_mutex_t* mutex)
+{
+ if (pthread_mutex_lock(mutex) != 0) {
+ HI_ASSERT(0);
+ }
+}
+
+/*
+ * 解除锁定mutex所指向的互斥锁
+ * pthread mutex unlock
+ */
+static inline void MutexUnlock(pthread_mutex_t* mutex)
+{
+ if (pthread_mutex_unlock(mutex) != 0) {
+ HI_ASSERT(0);
+ }
+}
+
+typedef HI_S32 (*HI_OSD_GETFONTMOD_CALLBACK_FN_PTR)(HI_CHAR* Character, HI_U8** FontMod, HI_S32* FontModLen);
+
+/*
+ * OSD字体库
+ * OSD Fonts Lib
+ */
+typedef struct hiOSD_FONTS_S {
+ /* OSD Lib Font Size, in pixel */
+ HI_U32 u32FontWidth;
+ HI_U32 u32FontHeight;
+ HI_OSD_GETFONTMOD_CALLBACK_FN_PTR pfnGetFontMod;
+} HI_OSD_FONTS_S;
+
+/*
+ * OSD像素格式枚举
+ * OSD pixel format enum
+ */
+typedef enum hiOSD_PIXEL_FMT_E {
+ HI_OSD_PIXEL_FMT_RGB1555 = 0,
+ HI_OSD_PIXEL_FMT_BUTT
+} HI_OSD_PIXEL_FMT_E;
+
+/*
+ * OSD位图属性
+ * OSD Bitmap Attribute
+ */
+typedef struct hiOSD_BITMAP_ATTR_S {
+ HI_OSD_PIXEL_FMT_E enPixelFormat;
+ HI_U32 u32Width;
+ HI_U32 u32Height;
+ HI_U64 u64PhyAddr;
+ HI_VOID* pvData;
+} HI_OSD_BITMAP_ATTR_S;
+
+/*
+ * OSD类型枚举
+ * OSD Type Enum
+ */
+typedef enum hiOSD_TYPE_E {
+ HI_OSD_TYPE_TIME = 0,
+ HI_OSD_TYPE_STRING,
+ HI_OSD_TYPE_BITMAP,
+ HI_OSD_TYPE_BUTT
+} HI_OSD_TYPE_E;
+
+/*
+ * OSD时间格式枚举
+ * OSD Time Format Enum
+ */
+typedef enum hiOSD_TIMEFMT_E {
+ HI_OSD_TIMEFMT_YMD24H = 0, // eg. 2017-03-10 23:00:59
+ HI_OSD_TIMEFMT_BUTT
+} HI_OSD_TIMEFMT_E;
+
+/*
+ * OSD绑定模块枚举
+ * OSD Binded Module enum
+ */
+typedef enum hiOSD_BIND_MOD_E {
+ HI_OSD_BINDMOD_VI = 0,
+ HI_OSD_BINDMOD_VPSS,
+ HI_OSD_BINDMOD_AVS,
+ HI_OSD_BINDMOD_VENC,
+ HI_OSD_BINDMOD_VO,
+ HI_OSD_BINDMOD_BUTT
+} HI_OSD_BIND_MOD_E;
+
+typedef enum hiOSD_COORDINATE_E {
+ HI_OSD_COORDINATE_RATIO_COOR = 0,
+ HI_OSD_COORDINATE_ABS_COOR
+} HI_OSD_COORDINATE_E;
+
+/*
+ * OSD显示属性
+ * OSD Display Attribute
+ */
+typedef struct hiOSD_DISP_ATTR_S {
+ HI_BOOL bShow;
+ HI_OSD_BIND_MOD_E enBindedMod;
+ HI_HANDLE ModHdl;
+ HI_HANDLE ChnHdl;
+ HI_U32 u32FgAlpha;
+ HI_U32 u32BgAlpha;
+ HI_OSD_COORDINATE_E enCoordinate; // Coordinate mode of the osd start Position
+ POINT_S stStartPos; // OSD Start Position
+ ATTACH_DEST_E enAttachDest; // only for venc
+ HI_S32 s32Batch;
+} HI_OSD_DISP_ATTR_S;
+
+/*
+ * OSD内容
+ * OSD Content
+ */
+typedef struct hiOSD_CONTENT_S {
+ HI_OSD_TYPE_E enType;
+ HI_OSD_TIMEFMT_E enTimeFmt;
+ HI_U32 u32Color; // string color
+ HI_U32 u32BgColor;
+ HI_CHAR szStr[HI_OSD_MAX_STR_LEN];
+ SIZE_S stFontSize;
+ HI_OSD_BITMAP_ATTR_S stBitmap; // Pixel Format: Only Support RGB1555 for now
+} HI_OSD_CONTENT_S;
+
+/*
+ * OSD属性
+ * OSD attribution
+ */
+typedef struct hiOSD_ATTR_S {
+ HI_U32 u32DispNum; /* 1Binded Display Number for this OSD */
+ HI_OSD_DISP_ATTR_S astDispAttr[HI_OSD_MAX_DISP_CNT];
+ HI_OSD_CONTENT_S stContent;
+} HI_OSD_ATTR_S;
+
+/*
+ * OSD参数
+ * OSD Parameter
+ */
+typedef struct tagOSD_PARAM_S {
+ HI_OSD_ATTR_S stAttr;
+ SIZE_S stMaxSize;
+ pthread_mutex_t mutexLock;
+ HI_BOOL bInit; /* OSD Attribute Set or not, Canbe modified only HI_OSD_SetAttr */
+ HI_BOOL bOn; /* OSD On/Off Flag, Canbe modified only by HI_OSD_Start/HI_OSD_Stop */
+} OSD_PARAM_S;
+
+typedef struct hiOSD_TEXTBITMAP_S {
+ RGN_HANDLE rgnHdl;
+ HI_OSD_CONTENT_S pstContent;
+ RGN_CANVAS_INFO_S stCanvasInfo;
+} HI_OSD_TEXTBITMAP_S;
+
+/*
+ * OSD区域设置
+ * OSD region set
+ */
+struct OsdSet {
+ // OSD Binded Module: Static
+ HI_OSD_BIND_MOD_E bindMod;
+ // Binded Module Handle: Static eg.VcapPipeHdl, VpssHdl, StitchHdl, DispHdl, 0
+ HI_U32 modHnd;
+ // Binded Channel Handle: Static eg.PipeChnHdl, VPortHdl, StitchPortHdl, WndHdl, VencHdl
+ HI_U32 chnHnd;
+};
+
+typedef struct OsdSet OsdSet;
+
+/*
+ * 在OsdSet中创建区域
+ * Create a region in OsdSet
+ */
+int OsdsCreateRgn(OsdSet* self);
+
+/*
+ * 设置文本区域的属性值
+ * Set the attribute value of the text region
+ */
+int TxtRgnInit(HI_OSD_ATTR_S* rgnAttr, const char* str, uint32_t begX, uint32_t begY, uint32_t color);
+
+/*
+ * 销毁OsdSet中的所有区域
+ * Destroy all regions in OsdSet
+ */
+void OsdsClear(OsdSet* self);
+
+/*
+ * 在OsdSet中设置指定区域的属性
+ * Set attributes for the specified region in OsdSet
+ */
+int OsdsSetRgn(OsdSet* self, int rgnHnd, const HI_OSD_ATTR_S* rgnAttr);
+
+/*
+ * 创建OsdSet
+ * Creat OsdSet
+ */
+OsdSet* OsdsCreate(HI_OSD_BIND_MOD_E bindMod, HI_U32 modHnd, HI_U32 chnHnd);
+
+/*
+ * 销毁OsdSet
+ * Destory OsdSet
+ */
+void OsdsDestroy(OsdSet* self);
+
+/*
+ * 初始化OsdSet库
+ * Initialize OsdSet lib
+ */
+int OsdLibInit(void);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/simsunb_16x32.txt b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/simsunb_16x32.txt
new file mode 100644
index 0000000000000000000000000000000000000000..b4ec6a390d997e9078000045dc33f4c0e18633b7
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/simsunb_16x32.txt
@@ -0,0 +1,380 @@
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x00 ,0x03 ,0x80 ,0x03 ,0x80 ,0x03 ,0x80 ,0x03 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,
+0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x80 ,0x03 ,0x80 ,
+0x03 ,0x80 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x06 ,0x70 ,0x06 ,0x70 ,0x06 ,0x70 ,0x06 ,0x60 ,0x06 ,0x60 ,0x06 ,0x60 ,0x06 ,0x60 ,
+0x06 ,0x20 ,0x04 ,0x40 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x04 ,0x18 ,0x0c ,0x18 ,0x0c ,0x10 ,0x08 ,0x10 ,
+0x08 ,0x10 ,0x7f ,0xfe ,0x7f ,0xfe ,0x08 ,0x10 ,0x08 ,0x10 ,0x08 ,0x10 ,0x08 ,0x10 ,0x08 ,0x10 ,
+0x08 ,0x30 ,0x08 ,0x30 ,0x7f ,0xfe ,0x7f ,0xfe ,0x10 ,0x20 ,0x10 ,0x20 ,0x10 ,0x20 ,0x10 ,0x20 ,
+0x10 ,0x20 ,0x10 ,0x20 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x80 ,0x01 ,0x80 ,0x07 ,0xe0 ,0x0d ,0xb0 ,0x19 ,0x98 ,0x19 ,0x98 ,
+0x19 ,0xb8 ,0x19 ,0xb0 ,0x19 ,0x80 ,0x1d ,0x80 ,0x0f ,0x80 ,0x07 ,0x80 ,0x01 ,0xc0 ,0x01 ,0xe0 ,
+0x01 ,0xf0 ,0x01 ,0xb8 ,0x01 ,0x98 ,0x19 ,0x98 ,0x39 ,0x98 ,0x39 ,0x98 ,0x31 ,0x98 ,0x11 ,0x90 ,
+0x0d ,0xe0 ,0x03 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x38 ,0x10 ,0x44 ,0x10 ,0x46 ,0x20 ,0xc6 ,0x20 ,
+0xc6 ,0x20 ,0xc6 ,0x40 ,0xc6 ,0x40 ,0xc6 ,0x80 ,0x46 ,0x80 ,0x44 ,0x80 ,0x3d ,0x18 ,0x01 ,0x64 ,
+0x02 ,0x46 ,0x02 ,0x46 ,0x04 ,0xc6 ,0x04 ,0xc6 ,0x04 ,0xc6 ,0x08 ,0xc6 ,0x08 ,0x46 ,0x10 ,0x46 ,
+0x10 ,0x2c ,0x10 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x0f ,0x80 ,0x18 ,0x80 ,0x10 ,0xc0 ,0x10 ,0xc0 ,
+0x10 ,0xc0 ,0x10 ,0x80 ,0x19 ,0x80 ,0x19 ,0x00 ,0x1a ,0x00 ,0x1c ,0x7c ,0x1c ,0x18 ,0x2c ,0x10 ,
+0x66 ,0x10 ,0x46 ,0x10 ,0xc7 ,0x20 ,0xc3 ,0x20 ,0xc1 ,0xa0 ,0xc1 ,0xc0 ,0x60 ,0xe0 ,0x70 ,0xf2 ,
+0x3f ,0x3e ,0x0c ,0x18 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x03 ,0x00 ,0x03 ,0x80 ,0x03 ,0x00 ,0x03 ,0x00 ,0x03 ,0x00 ,0x03 ,0x00 ,0x03 ,0x00 ,0x02 ,0x00 ,
+0x02 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x04 ,0x00 ,0x0c ,0x00 ,0x18 ,0x00 ,0x10 ,0x00 ,0x20 ,0x00 ,0x60 ,0x00 ,0x40 ,0x00 ,0xc0 ,
+0x00 ,0xc0 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x00 ,0x80 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0x40 ,0x00 ,0x60 ,
+0x00 ,0x30 ,0x00 ,0x10 ,0x00 ,0x08 ,0x00 ,0x04 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x40 ,0x00 ,0x20 ,0x00 ,0x10 ,0x00 ,0x18 ,0x00 ,0x0c ,0x00 ,0x04 ,0x00 ,0x06 ,0x00 ,0x02 ,0x00 ,
+0x03 ,0x00 ,0x03 ,0x00 ,0x01 ,0x00 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x00 ,0x03 ,0x00 ,0x03 ,0x00 ,0x02 ,0x00 ,0x06 ,0x00 ,0x04 ,0x00 ,
+0x0c ,0x00 ,0x18 ,0x00 ,0x10 ,0x00 ,0x20 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x79 ,0x8e ,0x3d ,0xbe ,0x1e ,0xf0 ,0x01 ,0x80 ,0x03 ,0xc0 ,
+0x06 ,0x70 ,0x0c ,0x38 ,0x1c ,0x1c ,0x38 ,0x0c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x7f ,0xfe ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x1c ,0x00 ,0x1e ,0x00 ,
+0x0e ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,0x0c ,0x00 ,0x18 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7f ,0xfe ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x18 ,0x00 ,0x3c ,0x00 ,
+0x3c ,0x00 ,0x18 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x02 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x08 ,0x00 ,0x08 ,0x00 ,0x10 ,0x00 ,0x10 ,
+0x00 ,0x20 ,0x00 ,0x20 ,0x00 ,0x40 ,0x00 ,0x40 ,0x00 ,0x80 ,0x00 ,0x80 ,0x01 ,0x00 ,0x01 ,0x00 ,
+0x02 ,0x00 ,0x02 ,0x00 ,0x06 ,0x00 ,0x04 ,0x00 ,0x0c ,0x00 ,0x08 ,0x00 ,0x18 ,0x00 ,0x10 ,0x00 ,
+0x10 ,0x00 ,0x20 ,0x00 ,0x20 ,0x00 ,0x40 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x07 ,0xc0 ,0x0c ,0x30 ,0x18 ,0x30 ,0x18 ,0x18 ,
+0x38 ,0x18 ,0x30 ,0x1c ,0x30 ,0x0c ,0x30 ,0x0c ,0x70 ,0x0c ,0x70 ,0x0c ,0x70 ,0x0c ,0x70 ,0x0c ,
+0x70 ,0x0c ,0x30 ,0x0c ,0x30 ,0x0c ,0x30 ,0x1c ,0x30 ,0x18 ,0x18 ,0x18 ,0x18 ,0x18 ,0x0c ,0x30 ,
+0x06 ,0x60 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x80 ,0x03 ,0x80 ,0x07 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x07 ,0xf0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x07 ,0xe0 ,0x18 ,0x30 ,0x10 ,0x18 ,0x30 ,0x18 ,
+0x30 ,0x1c ,0x38 ,0x1c ,0x38 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x30 ,0x00 ,0x60 ,0x00 ,0x40 ,
+0x00 ,0x80 ,0x01 ,0x00 ,0x02 ,0x00 ,0x04 ,0x00 ,0x08 ,0x04 ,0x10 ,0x04 ,0x30 ,0x0c ,0x20 ,0x38 ,
+0x3f ,0xf8 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x0f ,0xc0 ,0x18 ,0x30 ,0x30 ,0x30 ,0x30 ,0x18 ,
+0x38 ,0x18 ,0x10 ,0x18 ,0x00 ,0x18 ,0x00 ,0x30 ,0x00 ,0x60 ,0x03 ,0xc0 ,0x01 ,0xe0 ,0x00 ,0x30 ,
+0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x0c ,0x00 ,0x0c ,0x30 ,0x0c ,0x38 ,0x1c ,0x30 ,0x18 ,0x30 ,0x30 ,
+0x0c ,0x60 ,0x03 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x20 ,0x00 ,0x60 ,0x00 ,0xe0 ,0x00 ,0xe0 ,
+0x01 ,0x60 ,0x03 ,0x60 ,0x02 ,0x60 ,0x04 ,0x60 ,0x04 ,0x60 ,0x08 ,0x60 ,0x10 ,0x60 ,0x10 ,0x60 ,
+0x20 ,0x60 ,0x60 ,0x60 ,0x7f ,0xfe ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,
+0x01 ,0xfc ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x1f ,0xf8 ,0x1f ,0xf8 ,0x10 ,0x00 ,0x10 ,0x00 ,
+0x10 ,0x00 ,0x10 ,0x00 ,0x10 ,0x00 ,0x10 ,0x00 ,0x17 ,0xe0 ,0x18 ,0x30 ,0x10 ,0x18 ,0x00 ,0x18 ,
+0x00 ,0x0c ,0x00 ,0x0c ,0x00 ,0x0c ,0x10 ,0x0c ,0x38 ,0x0c ,0x30 ,0x18 ,0x30 ,0x18 ,0x10 ,0x30 ,
+0x0c ,0x60 ,0x03 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0xf0 ,0x04 ,0x18 ,0x08 ,0x18 ,0x18 ,0x18 ,
+0x10 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x33 ,0xf0 ,0x74 ,0x38 ,0x78 ,0x18 ,0x70 ,0x0c ,
+0x70 ,0x0c ,0x70 ,0x0c ,0x30 ,0x0c ,0x30 ,0x0c ,0x30 ,0x0c ,0x30 ,0x0c ,0x18 ,0x08 ,0x1c ,0x18 ,
+0x0e ,0x70 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x1f ,0xfc ,0x3f ,0xfc ,0x30 ,0x08 ,0x20 ,0x10 ,
+0x20 ,0x10 ,0x00 ,0x20 ,0x00 ,0x20 ,0x00 ,0x60 ,0x00 ,0x40 ,0x00 ,0xc0 ,0x00 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x03 ,0x00 ,0x03 ,0x00 ,0x03 ,0x00 ,0x03 ,0x00 ,0x03 ,0x00 ,0x07 ,0x00 ,
+0x03 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x0f ,0xe0 ,0x18 ,0x10 ,0x30 ,0x18 ,0x30 ,0x0c ,
+0x30 ,0x0c ,0x30 ,0x0c ,0x30 ,0x08 ,0x38 ,0x18 ,0x1e ,0x30 ,0x0f ,0xe0 ,0x07 ,0xe0 ,0x18 ,0xf0 ,
+0x30 ,0x38 ,0x30 ,0x18 ,0x60 ,0x0c ,0x60 ,0x0c ,0x60 ,0x0c ,0x60 ,0x0c ,0x30 ,0x08 ,0x10 ,0x18 ,
+0x0c ,0x70 ,0x03 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x0f ,0xc0 ,0x18 ,0x30 ,0x30 ,0x18 ,0x30 ,0x18 ,
+0x70 ,0x18 ,0x60 ,0x0c ,0x60 ,0x0c ,0x60 ,0x0c ,0x70 ,0x0c ,0x30 ,0x1c ,0x30 ,0x2c ,0x38 ,0x6c ,
+0x0f ,0xcc ,0x00 ,0x1c ,0x00 ,0x1c ,0x00 ,0x18 ,0x00 ,0x18 ,0x10 ,0x30 ,0x38 ,0x30 ,0x38 ,0x60 ,
+0x18 ,0xc0 ,0x07 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0x80 ,0x03 ,0x80 ,0x03 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x80 ,0x03 ,0x80 ,
+0x03 ,0x80 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0x80 ,0x03 ,0x80 ,0x03 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0x80 ,
+0x03 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x00 ,0x03 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x08 ,0x00 ,0x10 ,0x00 ,0x20 ,0x00 ,0x40 ,
+0x00 ,0x80 ,0x01 ,0x00 ,0x02 ,0x00 ,0x04 ,0x00 ,0x08 ,0x00 ,0x10 ,0x00 ,0x30 ,0x00 ,0x18 ,0x00 ,
+0x0c ,0x00 ,0x06 ,0x00 ,0x03 ,0x00 ,0x01 ,0x80 ,0x00 ,0xc0 ,0x00 ,0x60 ,0x00 ,0x30 ,0x00 ,0x18 ,
+0x00 ,0x0c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7f ,0xfe ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x7f ,0xfe ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x20 ,0x00 ,0x30 ,0x00 ,0x18 ,0x00 ,0x0c ,0x00 ,0x06 ,0x00 ,
+0x03 ,0x00 ,0x01 ,0x80 ,0x00 ,0xc0 ,0x00 ,0x60 ,0x00 ,0x30 ,0x00 ,0x18 ,0x00 ,0x0c ,0x00 ,0x18 ,
+0x00 ,0x30 ,0x00 ,0x60 ,0x00 ,0xc0 ,0x01 ,0x80 ,0x03 ,0x00 ,0x06 ,0x00 ,0x0c ,0x00 ,0x18 ,0x00 ,
+0x30 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x80 ,0x0f ,0xf0 ,0x10 ,0x18 ,0x30 ,0x1c ,0x20 ,0x0c ,
+0x20 ,0x0c ,0x30 ,0x0c ,0x38 ,0x0c ,0x10 ,0x1c ,0x00 ,0x18 ,0x00 ,0x30 ,0x00 ,0xe0 ,0x01 ,0x80 ,
+0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x80 ,0x03 ,0x80 ,
+0x03 ,0x80 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0xf0 ,0x0c ,0x18 ,0x08 ,0x04 ,0x10 ,0x04 ,
+0x30 ,0xf2 ,0x21 ,0x12 ,0x23 ,0x32 ,0x62 ,0x32 ,0x66 ,0x32 ,0x66 ,0x32 ,0x64 ,0x22 ,0x64 ,0x22 ,
+0x64 ,0x22 ,0x64 ,0x64 ,0x64 ,0x64 ,0x26 ,0xb8 ,0x33 ,0x10 ,0x10 ,0x02 ,0x18 ,0x04 ,0x08 ,0x08 ,
+0x06 ,0x70 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x80 ,0x03 ,0x80 ,0x03 ,0x80 ,0x02 ,0xc0 ,
+0x02 ,0xc0 ,0x04 ,0xc0 ,0x04 ,0xc0 ,0x04 ,0x60 ,0x04 ,0x60 ,0x08 ,0x60 ,0x08 ,0x60 ,0x08 ,0x30 ,
+0x08 ,0x30 ,0x17 ,0xf0 ,0x10 ,0x30 ,0x10 ,0x30 ,0x10 ,0x18 ,0x20 ,0x18 ,0x20 ,0x18 ,0x20 ,0x18 ,
+0x70 ,0x3e ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7f ,0xe0 ,0x38 ,0x38 ,0x38 ,0x18 ,0x38 ,0x1c ,
+0x38 ,0x0c ,0x38 ,0x0c ,0x38 ,0x1c ,0x38 ,0x18 ,0x38 ,0x30 ,0x3f ,0xc0 ,0x38 ,0x70 ,0x38 ,0x18 ,
+0x38 ,0x0c ,0x38 ,0x0c ,0x38 ,0x0e ,0x38 ,0x0e ,0x38 ,0x0e ,0x38 ,0x0e ,0x38 ,0x0c ,0x38 ,0x18 ,
+0x7f ,0xf0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0xfc ,0x0c ,0x0c ,0x18 ,0x04 ,0x18 ,0x04 ,
+0x30 ,0x02 ,0x30 ,0x00 ,0x70 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,
+0x60 ,0x00 ,0x60 ,0x00 ,0x70 ,0x00 ,0x70 ,0x02 ,0x30 ,0x02 ,0x30 ,0x04 ,0x18 ,0x04 ,0x1c ,0x08 ,
+0x07 ,0xf0 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7f ,0x80 ,0x38 ,0x60 ,0x38 ,0x30 ,0x38 ,0x18 ,
+0x38 ,0x0c ,0x38 ,0x0c ,0x38 ,0x0c ,0x38 ,0x0e ,0x38 ,0x0e ,0x38 ,0x0e ,0x38 ,0x0e ,0x38 ,0x0e ,
+0x38 ,0x0e ,0x38 ,0x0e ,0x38 ,0x0c ,0x38 ,0x0c ,0x38 ,0x0c ,0x38 ,0x18 ,0x38 ,0x18 ,0x38 ,0x70 ,
+0x3f ,0xc0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7f ,0xf8 ,0x18 ,0x1c ,0x18 ,0x04 ,0x18 ,0x04 ,
+0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x20 ,0x18 ,0x20 ,0x1f ,0xe0 ,0x18 ,0x60 ,0x18 ,0x20 ,
+0x18 ,0x20 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x02 ,0x18 ,0x02 ,0x18 ,0x04 ,0x18 ,0x0c ,
+0x7f ,0xfc ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7f ,0xfc ,0x18 ,0x0c ,0x18 ,0x06 ,0x18 ,0x02 ,
+0x18 ,0x02 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x30 ,0x1f ,0xf0 ,0x18 ,0x10 ,
+0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,
+0x7c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x07 ,0xf8 ,0x0c ,0x38 ,0x18 ,0x18 ,0x10 ,0x08 ,
+0x30 ,0x08 ,0x30 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,
+0x60 ,0x7e ,0x60 ,0x18 ,0x60 ,0x18 ,0x70 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x18 ,0x18 ,0x18 ,0x18 ,
+0x0e ,0x20 ,0x01 ,0xc0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xfc ,0x3e ,0x30 ,0x1c ,0x30 ,0x1c ,0x30 ,0x1c ,
+0x30 ,0x1c ,0x30 ,0x1c ,0x30 ,0x1c ,0x30 ,0x1c ,0x30 ,0x1c ,0x30 ,0x1c ,0x3f ,0xfc ,0x30 ,0x1c ,
+0x30 ,0x1c ,0x30 ,0x1c ,0x30 ,0x1c ,0x30 ,0x1c ,0x30 ,0x1c ,0x30 ,0x1c ,0x30 ,0x1c ,0x30 ,0x1c ,
+0x78 ,0x3e ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x1f ,0xf8 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x1f ,0xf0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x07 ,0xfe ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,
+0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,
+0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x30 ,0x40 ,0x30 ,0xc0 ,
+0x3f ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7c ,0x7e ,0x38 ,0x18 ,0x38 ,0x30 ,0x38 ,0x20 ,
+0x38 ,0x40 ,0x38 ,0x80 ,0x38 ,0x80 ,0x39 ,0x00 ,0x3b ,0x00 ,0x3f ,0x80 ,0x3d ,0x80 ,0x39 ,0x80 ,
+0x38 ,0xc0 ,0x38 ,0xc0 ,0x38 ,0x60 ,0x38 ,0x60 ,0x38 ,0x30 ,0x38 ,0x30 ,0x38 ,0x18 ,0x38 ,0x18 ,
+0x7c ,0x3e ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7e ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,
+0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,
+0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x02 ,0x18 ,0x02 ,0x18 ,0x04 ,0x18 ,0x0c ,
+0x7f ,0xfc ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf0 ,0x1f ,0x30 ,0x1c ,0x30 ,0x1c ,0x38 ,0x1c ,
+0x38 ,0x2c ,0x38 ,0x2c ,0x38 ,0x2c ,0x28 ,0x2c ,0x2c ,0x4c ,0x2c ,0x4c ,0x2c ,0x4c ,0x2c ,0x4c ,
+0x24 ,0x8c ,0x26 ,0x8c ,0x26 ,0x8c ,0x26 ,0x8c ,0x22 ,0x8c ,0x23 ,0x0c ,0x23 ,0x0c ,0x23 ,0x0c ,
+0x73 ,0x1e ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf0 ,0x1f ,0x38 ,0x04 ,0x38 ,0x04 ,0x2c ,0x04 ,
+0x2c ,0x04 ,0x26 ,0x04 ,0x26 ,0x04 ,0x23 ,0x04 ,0x23 ,0x04 ,0x21 ,0x84 ,0x21 ,0x84 ,0x20 ,0xc4 ,
+0x20 ,0xc4 ,0x20 ,0x64 ,0x20 ,0x74 ,0x20 ,0x34 ,0x20 ,0x3c ,0x20 ,0x1c ,0x20 ,0x1c ,0x20 ,0x0c ,
+0x78 ,0x0c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x07 ,0xe0 ,0x0c ,0x30 ,0x18 ,0x18 ,0x30 ,0x08 ,
+0x30 ,0x0c ,0x30 ,0x0c ,0x70 ,0x0e ,0x70 ,0x0e ,0x60 ,0x06 ,0x60 ,0x06 ,0x60 ,0x06 ,0x60 ,0x06 ,
+0x60 ,0x06 ,0x60 ,0x06 ,0x70 ,0x0e ,0x30 ,0x0c ,0x30 ,0x0c ,0x30 ,0x0c ,0x18 ,0x18 ,0x08 ,0x10 ,
+0x06 ,0x60 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7f ,0xe0 ,0x18 ,0x18 ,0x18 ,0x0c ,0x18 ,0x0c ,
+0x18 ,0x0e ,0x18 ,0x0e ,0x18 ,0x0e ,0x18 ,0x0c ,0x18 ,0x0c ,0x18 ,0x18 ,0x18 ,0x70 ,0x1f ,0x80 ,
+0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,
+0x7c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x07 ,0xe0 ,0x0c ,0x30 ,0x18 ,0x18 ,0x30 ,0x08 ,
+0x30 ,0x0c ,0x30 ,0x0c ,0x70 ,0x0c ,0x60 ,0x0e ,0x60 ,0x0e ,0x60 ,0x0e ,0x60 ,0x0e ,0x60 ,0x0e ,
+0x60 ,0x0e ,0x60 ,0x0e ,0x60 ,0x0e ,0x77 ,0x8c ,0x3d ,0xcc ,0x38 ,0xcc ,0x18 ,0x58 ,0x18 ,0x70 ,
+0x06 ,0x60 ,0x01 ,0xf0 ,0x00 ,0x3c ,0x00 ,0x3c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7f ,0xe0 ,0x18 ,0x38 ,0x18 ,0x18 ,0x18 ,0x0c ,
+0x18 ,0x0c ,0x18 ,0x0c ,0x18 ,0x0c ,0x18 ,0x1c ,0x18 ,0x18 ,0x18 ,0x70 ,0x1f ,0xc0 ,0x18 ,0xc0 ,
+0x18 ,0xc0 ,0x18 ,0x60 ,0x18 ,0x60 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x18 ,0x18 ,0x18 ,
+0x7c ,0x1e ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x0f ,0xe8 ,0x10 ,0x38 ,0x30 ,0x18 ,0x20 ,0x08 ,
+0x20 ,0x08 ,0x20 ,0x00 ,0x30 ,0x00 ,0x38 ,0x00 ,0x1c ,0x00 ,0x0f ,0x80 ,0x03 ,0xe0 ,0x00 ,0xf0 ,
+0x00 ,0x38 ,0x00 ,0x18 ,0x00 ,0x0c ,0x40 ,0x0c ,0x40 ,0x0c ,0x20 ,0x0c ,0x20 ,0x08 ,0x30 ,0x18 ,
+0x3c ,0x70 ,0x03 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x3f ,0xfc ,0x21 ,0x8c ,0x61 ,0x84 ,0x41 ,0x84 ,
+0x41 ,0x82 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x07 ,0xe0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xfc ,0x1e ,0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,
+0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,
+0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,0x30 ,0x08 ,0x18 ,0x10 ,
+0x0e ,0x60 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xfc ,0x3e ,0x30 ,0x08 ,0x30 ,0x08 ,0x18 ,0x08 ,
+0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x0c ,0x10 ,0x0c ,0x20 ,0x0c ,0x20 ,0x0c ,0x20 ,0x06 ,0x40 ,
+0x06 ,0x40 ,0x06 ,0x40 ,0x06 ,0x40 ,0x03 ,0x80 ,0x03 ,0x80 ,0x03 ,0x80 ,0x03 ,0x80 ,0x01 ,0x00 ,
+0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xfb ,0xcf ,0x61 ,0x84 ,0x61 ,0x84 ,0x21 ,0x84 ,
+0x31 ,0x84 ,0x31 ,0x84 ,0x31 ,0xc8 ,0x31 ,0xc8 ,0x31 ,0xc8 ,0x12 ,0xc8 ,0x12 ,0xc8 ,0x1a ,0x50 ,
+0x1a ,0x50 ,0x1a ,0x70 ,0x1c ,0x70 ,0x1c ,0x70 ,0x0c ,0x70 ,0x0c ,0x60 ,0x0c ,0x20 ,0x0c ,0x20 ,
+0x08 ,0x20 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7c ,0x3e ,0x18 ,0x18 ,0x18 ,0x10 ,0x0c ,0x10 ,
+0x0c ,0x20 ,0x06 ,0x20 ,0x06 ,0x40 ,0x02 ,0x40 ,0x03 ,0x80 ,0x03 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x02 ,0xc0 ,0x02 ,0xc0 ,0x04 ,0x60 ,0x04 ,0x60 ,0x0c ,0x30 ,0x08 ,0x30 ,0x08 ,0x18 ,0x10 ,0x18 ,
+0x78 ,0x3e ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7c ,0x3e ,0x30 ,0x08 ,0x18 ,0x08 ,0x18 ,0x10 ,
+0x18 ,0x10 ,0x0c ,0x20 ,0x0c ,0x20 ,0x06 ,0x20 ,0x06 ,0x40 ,0x06 ,0x40 ,0x03 ,0x40 ,0x03 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x07 ,0xe0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x1f ,0xfc ,0x18 ,0x0c ,0x30 ,0x18 ,0x20 ,0x18 ,
+0x00 ,0x30 ,0x00 ,0x70 ,0x00 ,0x60 ,0x00 ,0xe0 ,0x00 ,0xc0 ,0x01 ,0x80 ,0x01 ,0x80 ,0x03 ,0x00 ,
+0x03 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,0x0c ,0x00 ,0x0c ,0x00 ,0x18 ,0x04 ,0x18 ,0x04 ,0x30 ,0x0c ,
+0x7f ,0xf8 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x03 ,0xfc ,0x03 ,0xfc ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,
+0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,
+0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,
+0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x03 ,0xfc ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x10 ,0x00 ,0x10 ,0x00 ,0x18 ,0x00 ,0x08 ,0x00 ,0x0c ,0x00 ,
+0x04 ,0x00 ,0x04 ,0x00 ,0x06 ,0x00 ,0x02 ,0x00 ,0x03 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x80 ,
+0x00 ,0x80 ,0x00 ,0xc0 ,0x00 ,0x40 ,0x00 ,0x40 ,0x00 ,0x60 ,0x00 ,0x20 ,0x00 ,0x30 ,0x00 ,0x10 ,
+0x00 ,0x10 ,0x00 ,0x18 ,0x00 ,0x08 ,0x00 ,0x0c ,0x00 ,0x04 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x3f ,0xc0 ,0x3f ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,
+0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,
+0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,
+0x00 ,0xc0 ,0x00 ,0xc0 ,0x00 ,0xc0 ,0x3f ,0xc0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x03 ,0xc0 ,0x06 ,0xe0 ,0x0c ,0x20 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xff ,0xff ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x1e ,0x00 ,0x07 ,0x00 ,0x01 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x07 ,0xc0 ,0x18 ,0x30 ,0x30 ,0x10 ,0x30 ,0x18 ,0x00 ,0x18 ,
+0x00 ,0x78 ,0x07 ,0x98 ,0x18 ,0x18 ,0x30 ,0x18 ,0x70 ,0x18 ,0x60 ,0x18 ,0x60 ,0x18 ,0x30 ,0x3a ,
+0x1f ,0xde ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x10 ,0x00 ,0x70 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,
+0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x31 ,0xc0 ,0x32 ,0x30 ,0x34 ,0x18 ,0x38 ,0x0c ,0x38 ,0x0c ,
+0x30 ,0x0c ,0x30 ,0x0c ,0x30 ,0x0c ,0x30 ,0x0c ,0x30 ,0x0c ,0x30 ,0x0c ,0x30 ,0x18 ,0x38 ,0x18 ,
+0x37 ,0xf0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0xe0 ,0x0c ,0x30 ,0x18 ,0x18 ,0x18 ,0x18 ,0x30 ,0x18 ,
+0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x04 ,0x18 ,0x08 ,0x18 ,0x08 ,
+0x0f ,0x70 ,0x00 ,0xc0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x08 ,0x00 ,0x78 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,
+0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x03 ,0x98 ,0x0e ,0x78 ,0x18 ,0x18 ,0x18 ,0x18 ,0x30 ,0x18 ,
+0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x10 ,0x18 ,0x18 ,0x38 ,
+0x0f ,0xde ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0xc0 ,0x0c ,0x30 ,0x18 ,0x18 ,0x10 ,0x18 ,0x30 ,0x0c ,
+0x30 ,0x0c ,0x30 ,0x0c ,0x3f ,0xf0 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x18 ,0x08 ,0x18 ,0x08 ,
+0x07 ,0x70 ,0x00 ,0xc0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf8 ,0x01 ,0x06 ,0x03 ,0x06 ,0x02 ,0x04 ,
+0x02 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,0x3f ,0xf8 ,0x06 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,
+0x06 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,
+0x1f ,0xe0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0x8e ,0x0c ,0x76 ,0x18 ,0x30 ,0x10 ,0x10 ,0x10 ,0x10 ,
+0x10 ,0x10 ,0x18 ,0x10 ,0x08 ,0x30 ,0x0e ,0xe0 ,0x11 ,0x00 ,0x10 ,0x00 ,0x1f ,0x80 ,0x0f ,0xf8 ,
+0x10 ,0x3c ,0x20 ,0x0c ,0x20 ,0x0c ,0x20 ,0x0c ,0x10 ,0x18 ,0x0f ,0xf0 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x10 ,0x00 ,0x70 ,0x00 ,0x10 ,0x00 ,0x10 ,0x00 ,0x10 ,0x00 ,
+0x10 ,0x00 ,0x10 ,0x00 ,0x10 ,0x00 ,0x11 ,0xe0 ,0x17 ,0x30 ,0x1c ,0x18 ,0x18 ,0x18 ,0x10 ,0x18 ,
+0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,
+0x7c ,0x3c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x80 ,0x03 ,0xc0 ,0x01 ,0x80 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x80 ,0x1f ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x0f ,0xf0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x38 ,0x00 ,0x38 ,0x00 ,0x30 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0xf0 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,
+0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,
+0x00 ,0x30 ,0x00 ,0x30 ,0x00 ,0x30 ,0x38 ,0x20 ,0x18 ,0x60 ,0x0f ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x08 ,0x00 ,0x78 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,
+0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x7c ,0x18 ,0x30 ,0x18 ,0x60 ,0x18 ,0x40 ,0x18 ,0x80 ,
+0x19 ,0x00 ,0x1b ,0x80 ,0x1c ,0xc0 ,0x18 ,0xc0 ,0x18 ,0x60 ,0x18 ,0x70 ,0x18 ,0x30 ,0x18 ,0x18 ,
+0x7c ,0x3c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x80 ,0x1f ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x1f ,0xf0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xe7 ,0x38 ,0x69 ,0xcc ,0x71 ,0x84 ,0x61 ,0x86 ,0x61 ,0x86 ,
+0x61 ,0x86 ,0x61 ,0x86 ,0x61 ,0x86 ,0x61 ,0x86 ,0x61 ,0x86 ,0x61 ,0x86 ,0x61 ,0x86 ,0x61 ,0x86 ,
+0x73 ,0xce ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x71 ,0xe0 ,0x12 ,0x30 ,0x1c ,0x18 ,0x18 ,0x18 ,0x10 ,0x18 ,
+0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,
+0x7c ,0x3c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0xc0 ,0x0c ,0x30 ,0x18 ,0x18 ,0x30 ,0x08 ,0x30 ,0x0c ,
+0x30 ,0x0c ,0x60 ,0x0c ,0x60 ,0x0c ,0x60 ,0x0c ,0x30 ,0x0c ,0x30 ,0x0c ,0x30 ,0x08 ,0x18 ,0x18 ,
+0x0c ,0x20 ,0x03 ,0xc0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x71 ,0xc0 ,0x36 ,0x30 ,0x14 ,0x18 ,0x18 ,0x0c ,0x10 ,0x0c ,
+0x10 ,0x0c ,0x10 ,0x0c ,0x10 ,0x0c ,0x10 ,0x0c ,0x10 ,0x0c ,0x10 ,0x0c ,0x18 ,0x18 ,0x18 ,0x18 ,
+0x16 ,0x70 ,0x11 ,0x80 ,0x10 ,0x00 ,0x10 ,0x00 ,0x10 ,0x00 ,0x7e ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0x88 ,0x0c ,0x68 ,0x18 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,
+0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x18 ,0x38 ,
+0x0f ,0xd8 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x18 ,0x00 ,0x7e ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7c ,0x38 ,0x0c ,0x4c ,0x0c ,0x8c ,0x0d ,0x00 ,0x0e ,0x00 ,
+0x0c ,0x00 ,0x0c ,0x00 ,0x0c ,0x00 ,0x0c ,0x00 ,0x0c ,0x00 ,0x0c ,0x00 ,0x0c ,0x00 ,0x0c ,0x00 ,
+0x7f ,0xc0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0xc8 ,0x0c ,0x38 ,0x18 ,0x18 ,0x18 ,0x08 ,0x18 ,0x00 ,
+0x1c ,0x00 ,0x0f ,0x80 ,0x01 ,0xe0 ,0x00 ,0x78 ,0x00 ,0x18 ,0x10 ,0x0c ,0x10 ,0x08 ,0x18 ,0x08 ,
+0x1f ,0xf0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x00 ,
+0x02 ,0x00 ,0x02 ,0x00 ,0x06 ,0x00 ,0x3f ,0xf0 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,
+0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x00 ,0x02 ,0x04 ,0x02 ,0x08 ,0x03 ,0x08 ,
+0x01 ,0xf0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x70 ,0x78 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,
+0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x30 ,0x18 ,0x10 ,0x18 ,0x10 ,0x18 ,0x18 ,0x38 ,
+0x0f ,0xde ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7c ,0x3e ,0x18 ,0x18 ,0x18 ,0x10 ,0x18 ,0x10 ,0x0c ,0x10 ,
+0x0c ,0x20 ,0x0c ,0x20 ,0x06 ,0x20 ,0x06 ,0x40 ,0x02 ,0x40 ,0x03 ,0x80 ,0x03 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xfb ,0xdf ,0x61 ,0x84 ,0x21 ,0x84 ,0x31 ,0x84 ,0x31 ,0x88 ,
+0x31 ,0xc8 ,0x12 ,0xc8 ,0x12 ,0xc8 ,0x1a ,0x50 ,0x1a ,0x50 ,0x0c ,0x70 ,0x0c ,0x70 ,0x0c ,0x20 ,
+0x0c ,0x20 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x3e ,0x7c ,0x1c ,0x10 ,0x0c ,0x30 ,0x06 ,0x20 ,0x06 ,0x40 ,
+0x03 ,0xc0 ,0x01 ,0x80 ,0x01 ,0x80 ,0x03 ,0xc0 ,0x02 ,0x40 ,0x04 ,0x60 ,0x08 ,0x30 ,0x08 ,0x30 ,
+0x78 ,0x7c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7e ,0x7e ,0x18 ,0x18 ,0x18 ,0x10 ,0x0c ,0x10 ,0x0c ,0x30 ,
+0x0c ,0x20 ,0x06 ,0x20 ,0x06 ,0x60 ,0x02 ,0x40 ,0x03 ,0x40 ,0x03 ,0x80 ,0x01 ,0x80 ,0x01 ,0x80 ,
+0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x02 ,0x00 ,0x3e ,0x00 ,0x1c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x1f ,0xf8 ,0x38 ,0x30 ,0x30 ,0x30 ,0x20 ,0x60 ,0x20 ,0xc0 ,
+0x00 ,0xc0 ,0x01 ,0x80 ,0x03 ,0x00 ,0x03 ,0x00 ,0x06 ,0x04 ,0x0c ,0x08 ,0x0c ,0x08 ,0x18 ,0x08 ,
+0x3f ,0xf8 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x0c ,0x00 ,0x30 ,0x00 ,0x20 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,
+0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x40 ,0x00 ,0x40 ,0x00 ,0xc0 ,0x01 ,0x00 ,0x00 ,0xc0 ,
+0x00 ,0x40 ,0x00 ,0x40 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,0x00 ,0x60 ,
+0x00 ,0x60 ,0x00 ,0x20 ,0x00 ,0x20 ,0x00 ,0x38 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,
+0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,
+0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,
+0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x30 ,0x00 ,0x0c ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,
+0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x06 ,0x00 ,0x03 ,0x00 ,0x00 ,0x80 ,0x03 ,0x00 ,
+0x06 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,
+0x04 ,0x00 ,0x04 ,0x00 ,0x04 ,0x00 ,0x18 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x23 ,0x02 ,0x41 ,0x82 ,0x40 ,0xc4 ,0x00 ,0x6c ,0x00 ,0x30 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/vgs_img.h b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/vgs_img.h
new file mode 100644
index 0000000000000000000000000000000000000000..aa00b97a9eb6c3729a55330be039ca10f29e1049
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/include/vgs_img.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef VGS_IMG_H
+#define VGS_IMG_H
+
+#include
+#include
+
+#include "hi_common.h"
+#include "hi_comm_video.h"
+#include "hi_comm_venc.h"
+#include "ai_infer_process.h"
+
+#if __cplusplus
+extern "C" {
+#endif
+
+/*
+ * 常用数字单位
+ * Commonly used numerical units
+ */
+#define HI_KB 1024
+#define HI_MB (1024 * 1024)
+#define HI_MS_OF_SEC 1000 // 1s in milliseconds
+#define HI_NS_OF_MS 1000000 // Nanoseconds in 1ms
+#define HI_BYTE_BITS 8 // Number of bits in 1 byte
+#define HI_INT8_BITS 8 // 8-bit integer number of bits
+#define HI_INT16_BITS 16 // 16-bit integer number of bits
+#define HI_INT32_BITS 32 // 32-bit integer number of bits
+#define HI_INT64_BITS 64 // The number of bits of a 64-bit integer
+
+/*
+ * 帧缩放
+ * 多次调用vgs_resize以实现任意比例的缩放
+ * 为简化实现,约定每次缩放最大14倍,此时宽、高仅需2像素对齐
+ * 当两个方向缩放方向不同时,例如一向(如X)放大,另一向缩小倍,无需特别处理
+ * 此时某个方向或两个方向缩放比例均超标,也不需要特别处理
+ *
+ * resize frame.
+ * Call vgs_resize multiple times to achieve arbitrary scaling.
+ * In order to simplify the implementation, it is agreed that each zoom is up to 14 times,
+ * and at this time, the width and height only need to be aligned by 2 pixels.
+ * When the zoom directions are different in the two directions, for example,
+ * zooming in one direction (such as X) and zooming out in the other direction,
+ * no special processing is required. At this time, the zoom ratio in one direction or
+ * both directions exceeds the standard, and no special treatment is required.
+ */
+int MppFrmResize(
+ const VIDEO_FRAME_INFO_S* src,
+ VIDEO_FRAME_INFO_S* dst,
+ uint32_t dstWidth, uint32_t dstHeight);
+
+/*
+ * 销毁帧
+ * Destory frame
+ */
+void MppFrmDestroy(VIDEO_FRAME_INFO_S* frm);
+
+/*
+ * 在框架中叠加一个或多个矩形框
+ * Superimpose one or more rectangular boxes in the frame
+ */
+int MppFrmDrawRects(VIDEO_FRAME_INFO_S *frm,
+ const RectBox *boxes, int boxesNum, uint32_t color, int thick);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/src/ive_img.c b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/src/ive_img.c
new file mode 100644
index 0000000000000000000000000000000000000000..a5e88787a8b3fbfc867d0084b834977a4fc1b629
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/src/ive_img.c
@@ -0,0 +1,334 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "hi_comm_vb.h"
+#include "mpi_sys.h"
+#include "ive_img.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* End of #ifdef __cplusplus */
+
+#define HALF_THE_HEIGHT 2 // Half the height
+
+HI_U32 HiAlign16(HI_U32 num)
+{
+ return (((num) + 16 - 1) / 16 * 16); // 16: align 16
+}
+
+HI_U32 HiAlign32(HI_U32 num)
+{
+ return (((num) + 32 - 1) / 32 * 32); // 32: align 32
+}
+
+/*
+ * VIDEO_FRAME_INFO_S格式转换成IVE_IMAGE_S格式
+ * 复制数据指针,不复制数据
+ *
+ * video frame to ive image.
+ * Copy the data pointer, do not copy the data.
+ */
+int FrmToOrigImg(const VIDEO_FRAME_INFO_S* frm, IVE_IMAGE_S *img)
+{
+ static const int chnNum = 2; // Currently only supports YUV420/422, so only the addresses of 2 channels are copied
+ PIXEL_FORMAT_E pixelFormat = frm->stVFrame.enPixelFormat;
+
+ if (memset_s(img, sizeof(*img), 0, sizeof(*img)) != EOK) {
+ HI_ASSERT(0);
+ }
+
+ img->u32Width = frm->stVFrame.u32Width;
+ img->u32Height = frm->stVFrame.u32Height;
+
+ if (pixelFormat == PIXEL_FORMAT_YVU_SEMIPLANAR_420) {
+ img->enType = IVE_IMAGE_TYPE_YUV420SP;
+ } else if (pixelFormat == PIXEL_FORMAT_YVU_SEMIPLANAR_422) {
+ img->enType = IVE_IMAGE_TYPE_YUV422SP;
+ } else {
+ HI_ASSERT(0);
+ return -1;
+ }
+
+ for (int i = 0; i < chnNum; i++) {
+ img->au64PhyAddr[i] = frm->stVFrame.u64PhyAddr[i];
+ img->au64VirAddr[i] = frm->stVFrame.u64VirAddr[i];
+ img->au32Stride[i] = frm->stVFrame.u32Stride[i];
+ }
+ return 0;
+}
+
+/*
+ * 计算通道的步长
+ * Calculate the stride of a channel
+ */
+static uint32_t IveCalStride(IVE_IMAGE_TYPE_E enType, uint32_t width, AlignType align)
+{
+ uint32_t size = 1;
+
+ switch (enType) {
+ case IVE_IMAGE_TYPE_U8C1:
+ case IVE_IMAGE_TYPE_S8C1:
+ case IVE_IMAGE_TYPE_S8C2_PACKAGE:
+ case IVE_IMAGE_TYPE_S8C2_PLANAR:
+ case IVE_IMAGE_TYPE_U8C3_PACKAGE:
+ case IVE_IMAGE_TYPE_U8C3_PLANAR:
+ size = sizeof(HI_U8);
+ break;
+ case IVE_IMAGE_TYPE_S16C1:
+ case IVE_IMAGE_TYPE_U16C1:
+ size = sizeof(HI_U16);
+ break;
+ case IVE_IMAGE_TYPE_S32C1:
+ case IVE_IMAGE_TYPE_U32C1:
+ size = sizeof(uint32_t);
+ break;
+ case IVE_IMAGE_TYPE_S64C1:
+ case IVE_IMAGE_TYPE_U64C1:
+ size = sizeof(uint64_t);
+ break;
+ default:
+ break;
+ }
+
+ if (align == ALIGN_TYPE_16) {
+ return HiAlign16(width * size);
+ } else if (align == ALIGN_TYPE_32) {
+ return HiAlign32(width * size);
+ } else {
+ HI_ASSERT(0);
+ return 0;
+ }
+}
+
+/*
+ * 根据类型和大小创建缓存
+ * Create ive image buffer based on type and size
+ */
+int IveImgCreate(IVE_IMAGE_S* img,
+ IVE_IMAGE_TYPE_E enType, uint32_t width, uint32_t height)
+{
+ HI_ASSERT(img);
+ uint32_t oneChnSize;
+ uint32_t size;
+ int ret;
+
+ if (memset_s(img, sizeof(*img), 0, sizeof(*img)) != EOK) {
+ HI_ASSERT(0);
+ }
+ img->enType = enType;
+ img->u32Width = width;
+ img->u32Height = height;
+ img->au32Stride[0] = IveCalStride(img->enType, img->u32Width, ALIGN_TYPE_16);
+
+ switch (enType) {
+ case IVE_IMAGE_TYPE_U8C1:
+ case IVE_IMAGE_TYPE_S8C1: // Only 1 channel
+ size = img->au32Stride[0] * img->u32Height;
+ ret = HI_MPI_SYS_MmzAlloc(&img->au64PhyAddr[0], (void**)&img->au64VirAddr[0], NULL, NULL, size);
+ SAMPLE_CHECK_EXPR_RET(HI_SUCCESS != ret, ret, "Error(%#x), HI_MPI_SYS_MmzAlloc!\n", ret);
+ break;
+ /*
+ * 大小相当于像素的1.5倍(3/2), 相当于2个通道
+ * The size is equivalent to 1.5 times (3/2) of the pixel, which is equivalent to 2 channels
+ */
+ case IVE_IMAGE_TYPE_YUV420SP:
+ /*
+ * 大小相当于像素的2倍,相当于2个通道
+ * The size is equivalent to 2 times the pixel, which is equivalent to 2 channels
+ */
+ case IVE_IMAGE_TYPE_YUV422SP:
+ if (enType == IVE_IMAGE_TYPE_YUV420SP) {
+ size = img->au32Stride[0] * img->u32Height * THREE_TIMES / TWO_TIMES;
+ } else {
+ size = img->au32Stride[0] * img->u32Height * TWO_TIMES;
+ }
+ ret = HI_MPI_SYS_MmzAlloc(&img->au64PhyAddr[0], (void**)&img->au64VirAddr[0], NULL, NULL, size);
+ SAMPLE_CHECK_EXPR_RET(HI_SUCCESS != ret, ret, "Error(%#x), HI_MPI_SYS_MmzAlloc!\n", ret);
+
+ /*
+ * 设置通道1地址的步长,两者都需要通道1
+ * Set the stride of the address of channel 1, both of which require channel 1
+ */
+ img->au32Stride[1] = img->au32Stride[0];
+ img->au64PhyAddr[1] = img->au64PhyAddr[0] + img->au32Stride[0] * (uint64_t)img->u32Height;
+ img->au64VirAddr[1] = img->au64VirAddr[0] + img->au32Stride[0] * (uint64_t)img->u32Height;
+ break;
+
+ case IVE_IMAGE_TYPE_U8C3_PLANAR: // 3 channels, often used for RGB
+ oneChnSize = img->au32Stride[0] * img->u32Height;
+ size = oneChnSize * 3; // 3 channels have the same size
+ ret = HI_MPI_SYS_MmzAlloc(&img->au64PhyAddr[0], (void**)&img->au64VirAddr[0], NULL, NULL, size);
+ SAMPLE_CHECK_EXPR_RET(HI_SUCCESS != ret, ret, "Error(%#x), HI_MPI_SYS_MmzAlloc!\n", ret);
+
+ /*
+ * 设置通道1和通道2的地址和步长
+ * Set the address and stride of channel 1 and channel 2
+ */
+ img->au64VirAddr[1] = img->au64VirAddr[0] + oneChnSize;
+ img->au64PhyAddr[1] = img->au64PhyAddr[0] + oneChnSize;
+ img->au32Stride[1] = img->au32Stride[0];
+ img->au64VirAddr[2] = img->au64VirAddr[1] + oneChnSize; // 2: au64VirAddr array subscript, not out of bounds
+ img->au64PhyAddr[2] = img->au64PhyAddr[1] + oneChnSize; // 2: au64VirAddr array subscript, not out of bounds
+ img->au32Stride[2] = img->au32Stride[0]; // 2: au64VirAddr array subscript, not out of bounds
+ break;
+
+ /*
+ * 目前如下格式不支持,主要为YVC420P, YUV422P, S8C2_PACKAGE, S8C2_PLANAR,
+ * S32C1, U32C1, S64C1, U64C1, S16C1, U16C1, U8C3_PACKAGE等
+ *
+ * Types not currently supported: YVC420P, YUV422P, S8C2_PACKAGE, S8C2_PLANAR,
+ * S32C1, U32C1, S64C1, U64C1, S16C1, U16C1, U8C3_PACKAGE,etc.
+ */
+ default:
+ HI_ASSERT(0);
+ break;
+ }
+ return HI_SUCCESS;
+}
+
+int ImgYuvCrop(const IVE_IMAGE_S *src, IVE_IMAGE_S *dst, const RectBox* origBox)
+{
+ RectBox box = *origBox;
+ int boxWidth = box.xmax - box.xmin;
+ int boxHeight = box.ymax - box.ymin;
+ int ret;
+
+ HI_ASSERT(boxWidth > 0 && boxWidth <= src->u32Width);
+ HI_ASSERT(boxHeight > 0 && boxHeight <= src->u32Height);
+ HI_ASSERT(src->au64VirAddr[0]);
+ HI_ASSERT(src->au32Stride[0] >= src->u32Width);
+
+ /*
+ * 将框的宽度/高度调整为 2 的倍数
+ * Adjust the width/height of the box to a multiple of 2
+ */
+ if (boxWidth == 1 || boxHeight == 1) {
+ SAMPLE_PRT("box dstWidth=1 && dstHeight=1\n");
+ return -1;
+ }
+ if (boxWidth % HI_OVEN_BASE) {
+ box.xmax--;
+ boxWidth--;
+ }
+ if (boxHeight % HI_OVEN_BASE) {
+ box.ymax--;
+ boxHeight--;
+ }
+
+ ret = IveImgCreate(dst, src->enType, boxWidth, boxHeight);
+ HI_ASSERT(!ret);
+
+ /*
+ * 将框从源地址复制到目的地址
+ * copy box from src to dst
+ */
+ /*
+ * Y分量
+ * Y component
+ */
+ int srcStrideY = src->au32Stride[0];
+ int dstStrideY = dst->au32Stride[0];
+ uint8_t *srcBufY = (uint8_t*)((uintptr_t)src->au64VirAddr[0]);
+ uint8_t *dstBufY = (uint8_t*)((uintptr_t)dst->au64VirAddr[0]);
+ uint8_t *srcPtrY = &srcBufY[box.ymin * srcStrideY];
+ uint8_t *dstPtrY = dstBufY;
+ for (int h = 0; h < boxHeight; h++, srcPtrY += srcStrideY, dstPtrY += dstStrideY) {
+ if (memcpy_s(dstPtrY, boxWidth, srcPtrY + box.xmin, boxWidth) != EOK) {
+ HI_ASSERT(0);
+ }
+ }
+ HI_ASSERT(dstPtrY - dstBufY == boxHeight * dstStrideY);
+
+ /*
+ * UV分量
+ * UV component
+ */
+ int srcStrideUV = src->au32Stride[1];
+ int dstStrideUV = dst->au32Stride[1];
+ uint8_t *srcBufUV = (uint8_t*)((uintptr_t)src->au64VirAddr[1]);
+ uint8_t *dstBufUV = (uint8_t*)((uintptr_t)dst->au64VirAddr[1]);
+ uint8_t *srcPtrUV = &srcBufUV[(box.ymin / HALF_THE_HEIGHT) * srcStrideUV];
+ uint8_t *dstPtrUV = dstBufUV;
+ for (int h = 0; h < (boxHeight / HALF_THE_HEIGHT);
+ h++, srcPtrUV += srcStrideUV, dstPtrUV += dstStrideUV) {
+ if (memcpy_s(dstPtrUV, boxWidth, srcPtrUV + box.xmin, boxWidth) != EOK) {
+ HI_ASSERT(0);
+ }
+ }
+ HI_ASSERT(dstPtrUV - dstBufUV == (boxHeight / HALF_THE_HEIGHT) * dstStrideUV);
+
+ return ret;
+}
+
+/*
+ * 销毁ive image
+ * Destory ive image
+ */
+void IveImgDestroy(IVE_IMAGE_S* img)
+{
+ for (int i = 0; i < IMG_FULL_CHN; i++) {
+ if (img->au64PhyAddr[0] && img->au64VirAddr[0]) {
+ HI_MPI_SYS_MmzFree(img->au64PhyAddr[i], (void*)((uintptr_t)img->au64VirAddr[i]));
+ img->au64PhyAddr[i] = 0;
+ img->au64VirAddr[i] = 0;
+ }
+ }
+ if (memset_s(img, sizeof(*img), 0, sizeof(*img)) != EOK) {
+ HI_ASSERT(0);
+ }
+}
+
+int OrigImgToFrm(const IVE_IMAGE_S *img, VIDEO_FRAME_INFO_S* frm)
+{
+ static const int chnNum = 2;
+ IVE_IMAGE_TYPE_E enType = img->enType;
+ if (memset_s(frm, sizeof(*frm), 0, sizeof(*frm)) != EOK) {
+ HI_ASSERT(0);
+ }
+
+ frm->stVFrame.u32Width = img->u32Width;
+ frm->stVFrame.u32Height = img->u32Height;
+
+ if (enType == IVE_IMAGE_TYPE_YUV420SP) {
+ frm->stVFrame.enPixelFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
+ } else if (enType == IVE_IMAGE_TYPE_YUV422SP) {
+ frm->stVFrame.enPixelFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_422;
+ } else {
+ HI_ASSERT(0);
+ return -1;
+ }
+
+ for (int i = 0; i < chnNum; i++) {
+ frm->stVFrame.u64PhyAddr[i] = img->au64PhyAddr[i];
+ frm->stVFrame.u64VirAddr[i] = img->au64VirAddr[i];
+ frm->stVFrame.u32Stride[i] = img->au32Stride[i];
+ }
+ return 0;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* End of #ifdef __cplusplus */
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/src/osd_img.c b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/src/osd_img.c
new file mode 100644
index 0000000000000000000000000000000000000000..2baeb4273d69db3c0b79bdd73cafcfc175dd84c3
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/src/osd_img.c
@@ -0,0 +1,1266 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include "mpi_vi.h"
+#include "mpi_vpss.h"
+#include "mpi_venc.h"
+#include "mpi_vo.h"
+#include "mpi_region.h"
+#include "sample_comm_ive.h"
+#include "sample_media_ai.h"
+#include "vgs_img.h"
+#include "osd_img.h"
+
+/* OSD font library */
+static const HI_U8 G_FONT_LIB[] __attribute__((aligned(4))) = {
+#include "simsunb_16x32.txt"
+};
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* End of #ifdef __cplusplus */
+
+#define OSD_FONT_WIDTH_DEF 40 // Default font width
+#define OSD_FONT_HEIGHT_DEF 40 // The default font height
+#define NOASCII_CHARACTER_BYTES (2) /* Number of bytes occupied by each Chinese character */
+#define BYTE_BITS (8)
+
+#define OSD_FONT_ASC
+#define OSD_FONT_MOD_W 16
+#define OSD_FONT_MOD_H 32
+#define X_COORDINATE 100
+#define Y_COORDINATE 100
+#define BASE_YAER 1900
+#define MULTIPLE_NUM 100
+
+/*
+ * 全局对象
+ * 多个OsdSet实例将从全局池中分配id
+ *
+ * Global object.
+ * Multiple OsdSet instances will allocate ids from the global pool.
+ */
+static void* g_osdHndPool[HI_OSD_MAX_CNT]; // Used to identify whether the index handle is used
+static pthread_mutex_t g_osdMutex; // pool access lock
+
+/*
+ * OSD参数数组
+ * OSD Parameter Array、
+ */
+static OSD_PARAM_S s_stOSDParam[HI_OSD_MAX_CNT];
+
+/*
+ * OSD 模块初始化标志
+ * 只能被HI_PDT_OSD_Init/HI_PDT_OSD_DeInit修改
+ *
+ * OSD Module Init Flag
+ * Only modified by HI_PDT_OSD_Init/HI_PDT_OSD_DeInit
+ */
+static HI_BOOL s_bOSDInitFlg = HI_FALSE;
+
+/*
+ * OSD 字体库,由 HI_PDT_OSD_Init 初始化
+ * OSD Fonts Lib, inited by HI_PDT_OSD_Init
+ */
+static HI_OSD_FONTS_S s_stOSDFonts;
+
+/*
+ * OSD 时间更新运行标志
+ * 只能被HI_PDT_OSD_Init/HI_PDT_OSD_DeInit修改
+ *
+ * OSD Time Update Runing Flag
+ * Only modified by HI_PDT_OSD_Init/HI_PDT_OSD_DeInit
+ */
+static HI_BOOL s_bOSDTimeRun = HI_FALSE;
+
+/*
+ * 时间OSD更新任务线程ID,由HI_PDT_OSD_Init创建,由HI_OSD_DeInit销毁
+ * Time OSD Update Task Thread ID, created by HI_PDT_OSD_Init, destroyed by HI_OSD_DeInit
+ */
+static pthread_t s_OSDTimeTskId = 0;
+
+static HI_OSD_TEXTBITMAP_S s_stOSDTextBitMap;
+
+static HI_U8* FontMod = NULL;
+static HI_S32 FontModLen = 0;
+
+/*
+ * 位图行/列索引
+ * Bitmap Row/Col Index
+ */
+static HI_S32 s32BmRow;
+static HI_S32 s32BmCol;
+struct tm stTime = {0};
+
+/*
+ * OSD Font Step In Lib,以字节为单位
+ * OSD Font Step In Lib, in bytes
+ */
+#define OSD_LIB_FONT_W (s_stOSDFonts.u32FontWidth)
+#define OSD_LIB_FONT_H (s_stOSDFonts.u32FontHeight)
+#define OSD_LIB_FONT_STEP (OSD_LIB_FONT_W * OSD_LIB_FONT_H / BYTE_BITS)
+
+/*
+ * 数据对齐
+ * Value Align
+ */
+HI_S32 HiAppcommAlign(HI_S32 value, HI_S32 base)
+{
+ return (((value) + (base)-1) / (base) * (base));
+}
+
+HI_U32 max(HI_U32 a, HI_U32 b)
+{
+ return (((a) < (b)) ? (b) : (a));
+}
+
+HI_U32 min(HI_U32 a, HI_U32 b)
+{
+ return (((a) > (b)) ? (b) : (a));
+}
+
+HI_S32 IsAscii(HI_S32 a)
+{
+ return (((a) >= 0x00 && (a) <= 0x7F) ? 1 : 0);
+}
+
+static HI_S32 OSD_GetNonASCNum(HI_CHAR* string, HI_S32 len)
+{
+ HI_S32 i;
+ HI_S32 n = 0;
+ for (i = 0; i < len; i++) {
+ if (string[i] == '\0') {
+ break;
+ }
+ if (!IsAscii(string[i])) {
+ i++;
+ n++;
+ }
+ }
+ return n;
+}
+
+/*
+ * 创建OsdSet
+ * Creat OsdSet
+ */
+OsdSet* OsdsCreate(HI_OSD_BIND_MOD_E bindMod, HI_U32 modHnd, HI_U32 chnHnd)
+{
+ OsdSet *self = NULL;
+
+ self = (OsdSet*)malloc(sizeof(*self));
+ if (!self) {
+ HI_ASSERT(0);
+ }
+ if (memset_s(self, sizeof(*self), 0, sizeof(*self)) != EOK) {
+ HI_ASSERT(0);
+ }
+
+ self->bindMod = bindMod;
+ self->modHnd = modHnd;
+ self->chnHnd = chnHnd;
+ return self;
+}
+
+/*
+ * @brief 获取给定格式的时间字符串
+ * @param[in]pstTime : 时间结构,如果为空则获取当前系统时间
+ * @param[out]pazStr : 时间字符串缓冲区
+ * @param[in]s32Len : 时间字符串缓冲区长度
+ *
+ * @brief get time string with given format
+ * @param[in]pstTime : time struct, get current system time if null
+ * @param[out]pazStr : time string buffer
+ * @param[in]s32Len : time string buffer length
+ */
+static HI_VOID OSD_GetTimeStr(struct tm* pstTime, HI_CHAR* pazStr, HI_S32 s32Len)
+{
+ /*
+ * 获取时间
+ * Get Time
+ */
+ time_t nowTime;
+
+ if (!pstTime) {
+ time(&nowTime);
+ localtime_r(&nowTime, pstTime);
+ }
+
+ /*
+ * 生成时间字符串
+ * Generate Time String
+ */
+ if (snprintf_s(pazStr, s32Len, s32Len - 1, "%04d-%02d-%02d %02d:%02d:%02d",
+ pstTime->tm_year + BASE_YAER, pstTime->tm_mon + 1, pstTime->tm_mday,
+ pstTime->tm_hour, pstTime->tm_min, pstTime->tm_sec) < 0) {
+ HI_ASSERT(0);
+ }
+
+ return;
+}
+
+static HI_S32 OSD_RGNDetach(RGN_HANDLE RgnHdl, const HI_OSD_DISP_ATTR_S* pstDispAttr)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ MPP_CHN_S stChn;
+
+ stChn.s32DevId = pstDispAttr->ModHdl;
+ stChn.s32ChnId = pstDispAttr->ChnHdl;
+ switch (pstDispAttr->enBindedMod) {
+ case HI_OSD_BINDMOD_VI:
+ stChn.enModId = HI_ID_VI;
+ break;
+ case HI_OSD_BINDMOD_VPSS:
+ stChn.enModId = HI_ID_VPSS;
+ break;
+ case HI_OSD_BINDMOD_AVS:
+ stChn.enModId = HI_ID_AVS;
+ break;
+ case HI_OSD_BINDMOD_VENC:
+ stChn.s32DevId = 0;
+ stChn.enModId = HI_ID_VENC;
+ break;
+ case HI_OSD_BINDMOD_VO:
+ stChn.enModId = HI_ID_VO;
+ break;
+ default:
+ SAMPLE_PRT("RgnHdl[%d] invalide bind mode [%d]\n", RgnHdl, pstDispAttr->enBindedMod);
+ return HI_EINVAL;
+ }
+
+ s32Ret = HI_MPI_RGN_DetachFromChn(RgnHdl, &stChn);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("HI_MPI_RGN_DetachFromChn fail,RgnHdl[%d] stChn[%d,%d,%d] Error Code: [0x%08X]\n",
+ RgnHdl, stChn.enModId, stChn.s32DevId, stChn.s32ChnId, s32Ret);
+ return s32Ret;
+ }
+
+ return HI_SUCCESS;
+}
+
+static HI_S32 OSD_DestroyRGN(RGN_HANDLE RgnHdl, const HI_OSD_ATTR_S* pstAttr)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_S32 s32DispIdx = 0;
+
+ for (s32DispIdx = 0; s32DispIdx < pstAttr->u32DispNum ; ++s32DispIdx) {
+ if (pstAttr->astDispAttr[s32DispIdx].bShow) {
+ OSD_RGNDetach(RgnHdl, &pstAttr->astDispAttr[s32DispIdx]);
+ }
+ }
+
+ s32Ret = HI_MPI_RGN_Destroy(RgnHdl);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("HI_MPI_RGN_Destroy fail, RgnHdl[%d] Error Code: [0x%08X]\n", RgnHdl, s32Ret);
+ return s32Ret;
+ }
+
+ return HI_SUCCESS;
+}
+
+/*
+ * 在OsdSet中创建区域
+ * Create a region in OsdSet
+ */
+int OsdsCreateRgn(OsdSet* self)
+{
+ HI_ASSERT(self);
+ int ret = -1;
+
+ MutexLock(&g_osdMutex);
+ for (int i = 0; i < HI_OSD_MAX_CNT; i++) {
+ if (!g_osdHndPool[i]) {
+ g_osdHndPool[i] = self;
+ ret = i;
+ break;
+ }
+ }
+ MutexUnlock(&g_osdMutex);
+ return ret;
+}
+
+static HI_S32 OSD_Stop(HI_S32 s32OsdIdx)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ OSD_PARAM_S* pstOsdParam = &s_stOSDParam[s32OsdIdx];
+
+ if (!pstOsdParam->bOn) {
+ return HI_SUCCESS;
+ }
+
+ s32Ret = OSD_DestroyRGN(s32OsdIdx, &pstOsdParam->stAttr);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("OSD_DestroyRGN s32OsdIdx[%d] failed:[0x%08X]\n", s32OsdIdx, s32Ret);
+ return s32Ret;
+ }
+
+ pstOsdParam->bOn = HI_FALSE;
+ return HI_SUCCESS;
+}
+
+/*
+ * @brief 按索引停止osd
+ * @param[in] s32OsdIdx:osd 索引,范围[0,HI_OSD_MAX_CNT)
+ * @return 0 成功,非零错误码
+ *
+ * @brief stop osd by index.
+ * @param[in] s32OsdIdx:osd index, range[0,HI_OSD_MAX_CNT)
+ * @return 0 success,non-zero error code.
+ */
+HI_S32 HI_OSD_Stop(HI_S32 s32OsdIdx)
+{
+ /*
+ * 检查模块初始化与否
+ * Check Module Init or not
+ */
+ HI_ASSERT(HI_TRUE == s_bOSDInitFlg);
+ /*
+ * 检查输入参数
+ * Check Input Param
+ */
+ HI_ASSERT(s32OsdIdx >= 0);
+ HI_ASSERT(HI_OSD_MAX_CNT > s32OsdIdx);
+
+ HI_S32 s32Ret = HI_SUCCESS;
+ OSD_PARAM_S* pstOsdParam = &s_stOSDParam[s32OsdIdx];
+
+ pthread_mutex_lock(&pstOsdParam->mutexLock);
+
+ /*
+ * 检查OSD Attrbute是否初始化
+ * Check OSD Attrbute init or not
+ */
+ if (!pstOsdParam->bInit) {
+ pthread_mutex_unlock(&pstOsdParam->mutexLock);
+ return HI_SUCCESS;
+ }
+
+ /*
+ * 检查OSD是否停止
+ * Check OSD stop or not
+ */
+ if (!pstOsdParam->bOn) {
+ pthread_mutex_unlock(&pstOsdParam->mutexLock);
+ return HI_SUCCESS;
+ }
+
+ s32Ret = OSD_Stop(s32OsdIdx);
+ pstOsdParam->stMaxSize.u32Width = 0;
+ pstOsdParam->stMaxSize.u32Height= 0;
+ pthread_mutex_unlock(&pstOsdParam->mutexLock);
+ return s32Ret;
+}
+
+/*
+ * 销毁OsdSet中指定的区域
+ * Destroy the region specified in the OsdSet
+ */
+void OsdsDestroyRgn(OsdSet* self, int rgnHnd)
+{
+ HI_ASSERT(self);
+ HI_ASSERT(rgnHnd >= 0 && rgnHnd < HI_OSD_MAX_CNT);
+
+ MutexLock(&g_osdMutex);
+ HI_ASSERT(g_osdHndPool[rgnHnd] && g_osdHndPool[rgnHnd] == (void*)self);
+ g_osdHndPool[rgnHnd] = NULL;
+ MutexUnlock(&g_osdMutex);
+
+ HI_OSD_Stop(rgnHnd);
+}
+
+/*
+ * 销毁OsdSet中的所有区域
+ * Destroy all regions in OsdSet
+ */
+void OsdsClear(OsdSet* self)
+{
+ MutexLock(&g_osdMutex);
+ for (int i = 0; i < HI_OSD_MAX_CNT; i++) {
+ if (g_osdHndPool[i] && g_osdHndPool[i] == (void*)self) {
+ OsdsDestroyRgn(self, i);
+ }
+ }
+ MutexUnlock(&g_osdMutex);
+}
+
+/*
+ * 销毁OsdSet
+ * Destory OsdSet
+ */
+void OsdsDestroy(OsdSet* self)
+{
+ HI_ASSERT(self);
+ OsdsClear(self);
+ free(self);
+}
+
+/*
+ * 设置文本区域的属性值
+ * Set the attribute value of the text region
+ */
+int TxtRgnInit(HI_OSD_ATTR_S* rgnAttr, const char* str, uint32_t begX, uint32_t begY, uint32_t color)
+{
+ HI_ASSERT(rgnAttr);
+ if (!str) {
+ HI_ASSERT(0);
+ }
+ // 64:[0,128], the transparency of the text background block, the larger the background block color,
+ // the darker the background block color, 0 means no background block, that is, completely transparent
+ static const uint32_t bgAlpha = 64;
+ // 128:[0,128], the brightness of the text, the larger the value, the brighter the text
+ static const uint32_t fgAlpha = 128;
+
+ if (memset_s(rgnAttr, sizeof(*rgnAttr), 0, sizeof(*rgnAttr)) != EOK) {
+ HI_ASSERT(0);
+ }
+ rgnAttr->u32DispNum = 1;
+ rgnAttr->astDispAttr[0].bShow = (str && *str) ? HI_TRUE : HI_FALSE;
+ rgnAttr->astDispAttr[0].enBindedMod = HI_OSD_BINDMOD_BUTT;
+ rgnAttr->astDispAttr[0].ChnHdl = UINT32_MAX;
+ rgnAttr->astDispAttr[0].u32BgAlpha = bgAlpha;
+ rgnAttr->astDispAttr[0].u32FgAlpha = fgAlpha;
+ rgnAttr->astDispAttr[0].enCoordinate = HI_OSD_COORDINATE_ABS_COOR;
+ rgnAttr->astDispAttr[0].stStartPos.s32X = begX;
+ rgnAttr->astDispAttr[0].stStartPos.s32Y = begY;
+ rgnAttr->astDispAttr[0].enAttachDest = ATTACH_JPEG_MAIN;
+ rgnAttr->stContent.enType = HI_OSD_TYPE_STRING;
+ rgnAttr->stContent.u32Color = color; // ARGB #FFFF0000 Red
+ HiStrxfrm(rgnAttr->stContent.szStr, str, sizeof(rgnAttr->stContent.szStr));
+ rgnAttr->stContent.stFontSize.u32Width = OSD_FONT_WIDTH_DEF;
+ rgnAttr->stContent.stFontSize.u32Height = OSD_FONT_HEIGHT_DEF;
+ return 0;
+}
+
+static HI_S32 OSD_Ratio2Absolute(MPP_CHN_S stChn, const POINT_S* pstRatioCoor, POINT_S* pstAbsCoor)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SIZE_S stImageSize;
+
+ if (pstRatioCoor->s32X < 0 || pstRatioCoor->s32X > X_COORDINATE ||
+ pstRatioCoor->s32Y < 0 || pstRatioCoor->s32Y > Y_COORDINATE) {
+ SAMPLE_PRT("invalide Ratio coordinate(%d,%d)\n", pstRatioCoor->s32X, pstRatioCoor->s32Y);
+ return HI_EINVAL;
+ }
+ switch (stChn.enModId) {
+ case HI_ID_VI: {
+ VI_CHN_ATTR_S stChnAttr;
+ s32Ret = HI_MPI_VI_GetChnAttr(stChn.s32DevId, stChn.s32ChnId, &stChnAttr);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("HI_MPI_VI_GetChnAttr(%d,%d) fail,Error Code: [0x%08X]\n",
+ stChn.s32DevId, stChn.s32ChnId, s32Ret);
+ return s32Ret;
+ }
+ stImageSize = stChnAttr.stSize;
+ break;
+ }
+ case HI_ID_VPSS: {
+ VPSS_CHN_ATTR_S stChnAttr;
+ s32Ret = HI_MPI_VPSS_GetChnAttr(stChn.s32DevId, stChn.s32ChnId, &stChnAttr);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("HI_MPI_VPSS_GetChnAttr(%d,%d) fail, Error Code: [0x%08X]\n",
+ stChn.s32DevId, stChn.s32ChnId, s32Ret);
+ return s32Ret;
+ }
+ stImageSize.u32Width = stChnAttr.u32Width;
+ stImageSize.u32Height = stChnAttr.u32Height;
+ break;
+ }
+ case HI_ID_VO: {
+ VO_CHN_ATTR_S stChnAttr;
+ s32Ret = HI_MPI_VO_GetChnAttr(stChn.s32DevId, stChn.s32ChnId, &stChnAttr);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("HI_MPI_VO_GetChnAttr(%d,%d) fail,Error Code: [0x%08X]\n",
+ stChn.s32DevId, stChn.s32ChnId, s32Ret);
+ return s32Ret;
+ }
+ stImageSize.u32Width = stChnAttr.stRect.u32Width;
+ stImageSize.u32Height = stChnAttr.stRect.u32Height;
+ break;
+ }
+ default:
+ SAMPLE_PRT("invalide mode id [%d]\n", stChn.enModId);
+ return HI_EINVAL;
+ }
+
+ // 2: HiAppcommAlign api base param
+ pstAbsCoor->s32X = HiAppcommAlign(stImageSize.u32Width * pstRatioCoor->s32X / MULTIPLE_NUM, 2);
+ // 2: HiAppcommAlign api base param
+ pstAbsCoor->s32Y = HiAppcommAlign(stImageSize.u32Height * pstRatioCoor->s32Y / MULTIPLE_NUM, 2);
+ return HI_SUCCESS;
+}
+
+static HI_S32 OSD_Update(RGN_HANDLE RgnHdl, const HI_OSD_ATTR_S* pstAttr)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_S32 s32DispIdx = 0;
+ RGN_CHN_ATTR_S stRgnChnAttr;
+ MPP_CHN_S stChn;
+
+ for (s32DispIdx = 0; s32DispIdx < pstAttr->u32DispNum ; ++s32DispIdx) {
+ if (!pstAttr->astDispAttr[s32DispIdx].bShow) {
+ continue;
+ }
+
+ stChn.s32DevId = pstAttr->astDispAttr[s32DispIdx].ModHdl;
+ stChn.s32ChnId = pstAttr->astDispAttr[s32DispIdx].ChnHdl;
+ switch (pstAttr->astDispAttr[s32DispIdx].enBindedMod) {
+ case HI_OSD_BINDMOD_VI:
+ stChn.enModId = HI_ID_VI;
+ break;
+ case HI_OSD_BINDMOD_VPSS:
+ stChn.enModId = HI_ID_VPSS;
+ break;
+ case HI_OSD_BINDMOD_VO:
+ stChn.enModId = HI_ID_VO;
+ break;
+ default:
+ SAMPLE_PRT("invalide bind mode [%d]\n", pstAttr->astDispAttr[s32DispIdx].enBindedMod);
+ return HI_EINVAL;
+ }
+ /*
+ * 获取区域的通道显示属性
+ * Get the channel display properties of the zone
+ */
+ s32Ret = HI_MPI_RGN_GetDisplayAttr(RgnHdl, &stChn, &stRgnChnAttr);
+ SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "GetDisplayAttr fail, s32Ret:[0x%08X]\n", s32Ret);
+
+ stRgnChnAttr.bShow = pstAttr->astDispAttr[s32DispIdx].bShow;
+ POINT_S stStartPos;
+ if (pstAttr->astDispAttr[s32DispIdx].enCoordinate == HI_OSD_COORDINATE_RATIO_COOR) {
+ s32Ret = OSD_Ratio2Absolute(stChn, &pstAttr->astDispAttr[s32DispIdx].stStartPos, &stStartPos);
+ SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "Ratio2Absolute fail, s32Ret:[0x%08X]\n", s32Ret);
+ } else {
+ stStartPos = pstAttr->astDispAttr[s32DispIdx].stStartPos;
+ }
+
+ if (stRgnChnAttr.enType == OVERLAYEX_RGN) {
+ stRgnChnAttr.unChnAttr.stOverlayExChn.stPoint.s32X = stStartPos.s32X;
+ stRgnChnAttr.unChnAttr.stOverlayExChn.stPoint.s32Y = stStartPos.s32Y;
+ stRgnChnAttr.unChnAttr.stOverlayExChn.u32BgAlpha = pstAttr->astDispAttr[s32DispIdx].u32BgAlpha;
+ stRgnChnAttr.unChnAttr.stOverlayExChn.u32FgAlpha = pstAttr->astDispAttr[s32DispIdx].u32FgAlpha;
+ } else {
+ stRgnChnAttr.unChnAttr.stOverlayChn.stPoint.s32X = stStartPos.s32X;
+ stRgnChnAttr.unChnAttr.stOverlayChn.stPoint.s32Y = stStartPos.s32Y;
+ stRgnChnAttr.unChnAttr.stOverlayChn.u32BgAlpha = pstAttr->astDispAttr[s32DispIdx].u32BgAlpha;
+ stRgnChnAttr.unChnAttr.stOverlayChn.u32FgAlpha = pstAttr->astDispAttr[s32DispIdx].u32FgAlpha;
+ }
+ /*
+ * 设置区域的通道显示属性
+ * Sets the channel display properties for the zone
+ */
+ s32Ret = HI_MPI_RGN_SetDisplayAttr(RgnHdl, &stChn, &stRgnChnAttr);
+ SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "SetDisplayAttr fail, s32Ret:[0x%08X]\n", s32Ret);
+ }
+
+ return HI_SUCCESS;
+}
+
+HI_VOID OSD_PuBmData_Cal(HI_OSD_CONTENT_S* pstContent, HI_U16* puBmData, HI_S32 s32HexOffset,
+ HI_S32 s32BmDataIdx, HI_S32 s32BitOffset)
+{
+ HI_U8 temp = FontMod[s32HexOffset];
+ if ((temp >> ((BYTE_BITS - 1) - s32BitOffset)) & 0x1) {
+ puBmData[s32BmDataIdx] = (HI_U16)pstContent->u32Color;
+ } else {
+ puBmData[s32BmDataIdx] = (HI_U16)pstContent->u32BgColor;
+ }
+
+ return;
+}
+
+HI_S32 OSD_Bitmap_Cal(HI_OSD_CONTENT_S* pstContent, HI_S32 NonASCNum, HI_U16* puBmData)
+{
+ HI_S32 NonASCShow = 0;
+ for (s32BmCol = 0; s32BmCol < pstContent->stBitmap.u32Width; ++s32BmCol) {
+ /*
+ * 点的位图数据偏移
+ * Bitmap Data Offset for the point
+ */
+ HI_S32 s32BmDataIdx = s32BmRow * s_stOSDTextBitMap.stCanvasInfo.u32Stride / 2 + s32BmCol;
+ /*
+ * 文本字符串中的字符索引
+ * Character Index in Text String
+ */
+ HI_S32 s32CharIdx = s32BmCol / pstContent->stFontSize.u32Width;
+ HI_S32 s32StringIdx = s32CharIdx+NonASCShow * (NOASCII_CHARACTER_BYTES - 1);
+ if (NonASCNum > 0 && s32CharIdx > 0) {
+ NonASCShow = OSD_GetNonASCNum(pstContent->szStr, s32StringIdx);
+ s32StringIdx = s32CharIdx+NonASCShow * (NOASCII_CHARACTER_BYTES - 1);
+ }
+ /*
+ * 字符中的点行/列索引
+ * Point Row/Col Index in Character
+ */
+ HI_S32 s32CharCol = (s32BmCol - (pstContent->stFontSize.u32Width * s32CharIdx)) *
+ OSD_LIB_FONT_W / pstContent->stFontSize.u32Width;
+ HI_S32 s32CharRow = s32BmRow * OSD_LIB_FONT_H / pstContent->stFontSize.u32Height;
+ HI_S32 s32HexOffset = s32CharRow * OSD_LIB_FONT_W / BYTE_BITS + s32CharCol / BYTE_BITS;
+ HI_S32 s32BitOffset = s32CharCol % BYTE_BITS;
+
+ if (s_stOSDFonts.pfnGetFontMod(&pstContent->szStr[s32StringIdx], &FontMod, &FontModLen)
+ == HI_SUCCESS) {
+ if (FontMod != NULL && s32HexOffset < FontModLen) {
+ OSD_PuBmData_Cal(pstContent, puBmData, s32HexOffset, s32BmDataIdx, s32BitOffset);
+ continue;
+ }
+ }
+ SAMPLE_PRT("GetFontMod Fail\n");
+ return HI_FAILURE;
+ }
+}
+
+HI_S32 OSD_Generate_Bitmap(RGN_HANDLE RgnHdl, HI_OSD_CONTENT_S* pstContent)
+{
+ HI_S32 s32Ret;
+ HI_S32 s32StrLen = strnlen(pstContent->szStr, HI_OSD_MAX_STR_LEN);
+ HI_S32 NonASCNum = OSD_GetNonASCNum(pstContent->szStr, s32StrLen);
+
+ s32Ret = HI_MPI_RGN_GetCanvasInfo(RgnHdl, &s_stOSDTextBitMap.stCanvasInfo);
+ SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "RGN_GetCanvasInfo FAIL, s32Ret=%x\n", s32Ret);
+
+ /*
+ * 生成位图
+ * Generate Bitmap
+ */
+ pstContent->stBitmap.u32Width = pstContent->stFontSize.u32Width *
+ (s32StrLen - NonASCNum * (NOASCII_CHARACTER_BYTES - 1));
+ pstContent->stBitmap.u32Height = pstContent->stFontSize.u32Height;
+ HI_U16* puBmData = (HI_U16*)(HI_UL)s_stOSDTextBitMap.stCanvasInfo.u64VirtAddr;
+
+ for (s32BmRow = 0; s32BmRow < pstContent->stBitmap.u32Height; ++s32BmRow) {
+ OSD_Bitmap_Cal(pstContent, NonASCNum, puBmData);
+ for (s32BmCol = pstContent->stBitmap.u32Width;
+ s32BmCol < s_stOSDParam[RgnHdl].stMaxSize.u32Width; ++s32BmCol) {
+ HI_S32 s32BmDataIdx = s32BmRow * s_stOSDTextBitMap.stCanvasInfo.u32Stride / 2 + s32BmCol;
+ puBmData[s32BmDataIdx] = 0;
+ }
+ }
+
+ for (s32BmRow = pstContent->stBitmap.u32Height;
+ s32BmRow < s_stOSDParam[RgnHdl].stMaxSize.u32Height; ++s32BmRow) {
+ for (s32BmCol = 0; s32BmCol < s_stOSDParam[RgnHdl].stMaxSize.u32Width; ++s32BmCol) {
+ HI_S32 s32BmDataIdx = s32BmRow * s_stOSDTextBitMap.stCanvasInfo.u32Stride / 2 + s32BmCol;
+ puBmData[s32BmDataIdx] = 0;
+ }
+ }
+
+ return s32Ret;
+}
+
+static HI_S32 OSD_UpdateTextBitmap(RGN_HANDLE RgnHdl, HI_OSD_CONTENT_S* pstContent)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+
+ OSD_Generate_Bitmap(RgnHdl, pstContent);
+ s_stOSDTextBitMap.stCanvasInfo.enPixelFmt = PIXEL_FORMAT_ARGB_1555;
+ s_stOSDTextBitMap.stCanvasInfo.stSize.u32Width = pstContent->stBitmap.u32Width;
+ s_stOSDTextBitMap.stCanvasInfo.stSize.u32Height = pstContent->stBitmap.u32Height;
+
+ s32Ret = HI_MPI_RGN_UpdateCanvas(RgnHdl);
+ SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "RGN_UpdateCanvas FAIL, s32Ret=%x\n", s32Ret);
+
+ return s32Ret;
+}
+
+static HI_S32 OSD_RGNAttach(RGN_HANDLE RgnHdl, const HI_OSD_DISP_ATTR_S* pstDispAttr)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ RGN_CHN_ATTR_S stRgnChnAttr;
+ MPP_CHN_S stChn;
+
+ stChn.s32DevId = pstDispAttr->ModHdl;
+ stChn.s32ChnId = pstDispAttr->ChnHdl;
+ memset_s(&stRgnChnAttr, sizeof(RGN_CHN_ATTR_S), 0x0, sizeof(RGN_CHN_ATTR_S));
+ stRgnChnAttr.bShow = pstDispAttr->bShow;
+ stRgnChnAttr.enType = OVERLAYEX_RGN;
+ switch (pstDispAttr->enBindedMod) {
+ case HI_OSD_BINDMOD_VI:
+ stChn.enModId = HI_ID_VI;
+ break;
+ case HI_OSD_BINDMOD_VPSS:
+ stChn.enModId = HI_ID_VPSS;
+ break;
+ case HI_OSD_BINDMOD_VO:
+ stChn.enModId = HI_ID_VO;
+ break;
+ default:
+ SAMPLE_PRT("RgnHdl[%d] invalide bind mode [%d]\n", RgnHdl, pstDispAttr->enBindedMod);
+ return HI_EINVAL;
+ }
+
+ POINT_S stStartPos;
+ if (pstDispAttr->enCoordinate == HI_OSD_COORDINATE_RATIO_COOR) {
+ s32Ret = OSD_Ratio2Absolute(stChn, &pstDispAttr->stStartPos, &stStartPos);
+ SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "Ratio2Absolute FAIL, s32Ret=%x\n", s32Ret);
+ } else {
+ stStartPos = pstDispAttr->stStartPos;
+ }
+
+ if (stRgnChnAttr.enType == OVERLAYEX_RGN) {
+ stRgnChnAttr.unChnAttr.stOverlayExChn.stPoint.s32X = stStartPos.s32X;
+ stRgnChnAttr.unChnAttr.stOverlayExChn.stPoint.s32Y = stStartPos.s32Y;
+ stRgnChnAttr.unChnAttr.stOverlayExChn.u32BgAlpha = pstDispAttr->u32BgAlpha;
+ stRgnChnAttr.unChnAttr.stOverlayExChn.u32FgAlpha = pstDispAttr->u32FgAlpha;
+ stRgnChnAttr.unChnAttr.stOverlayExChn.u32Layer = 0;
+ } else {
+ stRgnChnAttr.unChnAttr.stOverlayChn.stPoint.s32X = stStartPos.s32X;
+ stRgnChnAttr.unChnAttr.stOverlayChn.stPoint.s32Y = stStartPos.s32Y;
+ stRgnChnAttr.unChnAttr.stOverlayChn.u32BgAlpha = pstDispAttr->u32BgAlpha;
+ stRgnChnAttr.unChnAttr.stOverlayChn.u32FgAlpha = pstDispAttr->u32FgAlpha;
+ stRgnChnAttr.unChnAttr.stOverlayChn.u32Layer = 0;
+ }
+
+ s32Ret = HI_MPI_RGN_AttachToChn(RgnHdl, &stChn, &stRgnChnAttr);
+ SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "RGN_AttachToChn FAIL, s32Ret=%x\n", s32Ret);
+
+ return HI_SUCCESS;
+}
+
+static HI_S32 OSD_CreateRGN(RGN_HANDLE RgnHdl, const HI_OSD_ATTR_S* pstAttr)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_S32 s32DispIdx = 0;
+ RGN_ATTR_S stRgnAttr;
+ stRgnAttr.enType = OVERLAY_RGN;
+
+ for (s32DispIdx = 0; s32DispIdx < pstAttr->u32DispNum ; ++s32DispIdx) {
+ if (pstAttr->astDispAttr[s32DispIdx].enBindedMod != HI_OSD_BINDMOD_VENC) {
+ stRgnAttr.enType = OVERLAYEX_RGN;
+ break;
+ }
+ }
+
+ if (stRgnAttr.enType == OVERLAYEX_RGN) {
+ stRgnAttr.unAttr.stOverlayEx.enPixelFmt = PIXEL_FORMAT_ARGB_1555;
+ stRgnAttr.unAttr.stOverlayEx.u32BgColor = pstAttr->stContent.u32Color;
+ stRgnAttr.unAttr.stOverlayEx.stSize.u32Width = pstAttr->stContent.stBitmap.u32Width;
+ stRgnAttr.unAttr.stOverlayEx.stSize.u32Height = pstAttr->stContent.stBitmap.u32Height;
+ stRgnAttr.unAttr.stOverlayEx.u32CanvasNum =
+ (HI_OSD_TYPE_BITMAP == pstAttr->stContent.enType) ? 1 : 2; // 2: u32CanvasNum
+ } else {
+ stRgnAttr.unAttr.stOverlay.enPixelFmt = PIXEL_FORMAT_ARGB_1555;
+ stRgnAttr.unAttr.stOverlay.u32BgColor = pstAttr->stContent.u32Color;
+ stRgnAttr.unAttr.stOverlay.stSize.u32Width = pstAttr->stContent.stBitmap.u32Width;
+ stRgnAttr.unAttr.stOverlay.stSize.u32Height = pstAttr->stContent.stBitmap.u32Height;
+ stRgnAttr.unAttr.stOverlay.u32CanvasNum =
+ (HI_OSD_TYPE_BITMAP == pstAttr->stContent.enType) ? 1 : 2; // 2: u32CanvasNum
+ }
+
+ s32Ret = HI_MPI_RGN_Create(RgnHdl, &stRgnAttr);
+ SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret,
+ "HI_MPI_RGN_Create fail,RgnHdl[%d] Error Code: [0x%08X]\n", RgnHdl, s32Ret);
+
+ if (pstAttr->stContent.enType == HI_OSD_TYPE_BITMAP) {
+ BITMAP_S stBitmap;
+ stBitmap.enPixelFormat = PIXEL_FORMAT_ARGB_1555;
+ stBitmap.u32Width = pstAttr->stContent.stBitmap.u32Width;
+ stBitmap.u32Height = pstAttr->stContent.stBitmap.u32Height;
+ stBitmap.pData = pstAttr->stContent.stBitmap.pvData;
+ s32Ret = HI_MPI_RGN_SetBitMap(RgnHdl, &stBitmap);
+ SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret,
+ "HI_MPI_RGN_SetBitMap fail,RgnHdl[%d] Error Code: [0x%08X]\n", RgnHdl, s32Ret);
+ } else {
+ s32Ret = OSD_UpdateTextBitmap(RgnHdl, (HI_OSD_CONTENT_S*)&pstAttr->stContent);
+ SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "UpdateTextBitmap fail, ret=%x\n", s32Ret);
+ }
+
+ for (s32DispIdx = 0; s32DispIdx < pstAttr->u32DispNum; ++s32DispIdx) {
+ if (pstAttr->astDispAttr[s32DispIdx].bShow) {
+ OSD_RGNAttach(RgnHdl, &pstAttr->astDispAttr[s32DispIdx]);
+ }
+ }
+
+ return HI_SUCCESS;
+}
+
+HI_VOID OSD_Update_Relate_Info(HI_S32 s32OsdIdx)
+{
+ HI_S32 s32Ret = 0;
+
+ for (s32OsdIdx = 0; s32OsdIdx < HI_OSD_MAX_CNT; ++s32OsdIdx) {
+ pthread_mutex_lock(&s_stOSDParam[s32OsdIdx].mutexLock);
+ if (s_stOSDParam[s32OsdIdx].stAttr.stContent.enType ==
+ HI_OSD_TYPE_TIME && s_stOSDParam[s32OsdIdx].bOn) {
+ /*
+ * 更新OSD时间字符串
+ * Update OSD Time String
+ */
+ OSD_GetTimeStr(&stTime,
+ s_stOSDParam[s32OsdIdx].stAttr.stContent.szStr, HI_OSD_MAX_STR_LEN);
+ /*
+ * 更新OSD文本位图
+ * Update OSD Text Bitmap
+ */
+ s32Ret = OSD_UpdateTextBitmap(s32OsdIdx, &s_stOSDParam[s32OsdIdx].stAttr.stContent);
+ if (HI_SUCCESS != s32Ret) {
+ pthread_mutex_unlock(&s_stOSDParam[s32OsdIdx].mutexLock);
+ SAMPLE_PRT("Update Text Bitmap failed\n");
+ continue;
+ }
+ /*
+ * 更新OSD属性
+ * Update OSD Attribute
+ */
+ s32Ret = OSD_Update(s32OsdIdx, &s_stOSDParam[s32OsdIdx].stAttr);
+ if (HI_SUCCESS != s32Ret) {
+ SAMPLE_PRT("Update Attribute failed\n");
+ }
+ }
+ pthread_mutex_unlock(&s_stOSDParam[s32OsdIdx].mutexLock);
+ }
+
+ return;
+}
+
+/*
+ * @brief 时间 osd 更新任务
+ * @param[in]pvParam : 不使用
+ * @return 0 成功,非零错误码
+ *
+ * @brief time osd update task
+ * @param[in]pvParam : nonuse
+ * @return 0 success, non-zero error code.
+ */
+static HI_VOID* OSD_TimeUpdate(HI_VOID* pvParam)
+{
+ HI_S32 s32Ret = 0;
+ HI_S32 s32OsdIdx = 0;
+ time_t nowTime = 0;
+ time_t lastTime = 0;
+ prctl(PR_SET_NAME, __FUNCTION__, 0, 0, 0);
+
+ while (s_bOSDTimeRun) {
+ nowTime = time(NULL); // also means time(&nowTime)
+ if (nowTime == lastTime) {
+ usleep(10000); // 10000:usleep time
+ continue;
+ } else {
+ localtime_r(&nowTime, &stTime);
+ OSD_Update_Relate_Info(s32OsdIdx);
+ lastTime = nowTime; /* update time */
+ }
+ usleep(500000); // 500000: usleep time
+ }
+
+ return NULL;
+}
+
+/*
+ * @brief osd模块初始化,例如:创建时间OSD更新任务
+ * @param[in] pstFonts:osd 字体库
+ * @return 0 成功,非零表示错误码
+ *
+ * @brief osd module initialization, eg. create time osd update task.
+ * @param[in] pstFonts:osd fonts lib
+ * @return 0 success, non-zero error code.
+ */
+HI_S32 HI_OSD_Init(const HI_OSD_FONTS_S* pstFonts)
+{
+ if (!(HI_TRUE != s_bOSDInitFlg)) {
+ return HI_EINITIALIZED;
+ }
+ if (pstFonts != NULL) {
+ if (!pstFonts->pfnGetFontMod) {
+ return HI_EINVAL;
+ }
+ if (pstFonts->u32FontWidth % BYTE_BITS) {
+ SAMPLE_PRT("FontWidth must be a multiple of %d.", BYTE_BITS);
+ return HI_EINVAL;
+ }
+ memcpy_s(&s_stOSDFonts, sizeof(HI_OSD_FONTS_S), pstFonts, sizeof(HI_OSD_FONTS_S));
+ } else {
+ memset_s(&s_stOSDFonts, sizeof(HI_OSD_FONTS_S), 0, sizeof(HI_OSD_FONTS_S));
+ }
+ HI_S32 s32Idx = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+
+ /*
+ * 初始化OSD参数
+ * Init OSD Param
+ */
+ for (s32Idx = 0; s32Idx < HI_OSD_MAX_CNT; ++s32Idx) {
+ pthread_mutex_init(&s_stOSDParam[s32Idx].mutexLock, NULL);
+ pthread_mutex_lock(&s_stOSDParam[s32Idx].mutexLock);
+ memset_s(&s_stOSDParam[s32Idx], sizeof(OSD_PARAM_S), 0, sizeof(OSD_PARAM_S));
+ pthread_mutex_unlock(&s_stOSDParam[s32Idx].mutexLock);
+ }
+
+ if (pstFonts != NULL) {
+ /*
+ * 创建时间OSD更新线程
+ * Create Time OSD Update Thread
+ */
+ s_bOSDTimeRun = HI_TRUE;
+ s32Ret = pthread_create(&s_OSDTimeTskId, NULL, OSD_TimeUpdate, NULL);
+ if (HI_SUCCESS != s32Ret) {
+ SAMPLE_PRT("create OSD_TimeUpdate failed:%s\n", strerror(errno));
+ return HI_ENORES;
+ }
+ }
+
+ s_bOSDInitFlg = HI_TRUE;
+ return HI_SUCCESS;
+}
+
+/*
+ * 初始化OSD字体
+ * Initialize OSD font
+ */
+static int OsdInitFont(HI_CHAR *character, HI_U8 **fontMod, HI_S32 *fontModLen)
+{
+ static const HI_CHAR baseChar = 0x20;
+
+ /*
+ * 获取ASCII字体库中的字体模组
+ * Get Font Mod in ASCII Fontlib
+ */
+ if (!character || !fontMod || !fontModLen) {
+ return HI_FAILURE;
+ }
+ /*
+ * 如果参数是ASCII字符则返回true,否则返回NULL(0)
+ * Return true if the parameter is an ASCII character, otherwise NULL (0)
+ */
+ if (!IsAscii(character[0])) {
+ return HI_FAILURE;
+ }
+ HI_U32 offset = (character[0] - baseChar) * (OSD_FONT_MOD_H * OSD_FONT_MOD_W / HI_BYTE_BITS);
+ *fontMod = (HI_U8 *)G_FONT_LIB + offset;
+ *fontModLen = OSD_FONT_MOD_H * OSD_FONT_MOD_W / HI_BYTE_BITS;
+ return HI_SUCCESS;
+}
+
+/*
+ * 初始化OsdSet库
+ * Initialize OsdSet lib
+ */
+int OsdLibInit(void)
+{
+ RecurMutexInit(&g_osdMutex);
+
+# if defined(OSD_FONT_HZK) || defined(OSD_FONT_ASC)
+ SAMPLE_PRT("==================success=================\n");
+ HI_OSD_FONTS_S stOsdFonts;
+ stOsdFonts.u32FontWidth = OSD_FONT_MOD_W;
+ stOsdFonts.u32FontHeight = OSD_FONT_MOD_H;
+ stOsdFonts.pfnGetFontMod = OsdInitFont;
+ return HI_OSD_Init(&stOsdFonts);
+# else
+ SAMPLE_PRT("##################success##################\n");
+ return HI_OSD_Init(NULL);
+# endif
+}
+
+HI_VOID Osd_Param_Config(const HI_OSD_ATTR_S* pstAttr, OSD_PARAM_S* pstOsdParam)
+{
+ /*
+ * 更新属性
+ * Update Attribute
+ */
+ pstOsdParam->stAttr.stContent.u32Color = pstAttr->stContent.u32Color;
+ pstOsdParam->stAttr.stContent.u32BgColor = pstAttr->stContent.u32BgColor;
+
+ if (HI_OSD_TYPE_BITMAP != pstAttr->stContent.enType) {
+ if (HI_OSD_TYPE_TIME == pstAttr->stContent.enType) {
+ /*
+ * 时间类型:更新时间字符串
+ * Time Type: Update time string
+ */
+ pstOsdParam->stAttr.stContent.enTimeFmt = pstAttr->stContent.enTimeFmt;
+ OSD_GetTimeStr(NULL, ((HI_OSD_ATTR_S*)pstAttr)->stContent.szStr, HI_OSD_MAX_STR_LEN);
+ }
+
+ /*
+ * 更新字符串
+ * Update string
+ */
+ if (snprintf_s(pstOsdParam->stAttr.stContent.szStr, HI_OSD_MAX_STR_LEN,
+ HI_OSD_MAX_STR_LEN - 1, "%s", pstAttr->stContent.szStr) < 0) {
+ HI_ASSERT(0);
+ }
+
+ pstOsdParam->stAttr.stContent.stBitmap.enPixelFormat = PIXEL_FORMAT_ARGB_1555;
+ ((HI_OSD_ATTR_S*)pstAttr)->stContent.stBitmap.u32Width =
+ pstAttr->stContent.stFontSize.u32Width * strnlen(pstOsdParam->stAttr.stContent.szStr, HI_OSD_MAX_STR_LEN);
+ ((HI_OSD_ATTR_S*)pstAttr)->stContent.stBitmap.u32Height= pstAttr->stContent.stFontSize.u32Height;
+ pstOsdParam->stAttr.stContent.stFontSize = pstAttr->stContent.stFontSize;
+ } else {
+ pstOsdParam->stAttr.stContent.stBitmap.enPixelFormat = pstAttr->stContent.stBitmap.enPixelFormat;
+ pstOsdParam->stAttr.stContent.stBitmap.u64PhyAddr = pstAttr->stContent.stBitmap.u64PhyAddr;
+ pstOsdParam->stAttr.stContent.stBitmap.pvData = pstAttr->stContent.stBitmap.pvData;
+ }
+ pstOsdParam->stAttr.stContent.stBitmap.u32Width = pstAttr->stContent.stBitmap.u32Width;
+ pstOsdParam->stAttr.stContent.stBitmap.u32Height = pstAttr->stContent.stBitmap.u32Height;
+ pstOsdParam->stAttr.stContent.enType = pstAttr->stContent.enType;
+
+ return;
+}
+
+static HI_S32 OSD_Update_RGN_Content(const HI_OSD_ATTR_S* pstAttr, OSD_PARAM_S* pstOsdParam, HI_S32 s32OsdIdx)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /*
+ * 更新RGN内容
+ * Update RGN Content
+ */
+ if (pstAttr->stContent.enType == HI_OSD_TYPE_BITMAP) {
+ BITMAP_S stBitmap;
+ stBitmap.enPixelFormat = PIXEL_FORMAT_ARGB_1555;
+ stBitmap.u32Width = pstAttr->stContent.stBitmap.u32Width;
+ stBitmap.u32Height = pstAttr->stContent.stBitmap.u32Height;
+ stBitmap.pData = pstAttr->stContent.stBitmap.pvData;
+ /*
+ * 设置区域位图,即对区域进行位图填充
+ * Set the area bitmap, that is, fill the area with a bitmap
+ */
+ s32Ret = HI_MPI_RGN_SetBitMap(s32OsdIdx, &stBitmap);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FAIL, "HI_MPI_RGN_SetBitMap. s32Ret: 0x%x\n", s32Ret);
+ } else {
+ /*
+ * 时间/字符串类型:更新文本位图
+ * Time/String Type: Update text bitmap
+ */
+ s32Ret = OSD_UpdateTextBitmap(s32OsdIdx, (HI_OSD_CONTENT_S*)&pstOsdParam->stAttr.stContent);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FAIL, "OSD_UpdateTextBitmap fail, err(%#x)\n", s32Ret);
+ }
+
+ HI_S32 s32DispIdx = 0;
+ for (s32DispIdx = 0; s32DispIdx < pstAttr->u32DispNum ; ++s32DispIdx) {
+ if (HI_TRUE == pstAttr->astDispAttr[s32DispIdx].bShow && HI_FALSE ==
+ pstOsdParam->stAttr.astDispAttr[s32DispIdx].bShow) {
+ OSD_RGNAttach(s32OsdIdx, &pstAttr->astDispAttr[s32DispIdx]);
+ } else if (HI_FALSE == pstAttr->astDispAttr[s32DispIdx].bShow && HI_TRUE ==
+ pstOsdParam->stAttr.astDispAttr[s32DispIdx].bShow) {
+ OSD_RGNDetach(s32OsdIdx, &pstOsdParam->stAttr.astDispAttr[s32DispIdx]);
+ }
+ }
+ s32Ret = OSD_Update(s32OsdIdx, pstAttr);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FAIL, "OSD_Update fail, err(%#x)\n", s32Ret);
+
+ return s32Ret;
+
+FAIL:
+ pthread_mutex_unlock(&pstOsdParam->mutexLock);
+ return s32Ret;
+}
+
+/*
+ * @brief 设置osd属性
+ * @param[in] s32OsdIdx:osd索引,范围[0,HI_OSD_MAX_CNT)
+ * @param[in] pstAttr:osd配置属性
+ * @return 0 成功,非零错误码
+ *
+ * @brief set osd attribute.
+ * @param[in] s32OsdIdx:osd index, range[0,HI_OSD_MAX_CNT)
+ * @param[in] pstAttr:osd configure attribute
+ * @return 0 success,non-zero error code.
+ */
+HI_S32 HI_OSD_SetAttr(HI_S32 s32OsdIdx, const HI_OSD_ATTR_S* pstAttr)
+{
+ /*
+ * 检查模块是否初始化成功
+ * Check Module Init or not
+ */
+ HI_ASSERT(HI_TRUE == s_bOSDInitFlg);
+ /*
+ * 检查输入的参数
+ * Check Input Param
+ */
+ HI_ASSERT(s32OsdIdx >= 0);
+ HI_ASSERT(HI_OSD_MAX_CNT > s32OsdIdx);
+ HI_ASSERT(pstAttr);
+ HI_ASSERT(HI_OSD_MAX_DISP_CNT >= pstAttr->u32DispNum);
+
+ if (HI_OSD_TYPE_BITMAP == pstAttr->stContent.enType) {
+ if (!pstAttr->stContent.stBitmap.pvData) {
+ return HI_FAILURE;
+ }
+ } else {
+ if (s_stOSDFonts.pfnGetFontMod == NULL) {
+ SAMPLE_PRT("The font library is not registered,only support bitmaps OSD\n");
+ return HI_FAILURE;
+ }
+ }
+
+ HI_S32 s32Ret = HI_SUCCESS;
+ OSD_PARAM_S* pstOsdParam = &s_stOSDParam[s32OsdIdx];
+ pthread_mutex_lock(&pstOsdParam->mutexLock);
+ HI_BOOL bOn = pstOsdParam->bOn;
+
+ /*
+ * 更新属性
+ * Update Attribute
+ */
+ Osd_Param_Config(pstAttr, pstOsdParam);
+ if (bOn) {
+ if (pstOsdParam->stMaxSize.u32Width < pstOsdParam->stAttr.stContent.stBitmap.u32Width
+ || pstOsdParam->stMaxSize.u32Height < pstOsdParam->stAttr.stContent.stBitmap.u32Height) {
+ SAMPLE_PRT("RGN(%d) size increase[%d,%d->%d,%d], rebuild\n", s32OsdIdx,
+ pstOsdParam->stMaxSize.u32Width, pstOsdParam->stMaxSize.u32Height,
+ pstAttr->stContent.stBitmap.u32Width, pstAttr->stContent.stBitmap.u32Height);
+ /*
+ * 销毁区域
+ * Destory region
+ */
+ s32Ret = OSD_DestroyRGN(s32OsdIdx, &pstOsdParam->stAttr);
+ if (s32Ret != HI_SUCCESS) {
+ pthread_mutex_unlock(&pstOsdParam->mutexLock);
+ return s32Ret;
+ }
+
+ s32Ret = OSD_CreateRGN(s32OsdIdx, pstAttr);
+ if (s32Ret != HI_SUCCESS) {
+ pthread_mutex_unlock(&pstOsdParam->mutexLock);
+ return s32Ret;
+ }
+ } else {
+ OSD_Update_RGN_Content(pstAttr, pstOsdParam, s32OsdIdx);
+ }
+ }
+
+ memcpy_s(pstOsdParam->stAttr.astDispAttr, sizeof(HI_OSD_DISP_ATTR_S) * HI_OSD_MAX_DISP_CNT,
+ pstAttr->astDispAttr, sizeof(HI_OSD_DISP_ATTR_S) * HI_OSD_MAX_DISP_CNT);
+ pstOsdParam->stAttr.u32DispNum = pstAttr->u32DispNum;
+ pstOsdParam->stMaxSize.u32Width =
+ max(pstOsdParam->stMaxSize.u32Width, pstOsdParam->stAttr.stContent.stBitmap.u32Width);
+ pstOsdParam->stMaxSize.u32Height=
+ max(pstOsdParam->stMaxSize.u32Height, pstOsdParam->stAttr.stContent.stBitmap.u32Height);
+ pstOsdParam->bInit = HI_TRUE;
+ pthread_mutex_unlock(&pstOsdParam->mutexLock);
+
+ return HI_SUCCESS;
+}
+
+static HI_S32 OSD_Start(HI_S32 s32OsdIdx)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ OSD_PARAM_S* pstOsdParam = &s_stOSDParam[s32OsdIdx];
+
+ /*
+ * 时间OSD:更新时间字符串和位图
+ * Time OSD: Update time string and bitmap
+ */
+ if (HI_OSD_TYPE_TIME == pstOsdParam->stAttr.stContent.enType) {
+ OSD_GetTimeStr(NULL, pstOsdParam->stAttr.stContent.szStr, HI_OSD_MAX_STR_LEN);
+ }
+
+ s32Ret = OSD_CreateRGN(s32OsdIdx, &pstOsdParam->stAttr);
+ if (HI_SUCCESS != s32Ret) {
+ SAMPLE_PRT("OSD_CreateRGN s32OsdIdx[%d] failed:[0x%08X]\n", s32OsdIdx, s32Ret);
+ return s32Ret;
+ }
+ pstOsdParam->bOn = HI_TRUE;
+ return HI_SUCCESS;
+}
+
+/*
+ * @brief 按索引启动 osd
+ * @param[in] s32OsdIdx:osd 索引,范围[0,HI_OSD_MAX_CNT)
+ * @return 0 成功,非零错误码
+ *
+ * @brief start osd by index.
+ * @param[in] s32OsdIdx:osd index, range[0,HI_OSD_MAX_CNT)
+ * @return 0 success,non-zero error code.
+ */
+HI_S32 HI_OSD_Start(HI_S32 s32OsdIdx)
+{
+ /*
+ * 检查模块是否初始化成功
+ * Check Module Init or not
+ */
+ HI_ASSERT(HI_TRUE == s_bOSDInitFlg);
+ /*
+ * 检查输入的参数
+ * Check Input Param
+ */
+ HI_ASSERT(s32OsdIdx >= 0);
+ HI_ASSERT(HI_OSD_MAX_CNT > s32OsdIdx);
+
+ HI_S32 s32Ret = HI_SUCCESS;
+ OSD_PARAM_S* pstOsdParam = &s_stOSDParam[s32OsdIdx];
+
+ pthread_mutex_lock(&pstOsdParam->mutexLock);
+
+ /*
+ * 检查OSD属性是否初始化
+ * Check OSD Attrbute init or not
+ */
+ if (!pstOsdParam->bInit) {
+ pthread_mutex_unlock(&pstOsdParam->mutexLock);
+ SAMPLE_PRT("OSD[%d] not init yet!\n", s32OsdIdx);
+ return HI_EINVAL;
+ }
+
+ /*
+ * 检查OSD是否停止
+ * Check OSD stop or not
+ */
+ if (pstOsdParam->bOn) {
+ pthread_mutex_unlock(&pstOsdParam->mutexLock);
+ SAMPLE_PRT("OSD[%d] has already started!\n", s32OsdIdx);
+ return HI_SUCCESS;
+ }
+
+ s32Ret = OSD_Start(s32OsdIdx);
+ pthread_mutex_unlock(&pstOsdParam->mutexLock);
+ return s32Ret;
+}
+
+/*
+ * 在OsdSet中设置指定区域的属性
+ * Set attributes for the specified region in OsdSet
+ */
+int OsdsSetRgn(OsdSet* self, int rgnHnd, const HI_OSD_ATTR_S* rgnAttr)
+{
+ HI_ASSERT(self);
+ HI_ASSERT(rgnHnd >= 0 && rgnHnd < HI_OSD_MAX_CNT);
+ HI_ASSERT(g_osdHndPool[rgnHnd] && g_osdHndPool[rgnHnd] == (void*)self); // not need lock
+ HI_OSD_ATTR_S attr;
+ int ret;
+
+ if (!rgnAttr) { // hidden the region
+ if (memset_s(&attr, sizeof(attr), 0, sizeof(attr)) != EOK) {
+ HI_ASSERT(0);
+ }
+ attr.u32DispNum = 1;
+ attr.astDispAttr[0].bShow = HI_FALSE;
+ } else {
+ attr = *rgnAttr;
+ }
+
+ attr.astDispAttr[0].enBindedMod = self->bindMod;
+ attr.astDispAttr[0].ModHdl = self->modHnd;
+ attr.astDispAttr[0].ChnHdl = self->chnHnd;
+
+ ret = HI_OSD_SetAttr(rgnHnd, &attr);
+ SAMPLE_CHECK_EXPR_RET(ret, "HI_OSD_SetAttr FAIL, ret=%d\n", ret);
+
+ ret = HI_OSD_Start(rgnHnd);
+ SAMPLE_CHECK_EXPR_RET(ret, "HI_OSD_Start FAIL, ret=%d\n", ret);
+ return 0;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* End of #ifdef __cplusplus */
\ No newline at end of file
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/src/vgs_img.c b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/src/vgs_img.c
new file mode 100644
index 0000000000000000000000000000000000000000..5de8570b8a8186dab48a817267f2fa45505fa44e
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/mpp_help/src/vgs_img.c
@@ -0,0 +1,493 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include
+#include
+
+#include "hi_comm_vb.h"
+#include "hi_comm_vgs.h"
+#include "hi_comm_region.h"
+#include "mpi_sys.h"
+#include "mpi_vgs.h"
+#include "hi_buffer.h"
+
+#include "misc_util.h"
+#include "ai_infer_process.h"
+#include "vgs_img.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* End of #ifdef __cplusplus */
+
+#define VGS_MAX_LINE 100 // The maximum number of lines for a superimposed graphics operation
+#define RECT_LINES 4 // The number of lines in a rectangle
+
+#define RECT_LINE1 1
+#define RECT_LINE2 2
+#define RECT_LINE3 3
+
+/*
+ * 设置帧的buffer
+ * Set the buf of the frame
+ */
+static void MppFrmSetBuf(VIDEO_FRAME_INFO_S* frm,
+ const VB_CAL_CONFIG_S *vbCfg, HI_U64 phyAddr, uint8_t *virAddr)
+{
+ /*
+ * 目前只支持SP422/SP420,不支持SP444
+ * Currently only SP422/SP420 is supported, SP444 is not supported
+ */
+ frm->stVFrame.u32HeaderStride[0] = vbCfg->u32HeadStride;
+ frm->stVFrame.u32HeaderStride[1] = vbCfg->u32HeadStride;
+ frm->stVFrame.u32HeaderStride[2] = vbCfg->u32HeadStride; // 2: Array subscript, not out of bounds
+ frm->stVFrame.u64HeaderPhyAddr[0] = phyAddr;
+ frm->stVFrame.u64HeaderPhyAddr[1] = frm->stVFrame.u64HeaderPhyAddr[0] + vbCfg->u32HeadYSize;
+ frm->stVFrame.u64HeaderPhyAddr[2] = frm->stVFrame.u64HeaderPhyAddr[1]; // 2: Array subscript, not out of bounds
+ frm->stVFrame.u64HeaderVirAddr[0] = (HI_U64)(HI_UL)virAddr;
+ frm->stVFrame.u64HeaderVirAddr[1] = frm->stVFrame.u64HeaderVirAddr[0] + vbCfg->u32HeadYSize;
+ frm->stVFrame.u64HeaderVirAddr[2] = frm->stVFrame.u64HeaderVirAddr[1]; // 2: Array subscript, not out of bounds
+
+ frm->stVFrame.u32Stride[0] = vbCfg->u32MainStride;
+ frm->stVFrame.u32Stride[1] = vbCfg->u32MainStride;
+ frm->stVFrame.u32Stride[2] = vbCfg->u32MainStride; // 2: Array subscript, not out of bounds
+ frm->stVFrame.u64PhyAddr[0] = frm->stVFrame.u64HeaderPhyAddr[0] + vbCfg->u32HeadSize;
+ frm->stVFrame.u64PhyAddr[1] = frm->stVFrame.u64PhyAddr[0] + vbCfg->u32MainYSize;
+ frm->stVFrame.u64PhyAddr[2] = frm->stVFrame.u64PhyAddr[1]; // 2: Array subscript, not out of bounds
+ frm->stVFrame.u64VirAddr[0] = frm->stVFrame.u64HeaderVirAddr[0] + vbCfg->u32HeadSize;
+ frm->stVFrame.u64VirAddr[1] = frm->stVFrame.u64VirAddr[0] + vbCfg->u32MainYSize;
+ frm->stVFrame.u64VirAddr[2] = frm->stVFrame.u64VirAddr[1]; // 2: Array subscript, not out of bounds
+}
+
+/*
+ * 创建一个空的frame buf.
+ * 它根据参数的规格计算frame所需空间,为frame分配内存.
+ * @param frm[in|out]: 若成功,创建的frame信息会复制到frm.
+ * @param width[in]: frame width.
+ * @param height[in]: frame height.
+ * @param pixelFormat[in]: 置为-1表示取默认值PIXEL_FORMAT_YVU_SEMIPLANAR_420.
+ * @param bitWidth[in]: 置为-1表示取默认值DATA_BITWIDTH_8.
+ * @param compressMode[in]: 置为-1表示取默认值COMPRESS_MODE_NONE.
+ * @param align[in]: 对齐的字节长度. 置为-1表示取默认值'自动对齐'.
+ *
+ * Create an empty frame buf.
+ * It calculates the space required by the frame according to the parameter specification,
+ * and allocates memory for the frame.
+ * @param frm[in|out]: If successful, the created frame information will be copied to frm.
+ * @param width[in]: frame width.
+ * @param height[in]: frame height.
+ * @param pixelFormat[in]: Set to -1 means to take the default value PIXEL_FORMAT_YVU_SEMIPLANAR_420.
+ * @param bitWidth[in]: Set to -1 means to take the default value DATA_BITWIDTH_8.
+ * @param compressMode[in]: Set to -1 means to take the default value COMPRESS_MODE_NONE.
+ * @param align[in]: The byte length of the alignment. Set to -1 to take the default value 'automatic alignment'.
+ */
+int MppFrmCreate(
+ VIDEO_FRAME_INFO_S* frm,
+ int width, int height,
+ PIXEL_FORMAT_E pixelFormat,
+ DATA_BITWIDTH_E bitWidth,
+ COMPRESS_MODE_E compressMode,
+ int align)
+{
+ HI_ASSERT(frm);
+ VB_CAL_CONFIG_S vbCfg;
+
+ if (memset_s(frm, sizeof(*frm), 0, sizeof(*frm)) != EOK) {
+ HI_ASSERT(0);
+ }
+
+ HI_ASSERT(width > 0 && height > 0);
+ if ((int)pixelFormat < 0) {
+ pixelFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
+ }
+ if ((int)bitWidth < 0) {
+ bitWidth = DATA_BITWIDTH_8;
+ }
+ if ((int)compressMode < 0) {
+ compressMode = COMPRESS_MODE_NONE;
+ }
+ if (align < 0) {
+ HI_ASSERT(0);
+ }
+
+ COMMON_GetPicBufferConfig(width, height, pixelFormat, bitWidth, compressMode, align, &vbCfg);
+
+ VB_BLK vbHnd = HI_MPI_VB_GetBlock(VB_INVALID_POOLID, vbCfg.u32VBSize, NULL);
+ if (vbHnd == VB_INVALID_HANDLE) {
+ SAMPLE_PRT("HI_MPI_VB_GetBlock FAIL\n");
+ return HI_FAILURE;
+ }
+
+ HI_U64 phyAddr = HI_MPI_VB_Handle2PhysAddr(vbHnd);
+ HI_ASSERT(phyAddr);
+ uint8_t* virAddr = (uint8_t*)HI_MPI_SYS_Mmap(phyAddr, vbCfg.u32VBSize);
+ HI_ASSERT(virAddr);
+
+ /*
+ * u64PrivateData用来存储映射的内存区长度和vbHnd,在destroy时会用到
+ *
+ * u64PrivateData is used to store the length of the mapped memory area and vbHnd,
+ * which will be used when destroying
+ */
+ frm->stVFrame.u64PrivateData = ((uint64_t)(uint32_t)vbHnd) << HI_INT32_BITS;
+ frm->stVFrame.u64PrivateData |= (uint64_t)vbCfg.u32VBSize;
+
+ frm->enModId = HI_ID_VGS;
+ frm->u32PoolId = HI_MPI_VB_Handle2PoolId(vbHnd);
+
+ frm->stVFrame.u32Width = width;
+ frm->stVFrame.u32Height = height;
+ frm->stVFrame.enField = VIDEO_FIELD_FRAME;
+ frm->stVFrame.enPixelFormat = pixelFormat;
+ frm->stVFrame.enVideoFormat = VIDEO_FORMAT_LINEAR;
+ frm->stVFrame.enCompressMode = compressMode;
+ frm->stVFrame.enDynamicRange = DYNAMIC_RANGE_SDR8;
+ frm->stVFrame.enColorGamut = COLOR_GAMUT_BT601;
+
+ MppFrmSetBuf(frm, &vbCfg, phyAddr, virAddr);
+ return HI_SUCCESS;
+}
+
+/*
+ * 判断frame是否可用, 即是否分配了内存
+ * Determine whether the frame is available, That is, whether the memory is allocated
+ */
+bool MppFrmValid(const VIDEO_FRAME_INFO_S* frm)
+{
+ /*
+ * VPSS输出的frame默认没有映射虚地址
+ * The frame output by VPSS does not map virtual addresses by default
+ */
+ return frm->stVFrame.u64PhyAddr[0];
+}
+
+/*
+ * 销毁frame
+ * Destory frame
+ */
+void MppFrmDestroy(VIDEO_FRAME_INFO_S* frm)
+{
+ if (!MppFrmValid(frm)) {
+ return;
+ }
+
+ /*
+ * u64PrivateData被用来存储映射的内存区长度和vbHnd,在创建时设置
+ * u64PrivateData is used to store the length of the mapped memory area and vbHnd, which is set at create
+ */
+ uint32_t memSize = (uint32_t)(frm->stVFrame.u64PrivateData);
+ uint32_t vbHnd = (uint32_t)(frm->stVFrame.u64PrivateData >> HI_INT32_BITS);
+ HI_S32 ret;
+
+ ret = HI_MPI_SYS_Munmap((void*)(uintptr_t)frm->stVFrame.u64VirAddr[0], memSize);
+ HI_ASSERT(ret == HI_SUCCESS);
+ ret = HI_MPI_VB_ReleaseBlock(vbHnd);
+ HI_ASSERT(ret == HI_SUCCESS);
+ if (memset_s(frm, sizeof(*frm), 0, sizeof(*frm)) != EOK) {
+ HI_ASSERT(0);
+ }
+}
+
+/*
+ * 执行一次VGS缩放
+ * 每一次VGS resize的缩放倍数是有限制的. VGS支持对一幅图像进行缩放,最大支持图像
+ * 宽高均放大16倍,缩小30 倍。支持单分量(Y)缩放
+ *
+ * Perform a VGS resize.
+ * The zoom factor of each VGS resize is limited. VGS supports zooming of an image.
+ * The width and height are both enlarged by 16 times and reduced by 30 times.Support single-component (Y) scaling.
+ */
+static int VgsResizeOnce(const VIDEO_FRAME_INFO_S* src, VIDEO_FRAME_INFO_S* dst, uint32_t dstWidth, uint32_t dstHeight)
+{
+ HI_ASSERT(src && dst);
+ HI_ASSERT(dstWidth > 0 && dstHeight > 0);
+ VGS_HANDLE jobHnd = -1;
+ VGS_TASK_ATTR_S task;
+ int ret;
+
+ ret = MppFrmCreate(dst, dstWidth, dstHeight, src->stVFrame.enPixelFormat, DATA_BITWIDTH_8,
+ src->stVFrame.enCompressMode, 0);
+ if (ret != 0) {
+ SAMPLE_PRT("frm resize FAIL, for create dstFrm FAIL\n");
+ return ret;
+ }
+
+ if (memset_s(&task, sizeof(task), 0, sizeof(task)) != EOK) {
+ HI_ASSERT(0);
+ }
+ task.stImgIn = *src;
+ task.stImgOut = *dst;
+
+ ret = HI_MPI_VGS_BeginJob(&jobHnd);
+ if (ret != 0) {
+ SAMPLE_PRT("HI_MPI_VGS_BeginJob FAIL, ret=%08X\n", ret);
+ if (jobHnd >= 0 && HI_MPI_VGS_CancelJob(jobHnd) != HI_SUCCESS) {
+ HI_ASSERT(0);
+ }
+ MppFrmDestroy(dst);
+ return ret;
+ }
+ HI_ASSERT(jobHnd >= 0);
+
+ ret = HI_MPI_VGS_AddScaleTask(jobHnd, &task, VGS_SCLCOEF_NORMAL);
+ if (ret != 0) {
+ SAMPLE_PRT("HI_MPI_VGS_AddScaleTask FAIL, ret=%08X\n", ret);
+ if (jobHnd >= 0 && HI_MPI_VGS_CancelJob(jobHnd) != HI_SUCCESS) {
+ HI_ASSERT(0);
+ }
+ MppFrmDestroy(dst);
+ return ret;
+ }
+
+ ret = HI_MPI_VGS_EndJob(jobHnd);
+ if (ret != 0) {
+ SAMPLE_PRT("HI_MPI_VGS_EndJob FAIL, ret=%08X\n", ret);
+ if (jobHnd >= 0 && HI_MPI_VGS_CancelJob(jobHnd) != HI_SUCCESS) {
+ HI_ASSERT(0);
+ }
+ MppFrmDestroy(dst);
+ return ret;
+ }
+ return 0;
+}
+
+/*
+ * 对一帧实现缩放
+ * 多次调用vgs_resize以实现任意比例的缩放
+ * 为简化实现,约定每次缩放最大14倍,此时宽、高仅需2像素对齐
+ * 当两个方向缩放方向不同时,例如一向(如X)放大,另一向缩小倍,无需特别处理
+ * 此时某个方向或两个方向缩放比例均超标,也不需要特别处理
+ *
+ * resize frame.
+ * Call vgs_resize multiple times to achieve arbitrary scaling.
+ * In order to simplify the implementation, it is agreed that each zoom is up to 14 times,
+ * and at this time, the width and height only need to be aligned by 2 pixels.
+ * When the zooming direction of the two directions is different, for example,
+ * zooming in one direction (such as X) and zooming out in the other direction, no special processing is required
+ * At this time, the zoom ratio in one direction or both directions exceeds the standard,
+ * and no special treatment is required.
+ */
+int MppFrmResize(
+ const VIDEO_FRAME_INFO_S* src,
+ VIDEO_FRAME_INFO_S* dst,
+ uint32_t dstWidth, uint32_t dstHeight)
+{
+ static const double rateMax = 14.0; // Maximum magnification
+ static const double rateMin = 1.0 / rateMax; // The smallest magnification, that is, the largest reduction
+
+ uint32_t srcWidth = src->stVFrame.u32Width;
+ uint32_t srcHeight = src->stVFrame.u32Height;
+ HI_ASSERT(srcWidth > 0 && srcHeight > 0);
+ HI_ASSERT(!(srcWidth % HI_OVEN_BASE) && !(srcHeight % HI_OVEN_BASE));
+ HI_ASSERT(dstWidth > 0 && dstHeight > 0);
+ HI_ASSERT(!(dstWidth % HI_OVEN_BASE) && !(dstHeight % HI_OVEN_BASE));
+ int ret;
+
+ /*
+ * 放大倍数
+ * magnification
+ */
+ double widthRate = ((double)dstWidth) / (double)srcWidth; // >1 means zoom in, <1 means zoom out
+ double heightRate = ((double)dstHeight) / (double)srcHeight; // >1 means zoom in, <1 means zoom out
+
+ /*
+ * 根据缩放倍数分别处理
+ * Separate processing according to zoom factor
+ */
+ if (widthRate > rateMax || widthRate < rateMin ||
+ heightRate > rateMax || heightRate < rateMin) {
+ /*
+ * 缩放倍数超过一次VGS的最大值时,递归处理 ...
+ * When the zoom factor exceeds the maximum value of one VGS, recursive processing...
+ */
+ uint32_t midWidth = (uint32_t)IntZoomTo((int)srcWidth, widthRate, rateMin, rateMax);
+ uint32_t midHeight = (uint32_t)IntZoomTo((int)srcHeight, heightRate, rateMin, rateMax);
+ /*
+ * 确保为偶数。为奇数时,放大则减一,否则加一
+ *
+ * Make sure it is an even number. When it is an odd number,
+ * the zoom is reduced by one, otherwise it is increased by one
+ */
+ if (midWidth % HI_OVEN_BASE) {
+ midWidth += widthRate > 1 ? -1 : 1;
+ }
+ if (midHeight % HI_OVEN_BASE) {
+ midHeight += heightRate > 1 ? -1 : 1;
+ }
+
+ SAMPLE_PRT("@@@ multi-lev vgs resize, src={%u, %u}, mid={%u, %u}, dst={%u, %u}, rate={%.4f, %.4f}\n",
+ srcWidth, srcHeight, midWidth, midHeight, dstWidth, dstHeight, widthRate, heightRate);
+
+ /*
+ * 缩放一次
+ * Zoom once
+ */
+ VIDEO_FRAME_INFO_S midFrm;
+ ret = VgsResizeOnce(src, &midFrm, midWidth, midHeight);
+ if (ret != 0) {
+ SAMPLE_PRT("VgsResizeOnce(dw=%u, dh=%u) FAIL\n", midWidth, midHeight);
+ return ret;
+ }
+
+ /*
+ * 以midFrm为src递归调用
+ * Recursively call with midFrm as src
+ */
+ ret = MppFrmResize(&midFrm, dst, dstWidth, dstHeight);
+ MppFrmDestroy(&midFrm);
+ if (ret != 0) {
+ SAMPLE_PRT("sub call MppFrmResize(dw=%u, dh=%u) FAIL\n", dstWidth, dstHeight);
+ return ret;
+ }
+ } else {
+ /*
+ * 缩放倍数未超过一次VGS的最大值,直接完成
+ * The zoom factor does not exceed the maximum value of VGS once, and it is done directly
+ */
+ ret = VgsResizeOnce(src, dst, dstWidth, dstHeight);
+ if (ret != 0) {
+ SAMPLE_PRT("VgsResizeOnce(dw=%u, dh=%u) FAIL\n", dstWidth, dstHeight);
+ return ret;
+ }
+ }
+ return ret;
+}
+
+/*
+ * 将整数向上修整为偶数
+ * Round up integers to even numbers
+ */
+static inline int IntToOven(int x)
+{
+ if (x % HI_OVEN_BASE == 0) {
+ return x;
+ } else {
+ return x + 1;
+ }
+}
+
+/*
+ * 创建并执行VGS画线任务
+ * Create and execute VGS draw lines job
+ */
+static HI_S32 VgsDrawLines(VIDEO_FRAME_INFO_S *frm, const VGS_DRAW_LINE_S lines[], int lineNum)
+{
+ VGS_HANDLE jobHnd = -1;
+ VGS_TASK_ATTR_S task;
+ int ret;
+
+ if (memset_s(&task, sizeof(task), 0, sizeof(task)) != EOK) {
+ HI_ASSERT(0);
+ }
+ task.stImgIn = *frm;
+ task.stImgOut = *frm;
+
+ /*
+ * 启动一个job
+ * Start a job
+ */
+ ret = HI_MPI_VGS_BeginJob(&jobHnd);
+ if (ret != 0) {
+ SAMPLE_PRT("HI_MPI_VGS_BeginJob FAIL, ret=%08X\n", ret);
+ if (jobHnd >= 0 && HI_MPI_VGS_CancelJob(jobHnd) != HI_SUCCESS) {
+ HI_ASSERT(0);
+ }
+ return ret;
+ }
+ HI_ASSERT(jobHnd >= 0);
+
+ /*
+ * 往一个已经启动的job里添加批量画线task
+ * Add a batch line drawing task to an already started job
+ */
+ ret = HI_MPI_VGS_AddDrawLineTaskArray(jobHnd, &task, lines, lineNum);
+ if (ret != 0) {
+ SAMPLE_PRT("HI_MPI_VGS_AddDrawLineTaskArray FAIL, ret=%08X\n", ret);
+ if (jobHnd >= 0 && HI_MPI_VGS_CancelJob(jobHnd) != HI_SUCCESS) {
+ HI_ASSERT(0);
+ }
+ return ret;
+ }
+
+ /*
+ * 提交一个job
+ * Submit a job
+ */
+ ret = HI_MPI_VGS_EndJob(jobHnd);
+ if (ret != 0) {
+ SAMPLE_PRT("HI_MPI_VGS_EndJob FAIL, ret=%08X\n", ret);
+ if (jobHnd >= 0 && HI_MPI_VGS_CancelJob(jobHnd) != HI_SUCCESS) {
+ HI_ASSERT(0);
+ }
+ return ret;
+ }
+ return 0;
+}
+
+/*
+ * 在frame中叠加一个或多个矩形框
+ * Superimpose one or more rectangular boxes in the frame
+ */
+int MppFrmDrawRects(VIDEO_FRAME_INFO_S *frm,
+ const RectBox *boxes, int boxesNum, uint32_t color, int thick)
+{
+ VGS_DRAW_LINE_S lines[VGS_MAX_LINE];
+ int i;
+
+ if (thick <= 0) {
+ HI_ASSERT(0);
+ }
+
+ /*
+ * 将各矩形四边平面化为lines
+ * Planarize the four sides of each rectangle into lines
+ */
+ for (i = 0; i < boxesNum; i++) {
+ lines[RECT_LINES * i].stStartPoint.s32X = IntToOven(boxes[i].xmin);
+ lines[RECT_LINES * i].stStartPoint.s32Y = IntToOven(boxes[i].ymin);
+ lines[RECT_LINES * i].stEndPoint.s32X = IntToOven(boxes[i].xmax);
+ lines[RECT_LINES * i].stEndPoint.s32Y = IntToOven(boxes[i].ymin);
+ lines[RECT_LINES * i].u32Color = color;
+ lines[RECT_LINES * i].u32Thick = thick;
+ lines[RECT_LINES * i + RECT_LINE1].stStartPoint.s32X = IntToOven(boxes[i].xmax);
+ lines[RECT_LINES * i + RECT_LINE1].stStartPoint.s32Y = IntToOven(boxes[i].ymin);
+ lines[RECT_LINES * i + RECT_LINE1].stEndPoint.s32X = IntToOven(boxes[i].xmax);
+ lines[RECT_LINES * i + RECT_LINE1].stEndPoint.s32Y = IntToOven(boxes[i].ymax);
+ lines[RECT_LINES * i + RECT_LINE1].u32Color = color;
+ lines[RECT_LINES * i + RECT_LINE1].u32Thick = thick;
+ lines[RECT_LINES * i + RECT_LINE2].stStartPoint.s32X = IntToOven(boxes[i].xmax);
+ lines[RECT_LINES * i + RECT_LINE2].stStartPoint.s32Y = IntToOven(boxes[i].ymax);
+ lines[RECT_LINES * i + RECT_LINE2].stEndPoint.s32X = IntToOven(boxes[i].xmin);
+ lines[RECT_LINES * i + RECT_LINE2].stEndPoint.s32Y = IntToOven(boxes[i].ymax);
+ lines[RECT_LINES * i + RECT_LINE2].u32Color = color;
+ lines[RECT_LINES * i + RECT_LINE2].u32Thick = thick;
+ lines[RECT_LINES * i + RECT_LINE3].stStartPoint.s32X = IntToOven(boxes[i].xmin);
+ lines[RECT_LINES * i + RECT_LINE3].stStartPoint.s32Y = IntToOven(boxes[i].ymax);
+ lines[RECT_LINES * i + RECT_LINE3].stEndPoint.s32X = IntToOven(boxes[i].xmin);
+ lines[RECT_LINES * i + RECT_LINE3].stEndPoint.s32Y = IntToOven(boxes[i].ymin);
+ lines[RECT_LINES * i + RECT_LINE3].u32Color = color;
+ lines[RECT_LINES * i + RECT_LINE3].u32Thick = thick;
+ }
+ return VgsDrawLines(frm, lines, i * RECT_LINES);
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* End of #ifdef __cplusplus */
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/nnie/BUILD.gn b/AIOT/10274_Intelligent AD Analysis System/code/nnie/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..04eeb8fbbb992dd567fa268d073b57e278b031da
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/nnie/BUILD.gn
@@ -0,0 +1,141 @@
+# Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/lite/config/component/lite_component.gni")
+lite_component("hi3516dv300_nnie_sample") {
+ features = [ ":ohos_nnie_demo" ]
+}
+
+need_link_mpp_lib = true
+if (need_link_mpp_lib) {
+ mpp_lib_path = "//device/soc/hisilicon/hi3516dv300/sdk_linux/out"
+}
+
+executable("ohos_nnie_demo") {
+ output_name = "ohos_nnie_demo"
+ sources = [
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/common/loadbmp.c",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/common/sample_comm_audio.c",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/common/sample_comm_isp.c",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/common/sample_comm_region.c",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/common/sample_comm_sys.c",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/common/sample_comm_venc.c",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/common/sample_comm_vi.c",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/common/sample_comm_vo.c",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/common/sample_comm_vpss.c",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/svp/common/sample_comm_ive.c",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/svp/common/sample_comm_nnie.c",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/svp/common/sample_comm_svp.c",
+ "sample/sample_nnie.c",
+ "sample_nnie_main.c",
+ "sample_nnie_software/sample_svp_nnie_software.c",
+ ]
+
+ include_dirs = [
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/include",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/drv/mpp/cbb/include",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/drv/mpp/cbb/init",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/mpp/include",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/common",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/svp/common",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/svp/nnie/sample",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/svp/nnie/sample_nnie_software",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/vio/",
+ "//device/soc/hisilicon/hi3516dv300/sdk_linux/sample/platform/audio/adp",
+ "//third_party/bounds_checking_function/include",
+ ]
+
+ defines = [
+ "SENSOR0_TYPE=SONY_IMX335_MIPI_4M_30FPS_12BIT",
+ "SENSOR1_TYPE=SONY_IMX335_MIPI_4M_30FPS_12BIT",
+ ]
+
+ if (need_link_mpp_lib) {
+ outdir = rebase_path("$mpp_lib_path/lib")
+ ldflags = [ "-L$outdir" ]
+ ldflags += [ "-laaccomm" ]
+ ldflags += [ "-laacdec" ]
+ ldflags += [ "-laacenc" ]
+ ldflags += [ "-laacsbrdec" ]
+ ldflags += [ "-laacsbrenc" ]
+ ldflags += [ "-ldnvqe" ]
+ ldflags += [ "-lhdmi" ]
+ ldflags += [ "-lhi3516cv500_acodec" ]
+ ldflags += [ "-lhi3516cv500_adec" ]
+ ldflags += [ "-lhi3516cv500_aenc" ]
+ ldflags += [ "-lhi3516cv500_aio" ]
+ ldflags += [ "-lhi3516cv500_ai" ]
+ ldflags += [ "-lhi3516cv500_ao" ]
+ ldflags += [ "-lhi3516cv500_base" ]
+ ldflags += [ "-lhi3516cv500_chnl" ]
+ ldflags += [ "-lhi3516cv500_dis" ]
+ ldflags += [ "-lhi3516cv500_gdc" ]
+ ldflags += [ "-lhi3516cv500_h264e" ]
+ ldflags += [ "-lhi3516cv500_h265e" ]
+ ldflags += [ "-lhi3516cv500_isp" ]
+ ldflags += [ "-lhi3516cv500_ive" ]
+ ldflags += [ "-lhi3516cv500_jpegd" ]
+ ldflags += [ "-lhi3516cv500_jpege" ]
+ ldflags += [ "-lhi3516cv500_nnie" ]
+ ldflags += [ "-lhi3516cv500_rc" ]
+ ldflags += [ "-lhi3516cv500_rgn" ]
+ ldflags += [ "-lhi3516cv500_sys" ]
+ ldflags += [ "-lhi3516cv500_vdec" ]
+ ldflags += [ "-lhi3516cv500_vedu" ]
+ ldflags += [ "-lhi3516cv500_venc" ]
+ ldflags += [ "-lhi3516cv500_vfmw" ]
+ ldflags += [ "-lhi3516cv500_vgs" ]
+ ldflags += [ "-lhi3516cv500_vi" ]
+ ldflags += [ "-lhi3516cv500_vo" ]
+ ldflags += [ "-lhi3516cv500_vpss" ]
+ ldflags += [ "-l_hiacs" ]
+ ldflags += [ "-l_hiae" ]
+ ldflags += [ "-l_hiawb_natura" ]
+ ldflags += [ "-l_hiawb" ]
+ ldflags += [ "-l_hicalcflicker" ]
+ ldflags += [ "-l_hidehaze" ]
+ ldflags += [ "-l_hidrc" ]
+ ldflags += [ "-lhifisheyecalibrate" ]
+ ldflags += [ "-l_hiir_auto" ]
+ ldflags += [ "-lhi_irq" ]
+ ldflags += [ "-l_hildci" ]
+ ldflags += [ "-lhi_osal" ]
+ ldflags += [ "-lhi_sensor_i2c" ]
+ ldflags += [ "-lhive_AEC" ]
+ ldflags += [ "-lhive_AGC" ]
+ ldflags += [ "-lhive_ANR" ]
+ ldflags += [ "-lhive_common" ]
+ ldflags += [ "-lhive_EQ" ]
+ ldflags += [ "-lhive_HPF" ]
+ ldflags += [ "-lhive_record" ]
+ ldflags += [ "-lhive_RES_ext" ]
+ ldflags += [ "-lhive_RES" ]
+ ldflags += [ "-lhive_talkv2" ]
+ ldflags += [ "-lhive_wnr" ]
+ ldflags += [ "-lisp" ]
+ ldflags += [ "-live" ]
+ ldflags += [ "-lmd" ]
+ ldflags += [ "-lmpi" ]
+ ldflags += [ "-lmpp_vbs" ]
+ ldflags += [ "-lnnie" ]
+ ldflags += [ "-lsdk" ]
+ ldflags += [ "-lsecurec" ]
+ ldflags += [ "-lsns_imx335" ]
+ ldflags += [ "-ltde" ]
+ ldflags += [ "-lupvqe" ]
+ ldflags += [ "-lvb_server" ]
+ ldflags += [ "-lVoiceEngine" ]
+
+ deps = []
+ }
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample/sample_nnie.c b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample/sample_nnie.c
new file mode 100644
index 0000000000000000000000000000000000000000..cd465cc044820b28fe760382e989cda6e773cfaa
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample/sample_nnie.c
@@ -0,0 +1,5410 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include "hi_common.h"
+#include "hi_comm_sys.h"
+#include "hi_comm_svp.h"
+#include "sample_comm.h"
+#include "sample_comm_svp.h"
+#include "sample_comm_nnie.h"
+#include "sample_nnie_main.h"
+#include "sample_svp_nnie_software.h"
+#include "sample_comm_ive.h"
+#include "vgs_img.h"
+#include "misc_util.h"
+#include "osd_img.h"
+#include "base_interface.h"
+
+#include "hi_debug.h"
+#include "hi_comm_ive.h"
+
+#define THRESH_MIN 0.4
+#define ARRAY_SUBSCRIPT_OFFSET_1 1
+#define ARRAY_SUBSCRIPT_OFFSET_2 2
+#define ARRAY_SUBSCRIPT_OFFSET_3 3
+#define DETECT_OBJ_MAX 32
+#define DRAW_RETC_THICK 2 // Draw the width of the line
+#define ARRAY_SUBSCRIPT_0 0
+#define ARRAY_SUBSCRIPT_1 1
+#define ARRAY_SUBSCRIPT_2 2
+#define ARRAY_SUBSCRIPT_3 3
+#define ARRAY_SUBSCRIPT_4 4
+#define ARRAY_SUBSCRIPT_5 5
+#define ARRAY_SUBSCRIPT_6 6
+#define ARRAY_SUBSCRIPT_7 7
+#define ARRAY_SUBSCRIPT_8 8
+#define ARRAY_SUBSCRIPT_9 9
+
+#define ARGB1555_YELLOW2 0xFF00 // 1 11111 11111 00000
+#define ARGB1555_BLUE 0x801F // 1 00000 00000 11111
+#define ARGB1555_BLACK 0x8000 // 1 00000 00000 00000
+#define ARGB1555_RED 0xFC00 // 1 11111 00000 00000
+#define TXT_BEGX 20
+#define TXT_BEGY 20
+
+#define IMG_FULL_CHN 3 // Full channel / three channel, for YUV444, RGB888
+
+static DetectObjInfo objs[DETECT_OBJ_MAX] = {0};
+static RectBox boxs[DETECT_OBJ_MAX] = {0};
+static RectBox remainingBoxs[DETECT_OBJ_MAX] = {0};
+static VIDEO_FRAME_INFO_S *dstFrm;
+static RectBox BoxsIDprint[DETECT_OBJ_MAX] = {0};
+
+static hi_bool g_stop_signal = HI_FALSE;
+/* cnn para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stCnnModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stCnnNnieParam = { 0 };
+static SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S s_stCnnSoftwareParam = { 0 };
+/* segment para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stSegnetModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stSegnetNnieParam = { 0 };
+/* fasterrcnn para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stFasterRcnnModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stFasterRcnnNnieParam = { 0 };
+static SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S s_stFasterRcnnSoftwareParam = { 0 };
+static SAMPLE_SVP_NNIE_NET_TYPE_E s_enNetType;
+/* rfcn para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stRfcnModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stRfcnNnieParam = { 0 };
+static SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S s_stRfcnSoftwareParam = { 0 };
+static SAMPLE_IVE_SWITCH_S s_stRfcnSwitch = { HI_FALSE, HI_FALSE };
+static HI_BOOL s_bNnieStopSignal = HI_FALSE;
+static pthread_t s_hNnieThread = 0;
+static SAMPLE_VI_CONFIG_S s_stViConfig = { 0 };
+
+/* ssd para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stSsdModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stSsdNnieParam = { 0 };
+static SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S s_stSsdSoftwareParam = { 0 };
+/* yolov1 para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stYolov1Model = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stYolov1NnieParam = { 0 };
+static SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S s_stYolov1SoftwareParam = { 0 };
+/* yolov2 para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stYolov2Model = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stYolov2NnieParam = { 0 };
+static SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S s_stYolov2SoftwareParam = { 0 };
+/* yolov3 para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stYolov3Model = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stYolov3NnieParam = { 0 };
+static SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S s_stYolov3SoftwareParam = { 0 };
+/* lstm para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stLstmModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stLstmNnieParam = { 0 };
+/* pvanet para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stPvanetModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stPvanetNnieParam = { 0 };
+static SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S s_stPvanetSoftwareParam = { 0 };
+
+/*yolov3 para*/
+static SAMPLE_IVE_SWITCH_S s_stYolov3Switch = {HI_FALSE,HI_FALSE};
+
+/*yolov2 para*/
+static SAMPLE_IVE_SWITCH_S s_stYolov2Switch = {HI_FALSE,HI_FALSE};
+/*print on screen(OSD)*/
+static OsdSet* g_osdsPerson = NULL;
+static HI_S32 g_osd0Person = -1;
+static HI_S32 g_osd_Person_ID[DETECT_OBJ_MAX];
+//memset_s(g_osd_Person_ID, sizeof(HI_S32)*DETECT_OBJ_MAX, -1, sizeof(HI_S32)*DETECT_OBJ_MAX); //或用0xFF
+/*track*/
+static HI_U32 ID_num_total=0; //被跟踪的总人数
+static HI_FLOAT focused_time_total=0.0;//人群注意力总时长
+// static HI_BOOL accumulate_first_flag=HI_FALSE;
+
+/* function : NNIE Forward */
+/*
+ * 获取结果
+ * Fetch result
+ */
+static void Yolo2FetchRes(SVP_BLOB_S *pstDstScore, SVP_BLOB_S *pstDstRoi, SVP_BLOB_S *pstClassRoiNum,
+ DetectObjInfo resBuf[], int resSize, int* resLen)
+{
+ HI_U32 i;
+ HI_U32 j;
+ HI_U32 u32RoiNumBias = 0;
+ HI_U32 u32ScoreBias;
+ HI_U32 u32BboxBias;
+ HI_FLOAT f32Score;
+ HI_S32* ps32Score = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstScore->u64VirAddr);
+ HI_S32* ps32Roi = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstRoi->u64VirAddr);
+ HI_S32* ps32ClassRoiNum = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstClassRoiNum->u64VirAddr);
+ HI_U32 u32ClassNum = pstClassRoiNum->unShape.stWhc.u32Width;
+
+ HI_ASSERT(u32ClassNum == 3); // 2: the number of class
+ HI_ASSERT(resSize > 0);
+ int current_cls =1;
+ int resId = 0;
+ *resLen = 0;
+ memset_s(resBuf, resSize * sizeof(resBuf[0]), 0x00, resSize * sizeof(resBuf[0]));
+
+ u32RoiNumBias += ps32ClassRoiNum[0];
+ for (i = 1; i < u32ClassNum; i++) {
+ current_cls = i;
+ u32ScoreBias = u32RoiNumBias;
+ u32BboxBias = u32RoiNumBias * SAMPLE_SVP_NNIE_COORDI_NUM;
+ /*
+ * 如果置信度分数大于结果阈值,则打印结果
+ * If the confidence score greater than result threshold, the result will be printed
+ */
+ if ((HI_FLOAT)ps32Score[u32ScoreBias] / SAMPLE_SVP_NNIE_QUANT_BASE >=
+ THRESH_MIN && ps32ClassRoiNum[i] != 0) {
+ }
+ for (j = 0; j < (HI_U32)ps32ClassRoiNum[i]; j++) {
+ f32Score = (HI_FLOAT)ps32Score[u32ScoreBias + j] / SAMPLE_SVP_NNIE_QUANT_BASE;
+ if (f32Score < THRESH_MIN) {
+ SAMPLE_PRT("f32Score:%.2f\n", f32Score);
+ break;
+ }
+ if (resId >= resSize) {
+ SAMPLE_PRT("yolo2 resBuf full\n");
+ break;
+ }
+ resBuf[resId].cls = current_cls; // class 1
+ resBuf[resId].score = f32Score;
+
+ RectBox *box = &resBuf[resId].box;
+ box->xmin = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM];
+ box->ymin = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + ARRAY_SUBSCRIPT_OFFSET_1];
+ box->xmax = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + ARRAY_SUBSCRIPT_OFFSET_2];
+ box->ymax = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + ARRAY_SUBSCRIPT_OFFSET_3];
+ if (box->xmin >= box->xmax || box->ymin >= box->ymax) {
+ // SAMPLE_PRT("yolo1_orig: {%d, %d, %d, %d}, discard for coord ERR\n",
+ // box->xmin, box->ymin, box->xmax, box->ymax);
+ } else {
+ resId++;
+ }
+ }
+ u32RoiNumBias += ps32ClassRoiNum[i];
+ }
+
+ *resLen = resId;
+}
+
+static HI_S32 SAMPLE_SVP_NNIE_Forward(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S *pstInputDataIdx, SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S *pstProcSegIdx,
+ HI_BOOL bInstant)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 i, j;
+ HI_BOOL bFinish = HI_FALSE;
+ SVP_NNIE_HANDLE hSvpNnieHandle = 0;
+ HI_U32 u32TotalStepNum = 0;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(pstProcSegIdx->u32SegIdx >= pstNnieParam->pstModel->u32NetSegNum ||
+ pstInputDataIdx->u32SegIdx >= pstNnieParam->pstModel->u32NetSegNum ||
+ pstNnieParam->pstModel->u32NetSegNum > SVP_NNIE_MAX_NET_SEG_NUM,
+ HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstProcSegIdx->u32SegIdx(%u) and pstInputDataIdx->u32SegIdx(%u) "
+ "should be less than %u, pstNnieParam->pstModel->u32NetSegNum(%u) can't be greater than %u!\n",
+ pstProcSegIdx->u32SegIdx, pstInputDataIdx->u32SegIdx, pstNnieParam->pstModel->u32NetSegNum,
+ pstNnieParam->pstModel->u32NetSegNum, SVP_NNIE_MAX_NET_SEG_NUM);
+
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u64VirAddr),
+ pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u32Size);
+
+ for (i = 0; i < pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].u32DstNum; i++) {
+ if (pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].enType == SVP_BLOB_TYPE_SEQ_S32) {
+ for (j = 0; j < pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num; j++) {
+ u32TotalStepNum += *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stSeq.u64VirAddrStep) +
+ j);
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ u32TotalStepNum * pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ } else {
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Chn *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Height *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ }
+ }
+
+ /* set input blob according to node name */
+ if (pstInputDataIdx->u32SegIdx != pstProcSegIdx->u32SegIdx) {
+ for (i = 0; i < pstNnieParam->pstModel->astSeg[pstProcSegIdx->u32SegIdx].u16SrcNum; i++) {
+ for (j = 0; j < pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].u16DstNum; j++) {
+ if (strncmp(pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].astDstNode[j].szName,
+ pstNnieParam->pstModel->astSeg[pstProcSegIdx->u32SegIdx].astSrcNode[i].szName,
+ SVP_NNIE_NODE_NAME_LEN) == 0) {
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astSrc[i] =
+ pstNnieParam->astSegData[pstInputDataIdx->u32SegIdx].astDst[j];
+ break;
+ }
+ }
+ SAMPLE_SVP_CHECK_EXPR_RET((j == pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].u16DstNum),
+ HI_FAILURE, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,can't find %d-th seg's %d-th src blob!\n",
+ pstProcSegIdx->u32SegIdx, i);
+ }
+ }
+
+ /* NNIE_Forward */
+ s32Ret = HI_MPI_SVP_NNIE_Forward(&hSvpNnieHandle, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astSrc,
+ pstNnieParam->pstModel, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst,
+ &pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx], bInstant);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,HI_MPI_SVP_NNIE_Forward failed!\n");
+
+ if (bInstant) {
+ /* Wait NNIE finish */
+ while (HI_ERR_SVP_NNIE_QUERY_TIMEOUT == (s32Ret = HI_MPI_SVP_NNIE_Query(
+ pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].enNnieId, hSvpNnieHandle, &bFinish, HI_TRUE))) {
+ usleep(100); /* sleep 100 micro_seconds */
+ SAMPLE_SVP_TRACE(SAMPLE_SVP_ERR_LEVEL_INFO, "HI_MPI_SVP_NNIE_Query Query timeout!\n");
+ }
+ }
+ u32TotalStepNum = 0;
+ for (i = 0; i < pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].u32DstNum; i++) {
+ if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].enType) {
+ for (j = 0; j < pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num; j++) {
+ u32TotalStepNum += *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stSeq.u64VirAddrStep) +
+ j);
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ u32TotalStepNum * pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ } else {
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Chn *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Height *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ }
+ }
+
+ return s32Ret;
+}
+
+/* function : NNIE ForwardWithBbox */
+static HI_S32 SAMPLE_SVP_NNIE_ForwardWithBbox(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S *pstInputDataIdx, SVP_SRC_BLOB_S astBbox[],
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S *pstProcSegIdx, HI_BOOL bInstant)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_BOOL bFinish = HI_FALSE;
+ SVP_NNIE_HANDLE hSvpNnieHandle = 0;
+ HI_U32 u32TotalStepNum = 0;
+ HI_U32 i, j;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(pstProcSegIdx->u32SegIdx >= pstNnieParam->pstModel->u32NetSegNum ||
+ pstInputDataIdx->u32SegIdx >= pstNnieParam->pstModel->u32NetSegNum ||
+ pstNnieParam->pstModel->u32NetSegNum > SVP_NNIE_MAX_NET_SEG_NUM,
+ HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstProcSegIdx->u32SegIdx(%u) and pstInputDataIdx->u32SegIdx(%u) "
+ "should be less than %u, pstNnieParam->pstModel->u32NetSegNum(%u) should be less than %u!\n",
+ pstProcSegIdx->u32SegIdx, pstInputDataIdx->u32SegIdx, pstNnieParam->pstModel->u32NetSegNum,
+ pstNnieParam->pstModel->u32NetSegNum, SVP_NNIE_MAX_NET_SEG_NUM);
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u64VirAddr),
+ pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u32Size);
+
+ for (i = 0; i < pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].u32DstNum; i++) {
+ if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].enType) {
+ for (j = 0; j < pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num; j++) {
+ u32TotalStepNum += *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stSeq.u64VirAddrStep) +
+ j);
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ u32TotalStepNum * pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ } else {
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Chn *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Height *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ }
+ }
+
+ /* set input blob according to node name */
+ if (pstInputDataIdx->u32SegIdx != pstProcSegIdx->u32SegIdx) {
+ for (i = 0; i < pstNnieParam->pstModel->astSeg[pstProcSegIdx->u32SegIdx].u16SrcNum; i++) {
+ for (j = 0; j < pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].u16DstNum; j++) {
+ if (strncmp(pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].astDstNode[j].szName,
+ pstNnieParam->pstModel->astSeg[pstProcSegIdx->u32SegIdx].astSrcNode[i].szName,
+ SVP_NNIE_NODE_NAME_LEN) == 0) {
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astSrc[i] =
+ pstNnieParam->astSegData[pstInputDataIdx->u32SegIdx].astDst[j];
+ break;
+ }
+ }
+ SAMPLE_SVP_CHECK_EXPR_RET((j == pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].u16DstNum),
+ HI_FAILURE, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,can't find %d-th seg's %d-th src blob!\n",
+ pstProcSegIdx->u32SegIdx, i);
+ }
+ }
+ /* NNIE_ForwardWithBbox */
+ s32Ret = HI_MPI_SVP_NNIE_ForwardWithBbox(&hSvpNnieHandle, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astSrc,
+ astBbox, pstNnieParam->pstModel, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst,
+ &pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx], bInstant);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,HI_MPI_SVP_NNIE_ForwardWithBbox failed!\n");
+
+ if (bInstant) {
+ /* Wait NNIE finish */
+ while (HI_ERR_SVP_NNIE_QUERY_TIMEOUT ==
+ (s32Ret = HI_MPI_SVP_NNIE_Query(pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].enNnieId,
+ hSvpNnieHandle, &bFinish, HI_TRUE))) {
+ usleep(100); /* sleep 100 micro_seconds */
+ SAMPLE_SVP_TRACE(SAMPLE_SVP_ERR_LEVEL_INFO, "HI_MPI_SVP_NNIE_Query Query timeout!\n");
+ }
+ }
+ u32TotalStepNum = 0;
+
+ for (i = 0; i < pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].u32DstNum; i++) {
+ if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].enType) {
+ for (j = 0; j < pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num; j++) {
+ u32TotalStepNum += *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stSeq.u64VirAddrStep) +
+ j);
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ u32TotalStepNum * pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ } else {
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Chn *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Height *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ }
+ }
+
+ return s32Ret;
+}
+
+/* function : Fill Src Data */
+static HI_S32 SAMPLE_SVP_NNIE_FillSrcData(SAMPLE_SVP_NNIE_CFG_S *pstNnieCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S *pstInputDataIdx)
+{
+ FILE *fp = NULL;
+ HI_U32 i = 0, j = 0, n = 0;
+ HI_U32 u32Height = 0, u32Width = 0, u32Chn = 0, u32Stride = 0, u32Dim = 0;
+ HI_U32 u32VarSize = 0;
+ HI_U8 *pu8PicAddr = NULL;
+ HI_U32 *pu32StepAddr = NULL;
+ HI_U32 u32SegIdx = pstInputDataIdx->u32SegIdx;
+ HI_U32 u32NodeIdx = pstInputDataIdx->u32NodeIdx;
+ HI_U32 u32TotalStepNum = 0;
+ HI_ULONG ulSize;
+ HI_CHAR path[PATH_MAX] = {0};
+
+ /* open file */
+ SAMPLE_SVP_CHECK_EXPR_RET(pstNnieCfg->pszPic == HI_NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstNnieCfg->pszPic is null!\n");
+ SAMPLE_SVP_CHECK_EXPR_RET(pstInputDataIdx->u32SegIdx >= SVP_NNIE_MAX_NET_SEG_NUM, HI_INVALID_VALUE,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error, u32SegIdx should be less than %u!\n", SVP_NNIE_MAX_NET_SEG_NUM);
+ SAMPLE_SVP_CHECK_EXPR_RET(pstInputDataIdx->u32NodeIdx >= SVP_NNIE_MAX_INPUT_NUM, HI_INVALID_VALUE,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error, u32NodeIdx should be less than %u!\n", SVP_NNIE_MAX_INPUT_NUM);
+
+ SAMPLE_SVP_CHECK_EXPR_RET((strlen(pstNnieCfg->pszPic) > PATH_MAX) ||
+ (realpath(pstNnieCfg->pszPic, path) == HI_NULL),
+ HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error, file_name is invalid!\n");
+ fp = fopen(path, "rb");
+ SAMPLE_SVP_CHECK_EXPR_RET(fp == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error, open file failed!\n");
+
+ /* get data size */
+ if (SVP_BLOB_TYPE_U8 <= pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType &&
+ SVP_BLOB_TYPE_YVU422SP >= pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType) {
+ u32VarSize = sizeof(HI_U8);
+ } else {
+ u32VarSize = sizeof(HI_U32);
+ }
+
+ /* fill src data */
+ if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType) {
+ u32Dim = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].unShape.stSeq.u32Dim;
+ u32Stride = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Stride;
+ pu32StepAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].unShape.stSeq.u64VirAddrStep);
+ pu8PicAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U8,
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64VirAddr);
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < *(pu32StepAddr + n); i++) {
+ ulSize = fread(pu8PicAddr, u32Dim * u32VarSize, 1, fp);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(ulSize != 1, FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Read image file failed!\n");
+ pu8PicAddr += u32Stride;
+ }
+ u32TotalStepNum += *(pu32StepAddr + n);
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64VirAddr),
+ u32TotalStepNum * u32Stride);
+ } else {
+ u32Height = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].unShape.stWhc.u32Height;
+ u32Width = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].unShape.stWhc.u32Width;
+ u32Chn = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].unShape.stWhc.u32Chn;
+ u32Stride = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Stride;
+ pu8PicAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U8,
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64VirAddr);
+ if (SVP_BLOB_TYPE_YVU420SP == pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType) {
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < u32Chn * u32Height / 2; i++) { /* Brightness: 1 height, Chroma: 1/2 height */
+ ulSize = fread(pu8PicAddr, u32Width * u32VarSize, 1, fp);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(ulSize != 1, FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Read image file failed!\n");
+ pu8PicAddr += u32Stride;
+ }
+ }
+ } else if (SVP_BLOB_TYPE_YVU422SP == pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType) {
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < u32Height * 2; i++) { /* Brightness: 1 height, Chroma: 1 height */
+ ulSize = fread(pu8PicAddr, u32Width * u32VarSize, 1, fp);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(ulSize != 1, FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Read image file failed!\n");
+ pu8PicAddr += u32Stride;
+ }
+ }
+ } else {
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < u32Chn; i++) {
+ for (j = 0; j < u32Height; j++) {
+ ulSize = fread(pu8PicAddr, u32Width * u32VarSize, 1, fp);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(ulSize != 1, FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Read image file failed!\n");
+ pu8PicAddr += u32Stride;
+ }
+ }
+ }
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64VirAddr),
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num * u32Chn * u32Height * u32Stride);
+ }
+
+ (HI_VOID)fclose(fp);
+ return HI_SUCCESS;
+FAIL:
+
+ (HI_VOID)fclose(fp);
+ return HI_FAILURE;
+}
+
+/* function : print report result */
+static HI_S32 SAMPLE_SVP_NNIE_PrintReportResult(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam)
+{
+ HI_U32 u32SegNum = pstNnieParam->pstModel->u32NetSegNum;
+ HI_U32 i = 0, j = 0, k = 0, n = 0;
+ HI_U32 u32SegIdx = 0, u32NodeIdx = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_CHAR acReportFileName[SAMPLE_SVP_NNIE_REPORT_NAME_LENGTH] = {'\0'};
+ FILE *fp = NULL;
+ HI_U32 *pu32StepAddr = NULL;
+ HI_S32 *ps32ResultAddr = NULL;
+ HI_U32 u32Height = 0, u32Width = 0, u32Chn = 0, u32Stride = 0, u32Dim = 0;
+
+ for (u32SegIdx = 0; u32SegIdx < u32SegNum; u32SegIdx++) {
+ for (u32NodeIdx = 0; u32NodeIdx < pstNnieParam->pstModel->astSeg[u32SegIdx].u16DstNum; u32NodeIdx++) {
+ s32Ret = snprintf_s(acReportFileName, SAMPLE_SVP_NNIE_REPORT_NAME_LENGTH,
+ SAMPLE_SVP_NNIE_REPORT_NAME_LENGTH - 1, "seg%d_layer%d_output%d_inst.linear.hex", u32SegIdx,
+ pstNnieParam->pstModel->astSeg[u32SegIdx].astDstNode[u32NodeIdx].u32NodeId, 0);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret < 0, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,create file name failed!\n");
+
+ fp = fopen(acReportFileName, "w");
+ SAMPLE_SVP_CHECK_EXPR_RET(fp == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,open file failed!\n");
+
+ if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].enType) {
+ u32Dim = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].unShape.stSeq.u32Dim;
+ u32Stride = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u32Stride;
+ pu32StepAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].unShape.stSeq.u64VirAddrStep);
+ ps32ResultAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,
+ pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u64VirAddr);
+
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < *(pu32StepAddr + n); i++) {
+ for (j = 0; j < u32Dim; j++) {
+ s32Ret = fprintf(fp, "%08x\n", *(ps32ResultAddr + j));
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret < 0, PRINT_FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,write report result file failed!\n");
+ }
+ ps32ResultAddr += u32Stride / sizeof(HI_U32);
+ }
+ }
+ } else {
+ u32Height = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].unShape.stWhc.u32Height;
+ u32Width = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].unShape.stWhc.u32Width;
+ u32Chn = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].unShape.stWhc.u32Chn;
+ u32Stride = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u32Stride;
+ ps32ResultAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,
+ pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u64VirAddr);
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < u32Chn; i++) {
+ for (j = 0; j < u32Height; j++) {
+ for (k = 0; k < u32Width; k++) {
+ s32Ret = fprintf(fp, "%08x\n", *(ps32ResultAddr + k));
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret < 0, PRINT_FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,write report result file failed!\n");
+ }
+ ps32ResultAddr += u32Stride / sizeof(HI_U32);
+ }
+ }
+ }
+ }
+ (HI_VOID)fclose(fp);
+ }
+ }
+ return HI_SUCCESS;
+
+PRINT_FAIL:
+ (HI_VOID)fclose(fp);
+ return HI_FAILURE;
+}
+
+/* function : Cnn software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Cnn_SoftwareDeinit(SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S *pstCnnSoftWarePara)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstCnnSoftWarePara == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstCnnSoftWarePara can't be NULL!\n");
+ if ((pstCnnSoftWarePara->stGetTopN.u64PhyAddr != 0) && (pstCnnSoftWarePara->stGetTopN.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstCnnSoftWarePara->stGetTopN.u64PhyAddr, pstCnnSoftWarePara->stGetTopN.u64VirAddr);
+ pstCnnSoftWarePara->stGetTopN.u64PhyAddr = 0;
+ pstCnnSoftWarePara->stGetTopN.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Cnn Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Cnn_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware para deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software para deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Cnn_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Cnn software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Cnn_SoftwareParaInit(SAMPLE_SVP_NNIE_CFG_S *pstNnieCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstCnnPara, SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S *pstCnnSoftWarePara)
+{
+ HI_U32 u32GetTopNMemSize = 0;
+ HI_U32 u32GetTopNAssistBufSize = 0;
+ HI_U32 u32GetTopNPerFrameSize = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32ClassNum = pstCnnPara->pstModel->astSeg[0].astDstNode[0].unShape.stWhc.u32Width;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U64 u64Tmp;
+
+ /* get mem size */
+ u64Tmp = (HI_U64)pstCnnSoftWarePara->u32TopN * sizeof(SAMPLE_SVP_NNIE_CNN_GETTOPN_UNIT_S);
+ SAMPLE_SVP_CHECK_EXPR_RET(u64Tmp > SAMPLE_SVP_NNIE_MAX_MEM, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,u64Tmp should be less than %u!\n", SAMPLE_SVP_NNIE_MAX_MEM);
+ u32GetTopNPerFrameSize = (HI_U32)u64Tmp;
+
+ u64Tmp = SAMPLE_SVP_NNIE_ALIGN16(u32GetTopNPerFrameSize) * (HI_U64)pstNnieCfg->u32MaxInputNum;
+ SAMPLE_SVP_CHECK_EXPR_RET(u64Tmp > SAMPLE_SVP_NNIE_MAX_MEM, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,u64Tmp should be less than %u!\n", SAMPLE_SVP_NNIE_MAX_MEM);
+ u32GetTopNMemSize = (HI_U32)u64Tmp;
+
+ u64Tmp = (HI_U64)u32ClassNum * sizeof(SAMPLE_SVP_NNIE_CNN_GETTOPN_UNIT_S);
+ SAMPLE_SVP_CHECK_EXPR_RET(u64Tmp > SAMPLE_SVP_NNIE_MAX_MEM, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,u64Tmp should be less than %u!\n", SAMPLE_SVP_NNIE_MAX_MEM);
+ u32GetTopNAssistBufSize = (HI_U32)u64Tmp;
+
+ SAMPLE_SVP_CHECK_EXPR_RET((HI_U64)u32GetTopNMemSize + u32GetTopNAssistBufSize > SAMPLE_SVP_NNIE_MAX_MEM,
+ HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,total size should be less than %u!\n",
+ SAMPLE_SVP_NNIE_MAX_MEM);
+ u32TotalSize = u32GetTopNMemSize + u32GetTopNAssistBufSize;
+
+ /* malloc mem */
+ s32Ret =
+ SAMPLE_COMM_SVP_MallocMem("SAMPLE_CNN_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr, u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+
+ /* init GetTopn */
+ pstCnnSoftWarePara->stGetTopN.u32Num = pstNnieCfg->u32MaxInputNum;
+ pstCnnSoftWarePara->stGetTopN.unShape.stWhc.u32Chn = 1;
+ pstCnnSoftWarePara->stGetTopN.unShape.stWhc.u32Height = 1;
+ pstCnnSoftWarePara->stGetTopN.unShape.stWhc.u32Width = u32GetTopNPerFrameSize / sizeof(HI_U32);
+ pstCnnSoftWarePara->stGetTopN.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32GetTopNPerFrameSize);
+ pstCnnSoftWarePara->stGetTopN.u64PhyAddr = u64PhyAddr;
+ pstCnnSoftWarePara->stGetTopN.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr);
+
+ /* init AssistBuf */
+ pstCnnSoftWarePara->stAssistBuf.u32Size = u32GetTopNAssistBufSize;
+ pstCnnSoftWarePara->stAssistBuf.u64PhyAddr = u64PhyAddr + u32GetTopNMemSize;
+ pstCnnSoftWarePara->stAssistBuf.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32GetTopNMemSize;
+
+ return s32Ret;
+}
+
+/* function : Cnn init */
+static HI_S32 SAMPLE_SVP_NNIE_Cnn_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstNnieCfg, SAMPLE_SVP_NNIE_PARAM_S *pstCnnPara,
+ SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S *pstCnnSoftWarePara)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstNnieCfg, pstCnnPara);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software para */
+ if (pstCnnSoftWarePara != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_SoftwareParaInit(pstNnieCfg, pstCnnPara, pstCnnSoftWarePara);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Cnn_SoftwareParaInit failed!\n", s32Ret);
+ }
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_Deinit(pstCnnPara, pstCnnSoftWarePara, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Cnn_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+
+/* function : Cnn process */
+static HI_S32 SAMPLE_SVP_NNIE_Cnn_PrintResult(SVP_BLOB_S *pstGetTopN, HI_U32 u32TopN)
+{
+ HI_U32 i, j;
+ HI_U32 *pu32Tmp = NULL;
+ HI_U32 u32Stride;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstGetTopN == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,pstGetTopN can't be NULL!\n");
+
+ u32Stride = pstGetTopN->u32Stride;
+ for (j = 0; j < pstGetTopN->u32Num; j++) {
+ SAMPLE_SVP_TRACE_INFO("==== The %dth image info====\n", j);
+ pu32Tmp = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, ((HI_UL)pstGetTopN->u64VirAddr + j * u32Stride));
+ for (i = 0; i < u32TopN * 2; i += 2) { /* leave a space */
+ SAMPLE_SVP_TRACE_INFO("%d:%d\n", pu32Tmp[i], pu32Tmp[i + 1]);
+ }
+ }
+ return HI_SUCCESS;
+}
+static hi_void SAMPLE_SVP_NNIE_Cnn_Stop(void)
+{
+ SAMPLE_SVP_NNIE_Cnn_Deinit(&s_stCnnNnieParam, &s_stCnnSoftwareParam, &s_stCnnModel);
+ (HI_VOID)memset_s(&s_stCnnNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stCnnSoftwareParam, sizeof(SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stCnnModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show Cnn sample(image 28x28 U8_C1) */
+void SAMPLE_SVP_NNIE_Cnn(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/y/0_28x28.y";
+ const HI_CHAR *pcModelName = "./data/nnie_model/classification/inst_mnist_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ s_stCnnSoftwareParam.u32TopN = 5; /* to get 5 highest results */
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Cnn_Stop();
+ return;
+ }
+
+ /* CNN Load model */
+ SAMPLE_SVP_TRACE_INFO("Cnn Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stCnnModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* CNN parameter initialization */
+ /* Cnn software parameters are set in SAMPLE_SVP_NNIE_Cnn_SoftwareParaInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Cnn_SoftwareParaInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Cnn parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Cnn_Stop();
+ return;
+ }
+ s_stCnnNnieParam.pstModel = &s_stCnnModel.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_ParamInit(&stNnieCfg, &s_stCnnNnieParam, &s_stCnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Cnn_ParamInit failed!\n");
+
+ /* record tskBuf */
+ s32Ret = HI_MPI_SVP_NNIE_AddTskBuf(&(s_stCnnNnieParam.astForwardCtrl[0].stTskBuf));
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,HI_MPI_SVP_NNIE_AddTskBuf failed!\n");
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Cnn start!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Cnn_Stop();
+ return;
+ }
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stCnnNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Cnn_Stop();
+ return;
+ }
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stCnnNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* Software process */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Cnn_GetTopN
+ function's input data are correct */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Cnn_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_GetTopN(&s_stCnnNnieParam, &s_stCnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_CnnGetTopN failed!\n");
+
+ /* Print result */
+ SAMPLE_SVP_TRACE_INFO("Cnn result:\n");
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_PrintResult(&(s_stCnnSoftwareParam.stGetTopN), s_stCnnSoftwareParam.u32TopN);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Cnn_PrintResult failed!\n");
+
+CNN_FAIL_1:
+ /* Remove TskBuf */
+ s32Ret = HI_MPI_SVP_NNIE_RemoveTskBuf(&(s_stCnnNnieParam.astForwardCtrl[0].stTskBuf));
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,HI_MPI_SVP_NNIE_RemoveTskBuf failed!\n");
+CNN_FAIL_0:
+ SAMPLE_SVP_NNIE_Cnn_Deinit(&s_stCnnNnieParam, &s_stCnnSoftwareParam, &s_stCnnModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+hi_void SAMPLE_SVP_NNIE_Cnn_HandleSig(hi_void)
+{
+ g_stop_signal = HI_TRUE;
+}
+static void SAMPLE_SVP_NNIE_Segnet_Stop(void)
+{
+ SAMPLE_SVP_NNIE_Cnn_Deinit(&s_stSegnetNnieParam, NULL, &s_stSegnetModel);
+ (HI_VOID)memset_s(&s_stSegnetNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stSegnetModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show Segnet sample(image 224x224 U8_C3) */
+void SAMPLE_SVP_NNIE_Segnet(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/segnet_image_224x224.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/segmentation/inst_segnet_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0;
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Segnet_Stop();
+ return;
+ }
+ /* Segnet Load model */
+ SAMPLE_SVP_TRACE_INFO("Segnet Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stSegnetModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SEGNET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* Segnet parameter initialization */
+ SAMPLE_SVP_TRACE_INFO("Segnet parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Segnet_Stop();
+ return;
+ }
+ s_stSegnetNnieParam.pstModel = &s_stSegnetModel.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_ParamInit(&stNnieCfg, &s_stSegnetNnieParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SEGNET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Cnn_ParamInit failed!\n");
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Segnet start!\n");
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Segnet_Stop();
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stSegnetNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SEGNET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Segnet_Stop();
+ return;
+ }
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stSegnetNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SEGNET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* print report result */
+ s32Ret = SAMPLE_SVP_NNIE_PrintReportResult(&s_stSegnetNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SEGNET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_PrintReportResult failed!\n");
+
+ SAMPLE_SVP_TRACE_INFO("Segnet is successfully processed!\n");
+
+SEGNET_FAIL_0:
+ SAMPLE_SVP_NNIE_Cnn_Deinit(&s_stSegnetNnieParam, NULL, &s_stSegnetModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : Segnet sample signal handle */
+hi_void SAMPLE_SVP_NNIE_Segnet_HandleSig(hi_void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : print detection result */
+static HI_S32 SAMPLE_SVP_NNIE_Detection_PrintResult(SVP_BLOB_S *pstDstScore, SVP_BLOB_S *pstDstRoi,
+ SVP_BLOB_S *pstClassRoiNum, HI_FLOAT f32PrintResultThresh)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RoiNumBias = 0;
+ HI_U32 u32ScoreBias = 0;
+ HI_U32 u32BboxBias = 0;
+ HI_FLOAT f32Score = 0.0f;
+ HI_S32 *ps32Score = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstScore->u64VirAddr);
+ HI_S32 *ps32Roi = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstRoi->u64VirAddr);
+ HI_S32 *ps32ClassRoiNum = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstClassRoiNum->u64VirAddr);
+ HI_U32 u32ClassNum = pstClassRoiNum->unShape.stWhc.u32Width;
+ HI_S32 s32XMin = 0, s32YMin = 0, s32XMax = 0, s32YMax = 0;
+
+ u32RoiNumBias += ps32ClassRoiNum[0];
+ for (i = 1; i < u32ClassNum; i++) {
+ u32ScoreBias = u32RoiNumBias;
+ u32BboxBias = u32RoiNumBias * SAMPLE_SVP_NNIE_COORDI_NUM;
+ /* if the confidence score greater than result threshold, the result will be printed */
+ if ((HI_FLOAT)ps32Score[u32ScoreBias] / SAMPLE_SVP_NNIE_QUANT_BASE >= f32PrintResultThresh &&
+ ps32ClassRoiNum[i] != 0) {
+ SAMPLE_SVP_TRACE_INFO("==== The %dth class box info====\n", i);
+ }
+ for (j = 0; j < (HI_U32)ps32ClassRoiNum[i]; j++) {
+ f32Score = (HI_FLOAT)ps32Score[u32ScoreBias + j] / SAMPLE_SVP_NNIE_QUANT_BASE;
+ if (f32Score < f32PrintResultThresh) {
+ break;
+ }
+ s32XMin = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM];
+ s32YMin = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + 1]; /* to get next element of this array */
+ s32XMax = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + 2]; /* to get next element of this array */
+ s32YMax = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + 3]; /* to get next element of this array */
+ SAMPLE_SVP_TRACE_INFO("%d %d %d %d %f\n", s32XMin, s32YMin, s32XMax, s32YMax, f32Score);
+ }
+ u32RoiNumBias += ps32ClassRoiNum[i];
+ }
+ return HI_SUCCESS;
+}
+
+/* function : FasterRcnn software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_FasterRcnn_SoftwareDeinit(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stRpnTmpBuf.u64PhyAddr != 0) && (pstSoftWareParam->stRpnTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stRpnTmpBuf.u64PhyAddr, pstSoftWareParam->stRpnTmpBuf.u64VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : FasterRcnn Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_FasterRcnn_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : FasterRcnn software para init */
+static HI_S32 SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam, SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RpnTmpBufSize = 0;
+ HI_U32 u32RpnBboxBufSize = 0;
+ HI_U32 u32GetResultTmpBufSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* RPN parameter init */
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->u32MaxRoiNum = pstCfg->u32MaxRoiNum;
+ if (SAMPLE_SVP_NNIE_VGG16_FASTER_RCNN == s_enNetType) {
+ pstSoftWareParam->u32ClassNum = 4;
+ pstSoftWareParam->u32NumRatioAnchors = 3;
+ pstSoftWareParam->u32NumScaleAnchors = 3;
+ pstSoftWareParam->au32Scales[0] = 8 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[1] = 16 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[2] = 32 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[0] = 0.5 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[1] = 1 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[2] = 2 * SAMPLE_SVP_QUANT_BASE;
+ } else {
+ pstSoftWareParam->u32ClassNum = 2;
+ pstSoftWareParam->u32NumRatioAnchors = 1;
+ pstSoftWareParam->u32NumScaleAnchors = 9;
+ pstSoftWareParam->au32Scales[0] = 1.5 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[1] = 2.1 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[2] = 2.9 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[3] = 4.1 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[4] = 5.8 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[5] = 8.0 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[6] = 11.3 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[7] = 15.8 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[8] = 22.1 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[0] = 2.44 * SAMPLE_SVP_QUANT_BASE;
+ }
+
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32MinSize = 16;
+ pstSoftWareParam->u32FilterThresh = 16;
+ pstSoftWareParam->u32SpatialScale = (HI_U32)(0.0625 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.7 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->u32FilterThresh = 0;
+ pstSoftWareParam->u32NumBeforeNms = 6000;
+ for (i = 0; i < pstSoftWareParam->u32ClassNum; i++) {
+ pstSoftWareParam->au32ConfThresh[i] = 1;
+ }
+ pstSoftWareParam->u32ValidNmsThresh = (HI_U32)(0.3 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->stRpnBbox.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height = pstCfg->u32MaxRoiNum;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Width = SAMPLE_SVP_COORDI_NUM;
+ pstSoftWareParam->stRpnBbox.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(SAMPLE_SVP_COORDI_NUM * sizeof(HI_U32));
+ pstSoftWareParam->stRpnBbox.u32Num = 1;
+ for (i = 0; i < SAMPLE_SVP_NNIE_SEGMENT_NUM; i++) {
+ for (j = 0; j < pstNnieParam->pstModel->astSeg[0].u16DstNum; j++) {
+ if (strncmp(pstNnieParam->pstModel->astSeg[0].astDstNode[j].szName,
+ pstSoftWareParam->apcRpnDataLayerName[i], SVP_NNIE_NODE_NAME_LEN) == 0) {
+ pstSoftWareParam->aps32Conv[i] =
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstNnieParam->astSegData[0].astDst[j].u64VirAddr);
+ pstSoftWareParam->au32ConvHeight[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Height;
+ pstSoftWareParam->au32ConvWidth[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Width;
+ pstSoftWareParam->au32ConvChannel[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Chn;
+ break;
+ }
+ }
+ SAMPLE_SVP_CHECK_EXPR_RET((j == pstNnieParam->pstModel->astSeg[0].u16DstNum), HI_FAILURE,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,failed to find report node %s!\n",
+ pstSoftWareParam->apcRpnDataLayerName[i]);
+ if (i == 0) {
+ pstSoftWareParam->u32ConvStride = pstNnieParam->astSegData[0].astDst[j].u32Stride;
+ }
+ }
+
+ /* calculate software mem size */
+ u32ClassNum = pstSoftWareParam->u32ClassNum;
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_RpnTmpBufSize(pstSoftWareParam->u32NumRatioAnchors,
+ pstSoftWareParam->u32NumScaleAnchors, pstSoftWareParam->au32ConvHeight[0], pstSoftWareParam->au32ConvWidth[0]);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32RpnTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_RpnTmpBufSize failed!\n");
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32RpnTmpBufSize);
+ u32RpnBboxBufSize = pstSoftWareParam->stRpnBbox.u32Num * pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height *
+ pstSoftWareParam->stRpnBbox.u32Stride;
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_FasterRcnn_GetResultTmpBufSize(pstCfg->u32MaxRoiNum, u32ClassNum);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32GetResultTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_GetResultTmpBufSize failed!\n");
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32GetResultTmpBufSize);
+ u32DstRoiSize =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32) * SAMPLE_SVP_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize +
+ u32ClassRoiNumSize;
+
+ /* malloc mem */
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_RCNN_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set addr */
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u32Size = u32RpnTmpBufSize;
+
+ pstSoftWareParam->stRpnBbox.u64PhyAddr = u64PhyAddr + u32RpnTmpBufSize;
+ pstSoftWareParam->stRpnBbox.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr) + u32RpnTmpBufSize;
+
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize);
+ pstSoftWareParam->stGetResultTmpBuf.u32Size = u32GetResultTmpBufSize;
+
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize);
+ pstSoftWareParam->stDstRoi.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32) * SAMPLE_SVP_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width =
+ u32ClassNum * pstSoftWareParam->u32MaxRoiNum * SAMPLE_SVP_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr =
+ u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) +
+ u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * pstSoftWareParam->u32MaxRoiNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr =
+ u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) +
+ u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : FasterRcnn parameter initialization */
+static HI_S32 SAMPLE_SVP_NNIE_FasterRcnn_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstFasterRcnnCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam, SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware parameter */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstFasterRcnnCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software parameter */
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit(pstFasterRcnnCfg, pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_FasterRcnn_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+static hi_void SAMPLE_SVP_NNIE_FasterRcnn_Stop(hi_void)
+{
+ SAMPLE_SVP_NNIE_FasterRcnn_Deinit(&s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam, &s_stFasterRcnnModel);
+ (HI_VOID)memset_s(&s_stFasterRcnnNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stFasterRcnnSoftwareParam, sizeof(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stFasterRcnnModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show fasterRcnn sample(image 1240x375 U8_C3) */
+void SAMPLE_SVP_NNIE_FasterRcnn(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/single_person_1240x375.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_alexnet_frcnn_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 i = 0;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+ g_stop_signal = HI_FALSE;
+
+ /* Set configuration parameter */
+ s_enNetType = SAMPLE_SVP_NNIE_ALEXNET_FASTER_RCNN;
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 300; // set maxmum 300 ROIs
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core for 0-th Seg
+ stNnieCfg.aenNnieCoreId[1] = SVP_NNIE_ID_0; // set NNIE core for 1-th Seg
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ /* FasterRcnn Load model */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stFasterRcnnModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* FasterRcnn para init */
+ /* apcRpnDataLayerName is used to set RPN data layer name
+ and search RPN input data,if user has changed network struct, please
+ make sure the data layer names are correct */
+ /* FasterRcnn parameters are set in SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit,
+ if user has changed network struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s_stFasterRcnnNnieParam.pstModel = &s_stFasterRcnnModel.stModel;
+ s_stFasterRcnnSoftwareParam.apcRpnDataLayerName[0] = "rpn_cls_score";
+ s_stFasterRcnnSoftwareParam.apcRpnDataLayerName[1] = "rpn_bbox_pred";
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_ParamInit(&stNnieCfg, &s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_ParamInit failed!\n");
+
+ /* Fill 0-th input node of 0-th seg */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn start!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stFasterRcnnNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process 0-th seg */
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stFasterRcnnNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* RPN */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_Rpn(&s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_Rpn failed!\n");
+
+ if (s_stFasterRcnnSoftwareParam.stRpnBbox.unShape.stWhc.u32Height != 0) {
+ /* NNIE process 1-th seg, the input conv data comes from 0-th seg's 0-th report node,
+ the input roi comes from RPN results */
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ stProcSegIdx.u32SegIdx = 1;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_ForwardWithBbox(&s_stFasterRcnnNnieParam, &stInputDataIdx,
+ &s_stFasterRcnnSoftwareParam.stRpnBbox, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* GetResult */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_FasterRcnn_GetResult
+ function's input data are correct */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_GetResult(&s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_GetResult failed!\n");
+ } else {
+ for (i = 0; i < s_stFasterRcnnSoftwareParam.stClassRoiNum.unShape.stWhc.u32Width; i++) {
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, s_stFasterRcnnSoftwareParam.stClassRoiNum.u64VirAddr) + i) = 0;
+ }
+ }
+ /* print result, Alexnet_FasterRcnn has 2 classes:
+ class 0:background class 1:pedestrian */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stFasterRcnnSoftwareParam.stDstScore,
+ &s_stFasterRcnnSoftwareParam.stDstRoi, &s_stFasterRcnnSoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+FRCNN_FAIL_0:
+ SAMPLE_SVP_NNIE_FasterRcnn_Deinit(&s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam, &s_stFasterRcnnModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function :show fasterrcnn double_roipooling sample(image 224x224 U8_C3) */
+void SAMPLE_SVP_NNIE_FasterRcnn_DoubleRoiPooling(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/double_roipooling_224_224.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_fasterrcnn_double_roipooling_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 i = 0;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ s_enNetType = SAMPLE_SVP_NNIE_VGG16_FASTER_RCNN;
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 300; // set maxmum 300 ROIs
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core for 0-th Seg
+ stNnieCfg.aenNnieCoreId[1] = SVP_NNIE_ID_0; // set NNIE core for 1-th Seg
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ /* FasterRcnn Load model */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stFasterRcnnModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* FasterRcnn para init */
+ /* apcRpnDataLayerName is used to set RPN data layer name
+ and search RPN input data,if user has changed network struct, please
+ make sure the data layer names are correct */
+ /* FasterRcnn parameters are set in SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit,
+ if user has changed network struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_FaasterRcnn_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s_stFasterRcnnNnieParam.pstModel = &s_stFasterRcnnModel.stModel;
+ s_stFasterRcnnSoftwareParam.apcRpnDataLayerName[0] = "rpn_cls_score";
+ s_stFasterRcnnSoftwareParam.apcRpnDataLayerName[1] = "rpn_bbox_pred";
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_ParamInit(&stNnieCfg, &s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_ParamInit failed!\n");
+
+ /* Fill 0-th input node of 0-th seg */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn start!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stFasterRcnnNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process 0-th seg */
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stFasterRcnnNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* RPN */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_Rpn(&s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_Rpn failed!\n");
+ if (s_stFasterRcnnSoftwareParam.stRpnBbox.unShape.stWhc.u32Height != 0) {
+ /* NNIE process 1-st seg, the input conv data comes from 0-th seg's 0-th and
+ 1-st report node,the input roi comes from RPN results */
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ stProcSegIdx.u32SegIdx = 1;
+ s32Ret = SAMPLE_SVP_NNIE_ForwardWithBbox(&s_stFasterRcnnNnieParam, &stInputDataIdx,
+ &s_stFasterRcnnSoftwareParam.stRpnBbox, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* GetResult */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_FasterRcnn_GetResult
+ function's input data are correct */
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_GetResult(&s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_GetResult failed!\n");
+ } else {
+ for (i = 0; i < s_stFasterRcnnSoftwareParam.stClassRoiNum.unShape.stWhc.u32Width; i++) {
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, s_stFasterRcnnSoftwareParam.stClassRoiNum.u64VirAddr) + i) = 0;
+ }
+ }
+ /* print result, FasterRcnn has 4 classes:
+ class 0:background class 1:person class 2:people class 3:person sitting */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stFasterRcnnSoftwareParam.stDstScore,
+ &s_stFasterRcnnSoftwareParam.stDstRoi, &s_stFasterRcnnSoftwareParam.stClassRoiNum, f32PrintResultThresh);
+FRCNN_FAIL_0:
+ SAMPLE_SVP_NNIE_FasterRcnn_Deinit(&s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam, &s_stFasterRcnnModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : fasterRcnn sample signal handle */
+hi_void SAMPLE_SVP_NNIE_FasterRcnn_HandleSig(hi_void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Rfcn software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_SoftwareDeinit(SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if (pstSoftWareParam->stRpnTmpBuf.u64PhyAddr != 0 && pstSoftWareParam->stRpnTmpBuf.u64VirAddr != 0) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stRpnTmpBuf.u64PhyAddr, pstSoftWareParam->stRpnTmpBuf.u64VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Rfcn Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Rfcn software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_SoftwareInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RpnTmpBufSize = 0;
+ HI_U32 u32RpnBboxBufSize = 0;
+ HI_U32 u32GetResultTmpBufSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* init Rpn para */
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->u32MaxRoiNum = pstCfg->u32MaxRoiNum;
+ pstSoftWareParam->u32ClassNum = 21;
+ pstSoftWareParam->u32NumRatioAnchors = 3;
+ pstSoftWareParam->u32NumScaleAnchors = 3;
+ pstSoftWareParam->au32Scales[0] = 8 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->au32Scales[1] = 16 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->au32Scales[2] = 32 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[0] = 0.5 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[1] = 1 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[2] = 2 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32MinSize = 16;
+ pstSoftWareParam->u32FilterThresh = 0;
+ pstSoftWareParam->u32SpatialScale = (HI_U32)(0.0625 * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.7 * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32FilterThresh = 0;
+ pstSoftWareParam->u32NumBeforeNms = 6000;
+ for (i = 0; i < pstSoftWareParam->u32ClassNum; i++) {
+ pstSoftWareParam->au32ConfThresh[i] = 1;
+ pstSoftWareParam->af32ScoreThr[i] = 0.8f;
+ }
+ pstSoftWareParam->u32ValidNmsThresh = (HI_U32)(0.3 * 4096);
+
+ /* set rpn input data info, the input info is set according to RPN data layers' name */
+ for (i = 0; i < SAMPLE_SVP_NNIE_SEGMENT_NUM; i++) {
+ for (j = 0; j < pstNnieParam->pstModel->astSeg[0].u16DstNum; j++) {
+ if (strncmp(pstNnieParam->pstModel->astSeg[0].astDstNode[j].szName,
+ pstSoftWareParam->apcRpnDataLayerName[i], SVP_NNIE_NODE_NAME_LEN) == 0) {
+ pstSoftWareParam->aps32Conv[i] =
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstNnieParam->astSegData[0].astDst[j].u64VirAddr);
+ pstSoftWareParam->au32ConvHeight[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Height;
+ pstSoftWareParam->au32ConvWidth[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Width;
+ pstSoftWareParam->au32ConvChannel[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Chn;
+ break;
+ }
+ }
+ SAMPLE_SVP_CHECK_EXPR_RET((j == pstNnieParam->pstModel->astSeg[0].u16DstNum), HI_FAILURE,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,failed to find report node %s!\n",
+ pstSoftWareParam->apcRpnDataLayerName[i]);
+ if (i == 0) {
+ pstSoftWareParam->u32ConvStride = pstNnieParam->astSegData[0].astDst[j].u32Stride;
+ }
+ }
+
+ pstSoftWareParam->stRpnBbox.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height = pstCfg->u32MaxRoiNum;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Width = SAMPLE_SVP_COORDI_NUM;
+ pstSoftWareParam->stRpnBbox.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(SAMPLE_SVP_COORDI_NUM * sizeof(HI_U32));
+ pstSoftWareParam->stRpnBbox.u32Num = 1;
+
+ /* malloc software mem */
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_RpnTmpBufSize(pstSoftWareParam->u32NumRatioAnchors,
+ pstSoftWareParam->u32NumScaleAnchors, pstSoftWareParam->au32ConvHeight[0], pstSoftWareParam->au32ConvWidth[0]);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32RpnTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_RpnTmpBufSize failed!\n");
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32RpnTmpBufSize);
+ u32RpnBboxBufSize = pstSoftWareParam->stRpnBbox.u32Num * pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height *
+ pstSoftWareParam->stRpnBbox.u32Stride;
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_Rfcn_GetResultTmpBuf(pstCfg->u32MaxRoiNum, pstSoftWareParam->u32ClassNum);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32GetResultTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_GetResultTmpBuf failed!\n");
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32GetResultTmpBufSize);
+ u32ClassNum = pstSoftWareParam->u32ClassNum;
+ u32DstRoiSize =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize +
+ u32ClassRoiNumSize;
+
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_RFCN_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u32Size = u32RpnTmpBufSize;
+
+ pstSoftWareParam->stRpnBbox.u64PhyAddr = u64PhyAddr + u32RpnTmpBufSize;
+ pstSoftWareParam->stRpnBbox.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr) + u32RpnTmpBufSize;
+
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr + u32RpnTmpBufSize + u32RpnBboxBufSize;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnTmpBufSize + u32RpnBboxBufSize);
+ pstSoftWareParam->stGetResultTmpBuf.u32Size = u32GetResultTmpBufSize;
+
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize);
+ pstSoftWareParam->stDstRoi.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum *
+ sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width =
+ u32ClassNum * pstSoftWareParam->u32MaxRoiNum * SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr =
+ u64PhyAddr + u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) +
+ u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * pstSoftWareParam->u32MaxRoiNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr =
+ u64PhyAddr + u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) +
+ u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+ return s32Ret;
+}
+
+/* function : Rfcn init */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);SAMPLE_SVP_NNIE_MAX_CLASS_NUM;
+
+ /* init software para */
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_SoftwareInit(pstCfg, pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Rfcn_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Rfcn_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+
+/* function : roi to rect */
+static HI_S32 SAMPLE_SVP_NNIE_RoiToRect(SVP_BLOB_S *pstDstScore, SVP_BLOB_S *pstDstRoi, SVP_BLOB_S *pstClassRoiNum,
+ HI_FLOAT *paf32ScoreThr, HI_BOOL bRmBg, SAMPLE_SVP_NNIE_RECT_ARRAY_S *pstRect, HI_U32 u32SrcWidth,
+ HI_U32 u32SrcHeight, HI_U32 u32DstWidth, HI_U32 u32DstHeight)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RoiNumBias = 0;
+ HI_U32 u32ScoreBias = 0;
+ HI_U32 u32BboxBias = 0;
+ HI_FLOAT f32Score = 0.0f;
+ HI_S32 *ps32Score = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstScore->u64VirAddr);
+ HI_S32 *ps32Roi = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstRoi->u64VirAddr);
+ HI_S32 *ps32ClassRoiNum = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstClassRoiNum->u64VirAddr);
+ HI_U32 u32ClassNum = pstClassRoiNum->unShape.stWhc.u32Width;
+ HI_U32 u32RoiNumTmp = 0;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(u32ClassNum > SAMPLE_SVP_NNIE_MAX_CLASS_NUM, HI_ERR_SVP_NNIE_ILLEGAL_PARAM,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error(%#x),u32ClassNum(%u) must be less than or equal %u to!\n",
+ HI_ERR_SVP_NNIE_ILLEGAL_PARAM, u32ClassNum, SAMPLE_SVP_NNIE_MAX_CLASS_NUM);
+ pstRect->u32TotalNum = 0;
+ pstRect->u32ClsNum = u32ClassNum;
+ if (bRmBg) {
+ pstRect->au32RoiNum[0] = 0;
+ u32RoiNumBias += ps32ClassRoiNum[0];
+ for (i = 1; i < u32ClassNum; i++) {
+ u32ScoreBias = u32RoiNumBias;
+ u32BboxBias = u32RoiNumBias * SAMPLE_SVP_NNIE_COORDI_NUM;
+ u32RoiNumTmp = 0;
+ /* if the confidence score greater than result thresh, the result will be drew */
+ if (((HI_FLOAT)ps32Score[u32ScoreBias] / SAMPLE_SVP_NNIE_QUANT_BASE >= paf32ScoreThr[i]) &&
+ (ps32ClassRoiNum[i] != 0)) {
+ for (j = 0; j < (HI_U32)ps32ClassRoiNum[i]; j++) {
+ /* Score is descend order */
+ f32Score = (HI_FLOAT)ps32Score[u32ScoreBias + j] / SAMPLE_SVP_NNIE_QUANT_BASE;
+ if ((f32Score < paf32ScoreThr[i]) || (u32RoiNumTmp >= SAMPLE_SVP_NNIE_MAX_ROI_NUM_OF_CLASS)) {
+ break;
+ }
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X =
+ (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM] /
+ (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1);
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y =
+ (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + \
+ SAMPLE_SVP_NNIE_Y_MIN_OFFSET] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X =
+ (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + \
+ SAMPLE_SVP_NNIE_X_MAX_OFFSET] / (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1);
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32Y =
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y;
+
+ /* get the third point coordinate */
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32X =
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y =
+ (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + \
+ SAMPLE_SVP_NNIE_Y_MAX_OFFSET] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+
+ /* get the fourth point coordinate */
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32X =
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32Y =
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y;
+
+ u32RoiNumTmp++;
+ }
+ }
+
+ pstRect->au32RoiNum[i] = u32RoiNumTmp;
+ pstRect->u32TotalNum += u32RoiNumTmp;
+ u32RoiNumBias += ps32ClassRoiNum[i];
+ }
+ }
+ return HI_SUCCESS;
+}
+
+/* function : Rfcn Proc */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_Proc(SAMPLE_SVP_NNIE_PARAM_S *pstParam,
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSwParam)
+{
+ HI_S32 s32Ret = HI_FAILURE;
+ HI_U32 i = 0;
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+
+ /* NNIE process 0-th seg */
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(pstParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* RPN */
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Rpn(pstSwParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_RFCN_Rpn failed!\n");
+
+ if (pstSwParam->stRpnBbox.unShape.stWhc.u32Height != 0) {
+ /* NNIE process 1-th seg, the input data comes from 3-rd report node of 0-th seg,
+ the input roi comes from RPN results */
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 3;
+ stProcSegIdx.u32SegIdx = 1;
+ s32Ret =
+ SAMPLE_SVP_NNIE_ForwardWithBbox(pstParam, &stInputDataIdx, &pstSwParam->stRpnBbox, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* NNIE process 2-nd seg, the input data comes from 4-th report node of 0-th seg
+ the input roi comes from RPN results */
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 4;
+ stProcSegIdx.u32SegIdx = 2;
+ s32Ret =
+ SAMPLE_SVP_NNIE_ForwardWithBbox(pstParam, &stInputDataIdx, &pstSwParam->stRpnBbox, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* GetResult */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Rfcn_GetResult
+ function's input data are correct */
+
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_GetResult(pstParam, pstSwParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_GetResult failed!\n");
+ } else {
+ for (i = 0; i < pstSwParam->stClassRoiNum.unShape.stWhc.u32Width; i++) {
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, pstSwParam->stClassRoiNum.u64VirAddr) + i) = 0;
+ }
+ }
+ return s32Ret;
+}
+
+/* function : Rfcn Proc */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_Proc_ViToVo(SAMPLE_SVP_NNIE_PARAM_S *pstParam,
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSwParam, VIDEO_FRAME_INFO_S *pstExtFrmInfo, HI_U32 u32BaseWidth,
+ HI_U32 u32BaseHeight)
+{
+ HI_S32 s32Ret = HI_FAILURE;
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ /* SP420 */
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64VirAddr =
+ pstExtFrmInfo->stVFrame.u64VirAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64PhyAddr =
+ pstExtFrmInfo->stVFrame.u64PhyAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u32Stride =
+ pstExtFrmInfo->stVFrame.u32Stride[0];
+
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Proc(pstParam, pstSwParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_Proc failed!\n");
+ /* draw result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor */
+ s32Ret = SAMPLE_SVP_NNIE_RoiToRect(&(pstSwParam->stDstScore), &(pstSwParam->stDstRoi), &(pstSwParam->stClassRoiNum),
+ pstSwParam->af32ScoreThr, HI_TRUE, &(pstSwParam->stRect), pstExtFrmInfo->stVFrame.u32Width,
+ pstExtFrmInfo->stVFrame.u32Height, u32BaseWidth, u32BaseHeight);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_RoiToRect failed!\n", s32Ret);
+
+ return s32Ret;
+}
+
+static HI_VOID SAMPLE_SVP_NNIE_Rfcn_Stop(hi_void)
+{
+ s_bNnieStopSignal = HI_TRUE;
+ if (s_hNnieThread != 0) {
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+ }
+
+ SAMPLE_SVP_NNIE_Rfcn_Deinit(&s_stRfcnNnieParam, &s_stRfcnSoftwareParam, &s_stRfcnModel);
+ (HI_VOID)memset_s(&s_stRfcnNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stRfcnSoftwareParam, sizeof(SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stRfcnModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+
+ SAMPLE_COMM_IVE_StopViVpssVencVo(&s_stViConfig, &s_stRfcnSwitch);
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_Pause(hi_void)
+{
+ printf("---------------press Enter key to exit!---------------\n");
+ if (s_bNnieStopSignal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop();
+ return HI_FAILURE;
+ }
+ (hi_void)getchar();
+ if (s_bNnieStopSignal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop();
+ return HI_FAILURE;
+ }
+ return HI_SUCCESS;
+}
+
+/* function : Rfcn vi to vo thread entry */
+static HI_VOID *SAMPLE_SVP_NNIE_Rfcn_ViToVo(HI_VOID *pArgs)
+{
+ HI_S32 s32Ret;
+ SAMPLE_SVP_NNIE_PARAM_S *pstParam = NULL;
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSwParam = NULL;
+ VIDEO_FRAME_INFO_S stBaseFrmInfo;
+ VIDEO_FRAME_INFO_S stExtFrmInfo;
+ const HI_S32 s32MilliSec = 20000; /* 20000ms timeout */
+ const VO_LAYER voLayer = 0;
+ const VO_CHN voChn = 0;
+ const HI_S32 s32VpssGrp = 0;
+ const HI_S32 as32VpssChn[] = {VPSS_CHN0, VPSS_CHN1};
+
+ hi_unused(pArgs);
+ pstParam = &s_stRfcnNnieParam;
+ pstSwParam = &s_stRfcnSoftwareParam;
+
+ struct timespec start_time1,end_time1;
+ float use_time1 =0;
+
+ while (HI_FALSE == s_bNnieStopSignal) {
+ clock_gettime(CLOCK_REALTIME, &start_time1);
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[1], &stExtFrmInfo, s32MilliSec);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n", s32Ret, s32VpssGrp,
+ as32VpssChn[1]);
+ continue;
+ }
+
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[0], &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, EXT_RELEASE,
+ "Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n", s32Ret, s32VpssGrp,
+ as32VpssChn[0]);
+
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Proc_ViToVo(pstParam, pstSwParam, &stExtFrmInfo, stBaseFrmInfo.stVFrame.u32Width,
+ stBaseFrmInfo.stVFrame.u32Height);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, BASE_RELEASE, "Error(%#x),SAMPLE_SVP_NNIE_Rfcn_Proc failed!\n",
+ s32Ret);
+
+ // Draw rect
+ s32Ret = SAMPLE_COMM_SVP_NNIE_FillRect(&stBaseFrmInfo, &(pstSwParam->stRect), 0x0000FF00);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, BASE_RELEASE,
+ "SAMPLE_COMM_SVP_NNIE_FillRect failed, Error(%#x)!\n", s32Ret);
+
+ s32Ret = HI_MPI_VO_SendFrame(voLayer, voChn, &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, BASE_RELEASE, "HI_MPI_VO_SendFrame failed, Error(%#x)!\n", s32Ret);
+
+ clock_gettime(CLOCK_REALTIME, &end_time1);
+ use_time1 = (float)(end_time1.tv_sec - start_time1.tv_sec)*1000 + (end_time1.tv_nsec - start_time1.tv_nsec) / 1000000.0;
+ SAMPLE_SVP_TRACE_INFO("The use time is %f \n", use_time1);
+
+ BASE_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp, as32VpssChn[0], &stBaseFrmInfo);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n", s32Ret, s32VpssGrp,
+ as32VpssChn[0]);
+ }
+
+ EXT_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp, as32VpssChn[1], &stExtFrmInfo);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n", s32Ret, s32VpssGrp,
+ as32VpssChn[1]);
+ }
+ }
+
+ return HI_NULL;
+}
+
+/* function : Rfcn Vi->VO */
+void SAMPLE_SVP_NNIE_Rfcn(void)
+{
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_rfcn_resnet50_cycle_352x288.wk";
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SIZE_S stSize;
+ PIC_SIZE_E enSize = PIC_CIF;
+ HI_S32 s32Ret = HI_SUCCESS;
+
+ (HI_VOID)memset_s(&s_stRfcnModel, sizeof(s_stRfcnModel), 0, sizeof(s_stRfcnModel));
+ (HI_VOID)memset_s(&s_stRfcnNnieParam, sizeof(s_stRfcnNnieParam), 0, sizeof(s_stRfcnNnieParam));
+ (HI_VOID)memset_s(&s_stRfcnSoftwareParam, sizeof(s_stRfcnSoftwareParam), 0, sizeof(s_stRfcnSoftwareParam));
+
+ /* step 1: start vi vpss vo */
+ s_stRfcnSwitch.bVenc = HI_FALSE;
+ s_stRfcnSwitch.bVo = HI_TRUE;
+ s32Ret = SAMPLE_COMM_IVE_StartViVpssVencVo(&s_stViConfig, &s_stRfcnSwitch, &enSize);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, "Error(%#x),SAMPLE_COMM_IVE_StartViVpssVencVo failed!\n",
+ s32Ret);
+
+ s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSize, &stSize);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, "Error(%#x),SAMPLE_COMM_SYS_GetPicSize failed!\n", s32Ret);
+
+ /* step 2: init NNIE param */
+ stNnieCfg.pszPic = NULL;
+ stNnieCfg.u32MaxInputNum = 1; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 300; // set maxmum 300 ROIs
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core for 0-th Seg
+ stNnieCfg.aenNnieCoreId[1] = SVP_NNIE_ID_0; // set NNIE core for 1-th Seg
+ stNnieCfg.aenNnieCoreId[2] = SVP_NNIE_ID_0; // set NNIE core for 2-th Seg
+
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stRfcnModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* apcRpnDataLayerName is used to set RPN data layer name
+ and search RPN input data,if user has changed network struct, please
+ make sure the data layer names are correct */
+ s_stRfcnNnieParam.pstModel = &s_stRfcnModel.stModel;
+ s_stRfcnSoftwareParam.apcRpnDataLayerName[0] = "rpn_cls_score";
+ s_stRfcnSoftwareParam.apcRpnDataLayerName[1] = "rpn_bbox_pred";
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_ParamInit(&stNnieCfg, &s_stRfcnNnieParam, &s_stRfcnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_ParamInit failed!\n");
+
+ s_bNnieStopSignal = HI_FALSE;
+
+ /* step 3: Create work thread */
+ s32Ret = prctl(PR_SET_NAME, "NNIE_ViToVo", 0, 0, 0);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "thread set name failed!\n");
+ s32Ret = pthread_create(&s_hNnieThread, 0, SAMPLE_SVP_NNIE_Rfcn_ViToVo, NULL);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_1, SAMPLE_SVP_ERR_LEVEL_ERROR, "thread create failed!\n");
+
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Pause();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR, "vi_rfcn_vo exit!\n");
+
+ s_bNnieStopSignal = HI_TRUE;
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+END_RFCN_1:
+
+ SAMPLE_SVP_NNIE_Rfcn_Deinit(&s_stRfcnNnieParam, &s_stRfcnSoftwareParam, &s_stRfcnModel);
+END_RFCN_0:
+ SAMPLE_COMM_IVE_StopViVpssVencVo(&s_stViConfig, &s_stRfcnSwitch);
+ return;
+}
+
+/* function : rfcn sample signal handle */
+void SAMPLE_SVP_NNIE_Rfcn_HandleSig(void)
+{
+ s_bNnieStopSignal = HI_TRUE;
+}
+
+/* function : rfcn sample signal handle */
+static hi_void SAMPLE_SVP_NNIE_Rfcn_Stop_File(hi_void)
+{
+ SAMPLE_SVP_NNIE_Rfcn_Deinit(&s_stRfcnNnieParam, &s_stRfcnSoftwareParam, &s_stRfcnModel);
+ (HI_VOID)memset_s(&s_stRfcnModel, sizeof(s_stRfcnModel), 0, sizeof(s_stRfcnModel));
+ (HI_VOID)memset_s(&s_stRfcnNnieParam, sizeof(s_stRfcnNnieParam), 0, sizeof(s_stRfcnNnieParam));
+ (HI_VOID)memset_s(&s_stRfcnSoftwareParam, sizeof(s_stRfcnSoftwareParam), 0, sizeof(s_stRfcnSoftwareParam));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+void SAMPLE_SVP_NNIE_Rfcn_HandleSig_File(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Rfcn Read file */
+void SAMPLE_SVP_NNIE_Rfcn_File(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/hoser_dog_car_person_800x600.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_rfcn_resnet50_cycle.wk";
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+
+ (HI_VOID)memset_s(&s_stRfcnModel, sizeof(s_stRfcnModel), 0, sizeof(s_stRfcnModel));
+ (HI_VOID)memset_s(&s_stRfcnNnieParam, sizeof(s_stRfcnNnieParam), 0, sizeof(s_stRfcnNnieParam));
+ (HI_VOID)memset_s(&s_stRfcnSoftwareParam, sizeof(s_stRfcnSoftwareParam), 0, sizeof(s_stRfcnSoftwareParam));
+
+ stNnieCfg.pszPic = pcSrcFile;
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.u32MaxInputNum = 1; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 300; // set maxmum 300 ROIs
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core for 0-th Seg
+ stNnieCfg.aenNnieCoreId[1] = SVP_NNIE_ID_0; // set NNIE core for 1-th Seg
+ stNnieCfg.aenNnieCoreId[2] = SVP_NNIE_ID_0; // set NNIE core for 2-th Seg
+ g_stop_signal = HI_FALSE;
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop_File();
+ return;
+ }
+
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stRfcnModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* apcRpnDataLayerName is used to set RPN data layer name
+ and search RPN input data,if user has changed network struct, please
+ make sure the data layer names are correct */
+ s_stRfcnNnieParam.pstModel = &s_stRfcnModel.stModel;
+ s_stRfcnSoftwareParam.apcRpnDataLayerName[0] = "rpn_cls_score";
+ s_stRfcnSoftwareParam.apcRpnDataLayerName[1] = "rpn_bbox_pred";
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop_File();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_ParamInit(&stNnieCfg, &s_stRfcnNnieParam, &s_stRfcnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_ParamInit failed!\n");
+
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop_File();
+ return;
+ }
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stRfcnNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop_File();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Proc(&s_stRfcnNnieParam, &s_stRfcnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_Proc failed!\n");
+
+ /* print result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor */
+
+ SAMPLE_SVP_TRACE_INFO("Rfcn result:\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop_File();
+ return;
+ }
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stRfcnSoftwareParam.stDstScore, &s_stRfcnSoftwareParam.stDstRoi,
+ &s_stRfcnSoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+END_RFCN_0:
+
+ SAMPLE_SVP_NNIE_Rfcn_Deinit(&s_stRfcnNnieParam, &s_stRfcnSoftwareParam, &s_stRfcnModel);
+ (HI_VOID)memset_s(&s_stRfcnModel, sizeof(s_stRfcnModel), 0, sizeof(s_stRfcnModel));
+ (HI_VOID)memset_s(&s_stRfcnNnieParam, sizeof(s_stRfcnNnieParam), 0, sizeof(s_stRfcnNnieParam));
+ (HI_VOID)memset_s(&s_stRfcnSoftwareParam, sizeof(s_stRfcnSoftwareParam), 0, sizeof(s_stRfcnSoftwareParam));
+ SAMPLE_COMM_SVP_CheckSysExit();
+
+ return;
+}
+
+/* function : SSD software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Ssd_SoftwareDeinit(SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stPriorBoxTmpBuf.u64PhyAddr != 0) && (pstSoftWareParam->stPriorBoxTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stPriorBoxTmpBuf.u64PhyAddr,
+ pstSoftWareParam->stPriorBoxTmpBuf.u64VirAddr);
+ pstSoftWareParam->stPriorBoxTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stPriorBoxTmpBuf.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Ssd Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Ssd_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Ssd_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Ssd_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Ssd software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Ssd_SoftwareInit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_U32 i = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32TmpBufTotalSize = 0;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* Set Conv Parameters */
+ /* the SSD sample report resule is after permute operation,
+ conv result is (C, H, W), after permute, the report node's
+ (C1, H1, W1) is (H, W, C), the stride of report result is aligned according to C dim */
+ for (i = 0; i < SAMPLE_SVP_NNIE_SSD_REPORT_NODE_NUM; i++) {
+ pstSoftWareParam->au32ConvHeight[i] = pstNnieParam->pstModel->astSeg[0].astDstNode[i].unShape.stWhc.u32Chn;
+ pstSoftWareParam->au32ConvWidth[i] = pstNnieParam->pstModel->astSeg[0].astDstNode[i].unShape.stWhc.u32Height;
+ pstSoftWareParam->au32ConvChannel[i] = pstNnieParam->pstModel->astSeg[0].astDstNode[i].unShape.stWhc.u32Width;
+ if (i % 2 == 1) { // only need to set the odd index parameter
+ pstSoftWareParam->au32ConvStride[i / 2] =
+ SAMPLE_SVP_NNIE_ALIGN16(pstSoftWareParam->au32ConvChannel[i] * sizeof(HI_U32)) / sizeof(HI_U32);
+ }
+ }
+
+ /* Set PriorBox Parameters */
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->au32PriorBoxWidth[0] = 38;
+ pstSoftWareParam->au32PriorBoxWidth[1] = 19;
+ pstSoftWareParam->au32PriorBoxWidth[2] = 10;
+ pstSoftWareParam->au32PriorBoxWidth[3] = 5;
+ pstSoftWareParam->au32PriorBoxWidth[4] = 3;
+ pstSoftWareParam->au32PriorBoxWidth[5] = 1;
+
+ pstSoftWareParam->au32PriorBoxHeight[0] = 38;
+ pstSoftWareParam->au32PriorBoxHeight[1] = 19;
+ pstSoftWareParam->au32PriorBoxHeight[2] = 10;
+ pstSoftWareParam->au32PriorBoxHeight[3] = 5;
+ pstSoftWareParam->au32PriorBoxHeight[4] = 3;
+ pstSoftWareParam->au32PriorBoxHeight[5] = 1;
+
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+
+ pstSoftWareParam->af32PriorBoxMinSize[0][0] = 30.0f;
+ pstSoftWareParam->af32PriorBoxMinSize[1][0] = 60.0f;
+ pstSoftWareParam->af32PriorBoxMinSize[2][0] = 111.0f;
+ pstSoftWareParam->af32PriorBoxMinSize[3][0] = 162.0f;
+ pstSoftWareParam->af32PriorBoxMinSize[4][0] = 213.0f;
+ pstSoftWareParam->af32PriorBoxMinSize[5][0] = 264.0f;
+
+ pstSoftWareParam->af32PriorBoxMaxSize[0][0] = 60.0f;
+ pstSoftWareParam->af32PriorBoxMaxSize[1][0] = 111.0f;
+ pstSoftWareParam->af32PriorBoxMaxSize[2][0] = 162.0f;
+ pstSoftWareParam->af32PriorBoxMaxSize[3][0] = 213.0f;
+ pstSoftWareParam->af32PriorBoxMaxSize[4][0] = 264.0f;
+ pstSoftWareParam->af32PriorBoxMaxSize[5][0] = 315.0f;
+
+ pstSoftWareParam->u32MinSizeNum = 1;
+ pstSoftWareParam->u32MaxSizeNum = 1;
+ pstSoftWareParam->bFlip = HI_TRUE;
+ pstSoftWareParam->bClip = HI_FALSE;
+
+ pstSoftWareParam->au32InputAspectRatioNum[0] = 1;
+ pstSoftWareParam->au32InputAspectRatioNum[1] = 2;
+ pstSoftWareParam->au32InputAspectRatioNum[2] = 2;
+ pstSoftWareParam->au32InputAspectRatioNum[3] = 2;
+ pstSoftWareParam->au32InputAspectRatioNum[4] = 1;
+ pstSoftWareParam->au32InputAspectRatioNum[5] = 1;
+
+ pstSoftWareParam->af32PriorBoxAspectRatio[0][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[0][1] = 0;
+ pstSoftWareParam->af32PriorBoxAspectRatio[1][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[1][1] = 3;
+ pstSoftWareParam->af32PriorBoxAspectRatio[2][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[2][1] = 3;
+ pstSoftWareParam->af32PriorBoxAspectRatio[3][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[3][1] = 3;
+ pstSoftWareParam->af32PriorBoxAspectRatio[4][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[4][1] = 0;
+ pstSoftWareParam->af32PriorBoxAspectRatio[5][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[5][1] = 0;
+
+ pstSoftWareParam->af32PriorBoxStepWidth[0] = 8;
+ pstSoftWareParam->af32PriorBoxStepWidth[1] = 16;
+ pstSoftWareParam->af32PriorBoxStepWidth[2] = 32;
+ pstSoftWareParam->af32PriorBoxStepWidth[3] = 64;
+ pstSoftWareParam->af32PriorBoxStepWidth[4] = 100;
+ pstSoftWareParam->af32PriorBoxStepWidth[5] = 300;
+
+ pstSoftWareParam->af32PriorBoxStepHeight[0] = 8;
+ pstSoftWareParam->af32PriorBoxStepHeight[1] = 16;
+ pstSoftWareParam->af32PriorBoxStepHeight[2] = 32;
+ pstSoftWareParam->af32PriorBoxStepHeight[3] = 64;
+ pstSoftWareParam->af32PriorBoxStepHeight[4] = 100;
+ pstSoftWareParam->af32PriorBoxStepHeight[5] = 300;
+
+ pstSoftWareParam->f32Offset = 0.5f;
+
+ pstSoftWareParam->as32PriorBoxVar[0] = (HI_S32)(0.1f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->as32PriorBoxVar[1] = (HI_S32)(0.1f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->as32PriorBoxVar[2] = (HI_S32)(0.2f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->as32PriorBoxVar[3] = (HI_S32)(0.2f * SAMPLE_SVP_NNIE_QUANT_BASE);
+
+ /* Set Softmax Parameters */
+ pstSoftWareParam->u32SoftMaxInHeight = 21;
+ pstSoftWareParam->au32SoftMaxInChn[0] = 121296;
+ pstSoftWareParam->au32SoftMaxInChn[1] = 45486;
+ pstSoftWareParam->au32SoftMaxInChn[2] = 12600;
+ pstSoftWareParam->au32SoftMaxInChn[3] = 3150;
+ pstSoftWareParam->au32SoftMaxInChn[4] = 756;
+ pstSoftWareParam->au32SoftMaxInChn[5] = 84;
+
+ pstSoftWareParam->u32ConcatNum = 6;
+ pstSoftWareParam->u32SoftMaxOutWidth = 1;
+ pstSoftWareParam->u32SoftMaxOutHeight = 21;
+ pstSoftWareParam->u32SoftMaxOutChn = 8732;
+
+ /* Set DetectionOut Parameters */
+ pstSoftWareParam->u32ClassNum = 21;
+ pstSoftWareParam->u32TopK = 400;
+ pstSoftWareParam->u32KeepTopK = 200;
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.3f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32ConfThresh = (HI_U32)(0.000245f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->au32DetectInputChn[0] = 23104;
+ pstSoftWareParam->au32DetectInputChn[1] = 8664;
+ pstSoftWareParam->au32DetectInputChn[2] = 2400;
+ pstSoftWareParam->au32DetectInputChn[3] = 600;
+ pstSoftWareParam->au32DetectInputChn[4] = 144;
+ pstSoftWareParam->au32DetectInputChn[5] = 16;
+
+ /* Malloc assist buffer memory */
+ u32ClassNum = pstSoftWareParam->u32ClassNum;
+ u32TotalSize = SAMPLE_SVP_NNIE_Ssd_GetResultTmpBuf(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32TotalSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, SAMPLE_SVP_NNIE_Ssd_GetResultTmpBuf failed!\n");
+ u32DstRoiSize =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32TopK * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32TopK * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32TotalSize + u32DstRoiSize + u32DstScoreSize + u32ClassRoiNumSize;
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_SSD_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set each tmp buffer addr */
+ pstSoftWareParam->stPriorBoxTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stPriorBoxTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+
+ pstSoftWareParam->stSoftMaxTmpBuf.u64PhyAddr = u64PhyAddr + pstSoftWareParam->stPriorBoxTmpBuf.u32Size;
+ pstSoftWareParam->stSoftMaxTmpBuf.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + pstSoftWareParam->stPriorBoxTmpBuf.u32Size);
+
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr =
+ u64PhyAddr + pstSoftWareParam->stPriorBoxTmpBuf.u32Size + pstSoftWareParam->stSoftMaxTmpBuf.u32Size;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr +
+ pstSoftWareParam->stPriorBoxTmpBuf.u32Size + pstSoftWareParam->stSoftMaxTmpBuf.u32Size);
+
+ u32TmpBufTotalSize = pstSoftWareParam->stPriorBoxTmpBuf.u32Size + pstSoftWareParam->stSoftMaxTmpBuf.u32Size +
+ pstSoftWareParam->stGetResultTmpBuf.u32Size;
+
+ /* set result blob */
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32TmpBufTotalSize);
+ pstSoftWareParam->stDstRoi.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32TopK * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width =
+ u32ClassNum * pstSoftWareParam->u32TopK * SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32TopK * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * pstSoftWareParam->u32TopK;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : Ssd init */
+static HI_S32 SAMPLE_SVP_NNIE_Ssd_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software para */
+ s32Ret = SAMPLE_SVP_NNIE_Ssd_SoftwareInit(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Ssd_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Ssd_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Ssd_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+
+static void SAMPLE_SVP_NNIE_Ssd_Stop(void)
+{
+ SAMPLE_SVP_NNIE_Ssd_Deinit(&s_stSsdNnieParam, &s_stSsdSoftwareParam, &s_stSsdModel);
+ (HI_VOID)memset_s(&s_stSsdNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stSsdSoftwareParam, sizeof(SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stSsdModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show SSD sample(image 300x300 U8_C3) */
+void SAMPLE_SVP_NNIE_Ssd(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/dog_bike_car_300x300.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_ssd_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+ /* Ssd Load model */
+ SAMPLE_SVP_TRACE_INFO("Ssd Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stSsdModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SSD_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* Ssd parameter initialization */
+ /* Ssd parameters are set in SAMPLE_SVP_NNIE_Ssd_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Ssd_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Ssd parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+ s_stSsdNnieParam.pstModel = &s_stSsdModel.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Ssd_ParamInit(&stNnieCfg, &s_stSsdNnieParam, &s_stSsdSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SSD_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Ssd_ParamInit failed!\n");
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Ssd start!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stSsdNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SSD_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stSsdNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SSD_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+ /* software process */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Ssd_GetResult
+ function's input data are correct */
+
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Ssd_GetResult(&s_stSsdNnieParam, &s_stSsdSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SSD_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Ssd_GetResult failed!\n");
+
+ /* print result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("Ssd result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stSsdSoftwareParam.stDstScore, &s_stSsdSoftwareParam.stDstRoi,
+ &s_stSsdSoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+SSD_FAIL_0:
+ SAMPLE_SVP_NNIE_Ssd_Deinit(&s_stSsdNnieParam, &s_stSsdSoftwareParam, &s_stSsdModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : SSD sample signal handle */
+void SAMPLE_SVP_NNIE_Ssd_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Yolov1 software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov1_SoftwareDeinit(SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr != 0) &&
+ (pstSoftWareParam->stGetResultTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr,
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr);
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = 0;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = 0;
+ pstSoftWareParam->stDstRoi.u64VirAddr = 0;
+ pstSoftWareParam->stDstScore.u64PhyAddr = 0;
+ pstSoftWareParam->stDstScore.u64VirAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Yolov1 Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov1_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Yolov1_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov1_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Yolov1 software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov1_SoftwareInit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32BboxNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32TmpBufTotalSize = 0;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32BboxNumEachGrid = 2;
+ pstSoftWareParam->u32ClassNum = 20;
+ pstSoftWareParam->u32GridNumHeight = 7;
+ pstSoftWareParam->u32GridNumWidth = 7;
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.5f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32ConfThresh = (HI_U32)(0.2f * SAMPLE_SVP_NNIE_QUANT_BASE);
+
+ /* Malloc assist buffer memory */
+ u32ClassNum = pstSoftWareParam->u32ClassNum + 1;
+ u32BboxNum =
+ pstSoftWareParam->u32BboxNumEachGrid * pstSoftWareParam->u32GridNumHeight * pstSoftWareParam->u32GridNumWidth;
+ u32TmpBufTotalSize = SAMPLE_SVP_NNIE_Yolov1_GetResultTmpBuf(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32TmpBufTotalSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, SAMPLE_SVP_NNIE_Yolov1_GetResultTmpBuf failed!\n");
+ u32DstRoiSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32TotalSize + u32DstRoiSize + u32DstScoreSize + u32ClassRoiNumSize + u32TmpBufTotalSize;
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_YOLOV1_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set each tmp buffer addr */
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+
+ /* set result blob */
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32TmpBufTotalSize);
+ pstSoftWareParam->stDstRoi.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width = u32ClassNum * u32BboxNum * SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32TmpBufTotalSize + u32DstRoiSize);
+ pstSoftWareParam->stDstScore.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * u32BboxNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : Yolov1 init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov1_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software para */
+ s32Ret = SAMPLE_SVP_NNIE_Yolov1_SoftwareInit(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov1_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Yolov1_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov1_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+
+static hi_void SAMPLE_SVP_NNIE_Yolov1_Stop(hi_void)
+{
+ SAMPLE_SVP_NNIE_Yolov1_Deinit(&s_stYolov1NnieParam, &s_stYolov1SoftwareParam, &s_stYolov1Model);
+ (HI_VOID)memset_s(&s_stYolov1NnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov1SoftwareParam, sizeof(SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov1Model, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show YOLOV1 sample(image 448x448 U8_C3) */
+void SAMPLE_SVP_NNIE_Yolov1(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/dog_bike_car_448x448.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_yolov1_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ f32PrintResultThresh = 0.3f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+
+ /* Yolov1 Load model */
+ SAMPLE_SVP_TRACE_INFO("Yolov1 Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stYolov1Model);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV1_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* Yolov1 parameter initialization */
+ /* Yolov1 software parameters are set in SAMPLE_SVP_NNIE_Yolov1_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Yolov1_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Yolov1 parameter initialization!\n");
+ s_stYolov1NnieParam.pstModel = &s_stYolov1Model.stModel;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Yolov1_ParamInit(&stNnieCfg, &s_stYolov1NnieParam, &s_stYolov1SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV1_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov1_ParamInit failed!\n");
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Yolov1 start!\n");
+
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stYolov1NnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV1_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ stProcSegIdx.u32SegIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stYolov1NnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV1_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+ /* software process */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Yolov1_GetResult
+ function input data are correct */
+
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Yolov1_GetResult(&s_stYolov1NnieParam, &s_stYolov1SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV1_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov1_GetResult failed!\n");
+
+ /* print result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("Yolov1 result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stYolov1SoftwareParam.stDstScore, &s_stYolov1SoftwareParam.stDstRoi,
+ &s_stYolov1SoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+YOLOV1_FAIL_0:
+ SAMPLE_SVP_NNIE_Yolov1_Deinit(&s_stYolov1NnieParam, &s_stYolov1SoftwareParam, &s_stYolov1Model);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : Yolov1 sample signal handle */
+void SAMPLE_SVP_NNIE_Yolov1_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/*----------------------------------*/
+/* function : Yolov2 software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov2_SoftwareDeinit(SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr != 0) &&
+ (pstSoftWareParam->stGetResultTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr,
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr);
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = 0;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = 0;
+ pstSoftWareParam->stDstRoi.u64VirAddr = 0;
+ pstSoftWareParam->stDstScore.u64PhyAddr = 0;
+ pstSoftWareParam->stDstScore.u64VirAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Yolov2 Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov2_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov2_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Yolov2 software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov2_SoftwareInit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32BboxNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32TmpBufTotalSize = 0;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32BboxNumEachGrid = 5;
+ pstSoftWareParam->u32ClassNum = 2;
+ pstSoftWareParam->u32GridNumHeight = 13;
+ pstSoftWareParam->u32GridNumWidth = 13;
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.3f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32ConfThresh = (HI_U32)(0.25f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32MaxRoiNum = 10;
+ pstSoftWareParam->af32Bias[0] = 1.08;
+ pstSoftWareParam->af32Bias[1] = 1.19;
+ pstSoftWareParam->af32Bias[2] = 3.42;
+ pstSoftWareParam->af32Bias[3] = 4.41;
+ pstSoftWareParam->af32Bias[4] = 6.63;
+ pstSoftWareParam->af32Bias[5] = 11.38;
+ pstSoftWareParam->af32Bias[6] = 9.42;
+ pstSoftWareParam->af32Bias[7] = 5.11;
+ pstSoftWareParam->af32Bias[8] = 16.62;
+ pstSoftWareParam->af32Bias[9] = 10.52;
+
+ /* Malloc assist buffer memory */
+ u32ClassNum = pstSoftWareParam->u32ClassNum + 1;
+ u32BboxNum =
+ pstSoftWareParam->u32BboxNumEachGrid * pstSoftWareParam->u32GridNumHeight * pstSoftWareParam->u32GridNumWidth;
+ u32TmpBufTotalSize = SAMPLE_SVP_NNIE_Yolov2_GetResultTmpBuf(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32TmpBufTotalSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, SAMPLE_SVP_NNIE_Yolov2_GetResultTmpBuf failed!\n");
+ u32DstRoiSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32TotalSize + u32DstRoiSize + u32DstScoreSize + u32ClassRoiNumSize + u32TmpBufTotalSize;
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_YOLOV2_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set each tmp buffer addr */
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+
+ /* set result blob */
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32TmpBufTotalSize);
+ pstSoftWareParam->stDstRoi.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width = u32ClassNum * u32BboxNum * SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * u32BboxNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : Yolov1 init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov2_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software para */
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_SoftwareInit(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov2_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov2_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+/*----------------------------------*/
+
+/*=================================*/
+static HI_S32 SampleSvpNnieYolov2SoftwareInit(SAMPLE_SVP_NNIE_CFG_S* pstCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam, SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S* pstSoftWareParam)
+{
+ HI_S32 s32Ret;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32BboxNum;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32DstRoiSize;
+ HI_U32 u32DstScoreSize;
+ HI_U32 u32ClassRoiNumSize;
+ HI_U32 u32TmpBufTotalSize;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8* pu8VirAddr = NULL;
+
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32BboxNumEachGrid = 5; // 5: 2BboxNumEachGrid
+ pstSoftWareParam->u32ClassNum = 2; // 5: class number
+ pstSoftWareParam->u32GridNumHeight = 12; // 12: GridNumHeight
+ pstSoftWareParam->u32GridNumWidth = 20; // 20: GridNumWidth
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.45f*SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32ConfThresh = (HI_U32)(0.4f*SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32MaxRoiNum = 10; // 10: MaxRoiNum
+ pstSoftWareParam->af32Bias[0] = 0.52; // 0.52: af32Bias[0] value
+ pstSoftWareParam->af32Bias[1] = 0.61; // 0.61: af32Bias[1] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_2] = 1.05; // 1.05: af32Bias[ARRAY_SUBSCRIPT_2] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_3] = 1.12; // 1.12: af32Bias[ARRAY_SUBSCRIPT_3] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_4] = 1.85; // 1.85: af32Bias[ARRAY_SUBSCRIPT_4] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_5] = 2.05; // 2.05: af32Bias[ARRAY_SUBSCRIPT_5] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_6] = 4.63; // 4.63: af32Bias[ARRAY_SUBSCRIPT_6] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_7] = 4.49; // 4.49: af32Bias[ARRAY_SUBSCRIPT_7] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_8] = 7.15; // 7.15: af32Bias[ARRAY_SUBSCRIPT_8] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_9] = 7.56; // 7.56: af32Bias[ARRAY_SUBSCRIPT_9] value
+
+ /*
+ * 申请辅助内存空间
+ * Malloc assist buffer memory
+ */
+ u32ClassNum = pstSoftWareParam->u32ClassNum + 1;
+ u32BboxNum = pstSoftWareParam->u32BboxNumEachGrid*pstSoftWareParam->u32GridNumHeight*
+ pstSoftWareParam->u32GridNumWidth;
+ u32TmpBufTotalSize = SAMPLE_SVP_NNIE_Yolov2_GetResultTmpBuf(pstSoftWareParam);
+ u32DstRoiSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32TotalSize + u32DstRoiSize + u32DstScoreSize + u32ClassRoiNumSize + u32TmpBufTotalSize;
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_YOLOV2_INIT", NULL, (HI_U64*)&u64PhyAddr,
+ (void**)&pu8VirAddr, u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void*)pu8VirAddr, u32TotalSize);
+
+ /*
+ * 设置每个tmp buffer地址
+ * Set each tmp buffer addr
+ */
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = (HI_U64)((HI_UL)pu8VirAddr);
+
+ /*
+ * 设置结果blob
+ * Set result blob
+ */
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr = (HI_U64)((HI_UL)pu8VirAddr + u32TmpBufTotalSize);
+ pstSoftWareParam->stDstRoi.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum *
+ u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width = u32ClassNum *
+ u32BboxNum*SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr = (HI_U64)((HI_UL)pu8VirAddr + u32TmpBufTotalSize + u32DstRoiSize);
+ pstSoftWareParam->stDstScore.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum*u32BboxNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize +
+ u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = (HI_U64)((HI_UL)pu8VirAddr + u32TmpBufTotalSize +
+ u32DstRoiSize + u32DstScoreSize);
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum*sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+static HI_S32 SampleSvpNnieYolov2SoftwareDeinit(SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S* pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if (pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr != 0 && pstSoftWareParam->stGetResultTmpBuf.u64VirAddr != 0) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr,
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr);
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = 0;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = 0;
+ pstSoftWareParam->stDstRoi.u64VirAddr = 0;
+ pstSoftWareParam->stDstScore.u64PhyAddr = 0;
+ pstSoftWareParam->stDstScore.u64VirAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+static HI_S32 SampleSvpNnieYolov2Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S* pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /*
+ * SAMPLE_SVP_NNIE_PARAM_S参数去初始化
+ * Hardware param deinit
+ */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(HI_SUCCESS != s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /*
+ * SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S参数去初始化
+ * Software deinit
+ */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SampleSvpNnieYolov2SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(HI_SUCCESS != s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SampleSvpNnieYolov2SoftwareDeinit failed!\n");
+ }
+
+ /*
+ * SAMPLE_SVP_NNIE_MODEL_S参数去初始化
+ * Model deinit
+ */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(HI_SUCCESS != s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+static HI_S32 SampleSvpNnieYolov2ParamInit(SAMPLE_SVP_NNIE_CFG_S* pstCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam, SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S* pstSoftWareParam)
+{
+ HI_S32 s32Ret;
+ /*
+ * 初始化hardware参数
+ * Init hardware param
+ */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /*
+ * 初始化software参数
+ * Init software param
+ */
+ s32Ret = SampleSvpNnieYolov2SoftwareInit(pstCfg, pstNnieParam,
+ pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov1_SoftwareInit failed!\n", s32Ret);
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SampleSvpNnieYolov2Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov1_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+/*=================================*/
+
+static void SAMPLE_SVP_NNIE_Yolov2_Stop(void)
+{
+ SAMPLE_SVP_NNIE_Yolov2_Deinit(&s_stYolov2NnieParam, &s_stYolov2SoftwareParam, &s_stYolov2Model);
+ (HI_VOID)memset_s(&s_stYolov2NnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov2SoftwareParam, sizeof(SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov2Model, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show YOLOV2 sample(image 416x416 U8_C3) */
+void SAMPLE_SVP_NNIE_Yolov2(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/2008_001538_640x384.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/resnet18_best_inst.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ f32PrintResultThresh = 0.2f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+
+ /* Yolov2 Load model */
+ SAMPLE_SVP_TRACE_INFO("Yolov2 Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stYolov2Model);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* Yolov2 parameter initialization */
+ /* Yolov2 software parameters are set in SAMPLE_SVP_NNIE_Yolov2_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Yolov2_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Yolov2 parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+ s_stYolov2NnieParam.pstModel = &s_stYolov2Model.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_ParamInit(&stNnieCfg, &s_stYolov2NnieParam, &s_stYolov2SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov2_ParamInit failed!\n");
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Yolov2 start!\n");
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stYolov2NnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ stProcSegIdx.u32SegIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stYolov2NnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* Software process */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Yolov2_GetResult
+ function input data are correct */
+
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_GetResult(&s_stYolov2NnieParam, &s_stYolov2SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov2_GetResult failed!\n");
+
+ /* print result, this sample has 6 classes:
+ class 0:background class 1:Carclass class 2:Vanclass
+ class 3:Truckclass class 4:Pedestrianclass class 5:Cyclist */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("Yolov2 result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stYolov2SoftwareParam.stDstScore, &s_stYolov2SoftwareParam.stDstRoi,
+ &s_stYolov2SoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+YOLOV2_FAIL_0:
+ SAMPLE_SVP_NNIE_Yolov2_Deinit(&s_stYolov2NnieParam, &s_stYolov2SoftwareParam, &s_stYolov2Model);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : Yolov2 sample signal handle */
+void SAMPLE_SVP_NNIE_Yolov2_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Yolov3 software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov3_SoftwareDeinit(SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr != 0) &&
+ (pstSoftWareParam->stGetResultTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr,
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr);
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = 0;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = 0;
+ pstSoftWareParam->stDstRoi.u64VirAddr = 0;
+ pstSoftWareParam->stDstScore.u64PhyAddr = 0;
+ pstSoftWareParam->stDstScore.u64VirAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Yolov3 Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov3_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov3_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Yolov3 software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov3_SoftwareInit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32TmpBufTotalSize = 0;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32BboxNumEachGrid = 3;
+ pstSoftWareParam->u32ClassNum = 80;
+ pstSoftWareParam->au32GridNumHeight[0] = 13;
+ pstSoftWareParam->au32GridNumHeight[1] = 26;
+ pstSoftWareParam->au32GridNumHeight[2] = 52;
+ pstSoftWareParam->au32GridNumWidth[0] = 13;
+ pstSoftWareParam->au32GridNumWidth[1] = 26;
+ pstSoftWareParam->au32GridNumWidth[2] = 52;
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.3f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32ConfThresh = (HI_U32)(0.5f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32MaxRoiNum = 10;
+ pstSoftWareParam->af32Bias[0][0] = 116;
+ pstSoftWareParam->af32Bias[0][1] = 90;
+ pstSoftWareParam->af32Bias[0][2] = 156;
+ pstSoftWareParam->af32Bias[0][3] = 198;
+ pstSoftWareParam->af32Bias[0][4] = 373;
+ pstSoftWareParam->af32Bias[0][5] = 326;
+ pstSoftWareParam->af32Bias[1][0] = 30;
+ pstSoftWareParam->af32Bias[1][1] = 61;
+ pstSoftWareParam->af32Bias[1][2] = 62;
+ pstSoftWareParam->af32Bias[1][3] = 45;
+ pstSoftWareParam->af32Bias[1][4] = 59;
+ pstSoftWareParam->af32Bias[1][5] = 119;
+ pstSoftWareParam->af32Bias[2][0] = 10;
+ pstSoftWareParam->af32Bias[2][1] = 13;
+ pstSoftWareParam->af32Bias[2][2] = 16;
+ pstSoftWareParam->af32Bias[2][3] = 30;
+ pstSoftWareParam->af32Bias[2][4] = 33;
+ pstSoftWareParam->af32Bias[2][5] = 23;
+
+ /* Malloc assist buffer memory */
+ u32ClassNum = pstSoftWareParam->u32ClassNum + 1;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(SAMPLE_SVP_NNIE_YOLOV3_REPORT_BLOB_NUM != pstNnieParam->pstModel->astSeg[0].u16DstNum,
+ HI_FAILURE, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,pstNnieParam->pstModel->astSeg[0].u16DstNum(%d) should be %d!\n",
+ pstNnieParam->pstModel->astSeg[0].u16DstNum, SAMPLE_SVP_NNIE_YOLOV3_REPORT_BLOB_NUM);
+ u32TmpBufTotalSize = SAMPLE_SVP_NNIE_Yolov3_GetResultTmpBuf(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32TmpBufTotalSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, SAMPLE_SVP_NNIE_Yolov3_GetResultTmpBuf failed!\n");
+ u32DstRoiSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32) *
+ SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32TotalSize + u32DstRoiSize + u32DstScoreSize + u32ClassRoiNumSize + u32TmpBufTotalSize;
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_YOLOV3_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set each tmp buffer addr */
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr);
+
+ /* set result blob */
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr + u32TmpBufTotalSize);
+ pstSoftWareParam->stDstRoi.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum *
+ sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width =
+ u32ClassNum * pstSoftWareParam->u32MaxRoiNum * SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr + u32TmpBufTotalSize + u32DstRoiSize);
+ pstSoftWareParam->stDstScore.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * pstSoftWareParam->u32MaxRoiNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize);
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : Yolov3 init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov3_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software para */
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_SoftwareInit(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov3_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov3_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+
+static hi_void SAMPLE_SVP_NNIE_Yolov3_Stop(hi_void)
+{
+ SAMPLE_SVP_NNIE_Yolov3_Deinit(&s_stYolov3NnieParam, &s_stYolov3SoftwareParam, &s_stYolov3Model);
+ (HI_VOID)memset_s(&s_stYolov3NnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov3SoftwareParam, sizeof(SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov3Model, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show YOLOV3 sample(image 416x416 U8_C3) */
+void SAMPLE_SVP_NNIE_Yolov3(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/dog_bike_car_416x416.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_yolov3_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };//初始化结构体
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov3_Stop();
+ return;
+ }
+
+ /* Yolov3 Load model */
+ SAMPLE_SVP_TRACE_INFO("Yolov3 Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stYolov3Model);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV3_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+
+ clock_t start,end;
+ double time_used;
+ start = clock();
+ /* Yolov3 parameter initialization */
+ /* Yolov3 software parameters are set in SAMPLE_SVP_NNIE_Yolov3_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Yolov3_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Yolov3 parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov3_Stop();
+ return;
+ }
+ s_stYolov3NnieParam.pstModel = &s_stYolov3Model.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_ParamInit(&stNnieCfg, &s_stYolov3NnieParam, &s_stYolov3SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV3_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov3_ParamInit failed!\n");
+
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Yolov3 start!\n");
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov3_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stYolov3NnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV3_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ stProcSegIdx.u32SegIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov3_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stYolov3NnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV3_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* Software process */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Yolov3_GetResult
+ function input data are correct */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov3_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_GetResult(&s_stYolov3NnieParam, &s_stYolov3SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV3_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov3_GetResult failed!\n");
+
+ /* print result, this sample has 81 classes:
+ class 0:background class 1:person class 2:bicycle class 3:car class 4:motorbike class
+ 5:aeroplane class 6:bus class 7:train class 8:truck class 9:boat class
+ 10:traffic light class 11:fire hydrant class 12:stop sign class 13:parking meter class 14:bench class
+ 15:bird class 16:cat class 17:dog class 18:horse class 19:sheep class 20:cow
+ class 21:elephant class 22:bear class 23:zebra class 24:giraffe class 25:backpack
+ class 26:umbrella class 27:handbag class 28:tie class 29:suitcase class 30:frisbee
+ class 31:skis class 32:snowboard class 33:sports ball class 34:kite class 35:baseball bat
+ class 36:baseball glove class 37:skateboard class 38:surfboard class 39:tennis racket class 40bottle
+ class 41:wine glass class 42:cup class 43:fork class 44:knife class 45:spoon
+ class 46:bowl class 47:banana class 48:apple class 49:sandwich class 50orange
+ class 51:broccoli class 52:carrot class 53:hot dog class 54:pizza class 55:donut
+ class 56:cake class 57:chair class 58:sofa class 59:pottedplant class 60bed
+ class 61:diningtable class 62:toilet class 63:vmonitor class 64:laptop class 65:mouse
+ class 66:remote class 67:keyboard class 68:cell phone class 69:microwave class 70:oven
+ class 71:toaster class 72:sink class 73:refrigerator class 74:book class 75:clock
+ class 76:vase class 77:scissors class 78:teddy bear class 79:hair drier class 80:toothbrush */
+ SAMPLE_SVP_TRACE_INFO("Yolov3 result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stYolov3SoftwareParam.stDstScore, &s_stYolov3SoftwareParam.stDstRoi,
+ &s_stYolov3SoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+ end = clock();
+ time_used = ((double)(end-start))/CLOCKS_PER_SEC;
+ printf("process time : %f ms\n",time_used/1000);
+
+YOLOV3_FAIL_0:
+ SAMPLE_SVP_NNIE_Yolov3_Deinit(&s_stYolov3NnieParam, &s_stYolov3SoftwareParam, &s_stYolov3Model);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : Yolov3 sample signal handle */
+void SAMPLE_SVP_NNIE_Yolov3_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Lstm Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Lstm_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParamm, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParamm != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParamm);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Lstm init */
+static HI_S32 SAMPLE_SVP_NNIE_Lstm_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstNnieCfg, SAMPLE_SVP_NNIE_PARAM_S *pstLstmPara)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstNnieCfg, pstLstmPara);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Lstm_Deinit(pstLstmPara, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Lstm_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+static hi_void SAMPLE_SVP_NNIE_Lstm_Stop(hi_void)
+{
+ SAMPLE_SVP_NNIE_Lstm_Deinit(&s_stLstmNnieParam, &s_stLstmModel);
+ (HI_VOID)memset_s(&s_stLstmNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stLstmModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show Lstm sample(vector) */
+void SAMPLE_SVP_NNIE_Lstm(void)
+{
+ const HI_CHAR *apcSrcFile[3] = {"./data/nnie_image/vector/Seq.SEQ_S32",
+ "./data/nnie_image/vector/Vec1.VEC_S32",
+ "./data/nnie_image/vector/Vec2.VEC_S32"};
+ const HI_CHAR *pchModelName = "./data/nnie_model/recurrent/lstm_3_3.wk";
+ HI_U8 *pu8VirAddr = NULL;
+ HI_U32 u32SegNum = 0;
+ HI_U32 u32Step = 0;
+ HI_U32 u32Offset = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 i = 0, j = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ stNnieCfg.u32MaxInputNum = 16; // max input data num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ u32Step = 20; // time step
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Lstm_Stop();
+ return;
+ }
+
+ /* Lstm Load model */
+ SAMPLE_SVP_TRACE_INFO("Lstm Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pchModelName, &s_stLstmModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* Lstm step initialization */
+ u32SegNum = s_stLstmModel.stModel.u32NetSegNum;
+ u32TotalSize = stNnieCfg.u32MaxInputNum * sizeof(HI_S32) * u32SegNum * 2;
+ s32Ret = SAMPLE_COMM_SVP_MallocMem("SVP_NNIE_STEP", NULL, (HI_U64 *)&s_stLstmNnieParam.stStepBuf.u64PhyAddr,
+ (void **)&pu8VirAddr, u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ /* Get step virtual addr */
+ s_stLstmNnieParam.stStepBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+ for (i = 0; i < u32SegNum * SAMPLE_SVP_NNIE_EACH_SEG_STEP_ADDR_NUM; i++) {
+ stNnieCfg.au64StepVirAddr[i] =
+ s_stLstmNnieParam.stStepBuf.u64VirAddr + i * stNnieCfg.u32MaxInputNum * sizeof(HI_S32);
+ }
+ /* Set step value, in this sample, the step values are set to be 20,
+ if user has changed input network, please set correct step
+ values according to the input network */
+ for (i = 0; i < u32SegNum; i++) {
+ u32Offset = i * SAMPLE_SVP_NNIE_EACH_SEG_STEP_ADDR_NUM;
+ for (j = 0; j < stNnieCfg.u32MaxInputNum; j++) {
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, stNnieCfg.au64StepVirAddr[u32Offset]) + j) =
+ u32Step; // step of input x_t
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, stNnieCfg.au64StepVirAddr[u32Offset + 1]) + j) =
+ u32Step; // step of output h_t
+ }
+ }
+
+ /* Lstm parameter initialization */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Lstm_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("Lstm parameter initialization!\n");
+ s_stLstmNnieParam.pstModel = &(s_stLstmModel.stModel);
+ s32Ret = SAMPLE_SVP_NNIE_Lstm_ParamInit(&stNnieCfg, &s_stLstmNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Lstm_ParamInit failed!\n");
+
+ /* Fill src data, in this sample, the 0-th seg is lstm network,if user has
+ changed input network,please make sure the value of stInputDataIdx.u32SegIdx
+ is correct */
+ SAMPLE_SVP_TRACE_INFO("Lstm start!\n");
+ stInputDataIdx.u32SegIdx = 0;
+ for (i = 0;
+ i < (s_stLstmNnieParam.pstModel->astSeg[stInputDataIdx.u32SegIdx].u16SrcNum) && (g_stop_signal == HI_FALSE);
+ i++) {
+ stNnieCfg.pszPic = apcSrcFile[i];
+ stInputDataIdx.u32NodeIdx = i;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stLstmNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+ }
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Lstm_Stop();
+ return;
+ }
+
+ /* NNIE process(process the 0-th segment) */
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stLstmNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* print report result */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Lstm_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_PrintReportResult(&s_stLstmNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_PrintReportResult failed!\n");
+
+ SAMPLE_SVP_TRACE_INFO("Lstm is successfully processed!\n");
+
+LSTM_FAIL_0:
+ SAMPLE_SVP_NNIE_Lstm_Deinit(&s_stLstmNnieParam, &s_stLstmModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : Lstm sample signal handle */
+void SAMPLE_SVP_NNIE_Lstm_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Pavnet software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Pvanet_SoftwareDeinit(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stRpnTmpBuf.u64PhyAddr != 0) && (pstSoftWareParam->stRpnTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stRpnTmpBuf.u64PhyAddr, pstSoftWareParam->stRpnTmpBuf.u64VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Pvanet Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Pvanet_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Pvanet_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Pvanet software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Pvanet_SoftwareInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RpnTmpBufSize = 0;
+ HI_U32 u32RpnBboxBufSize = 0;
+ HI_U32 u32GetResultTmpBufSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* RPN parameter init */
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->u32MaxRoiNum = pstCfg->u32MaxRoiNum;
+ pstSoftWareParam->u32ClassNum = 21;
+ pstSoftWareParam->u32NumRatioAnchors = 7;
+ pstSoftWareParam->u32NumScaleAnchors = 6;
+ pstSoftWareParam->au32Ratios[0] = (HI_S32)(0.333 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[1] = (HI_S32)(0.5 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[2] = (HI_S32)(0.667 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[3] = (HI_S32)(1 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[4] = (HI_S32)(1.5 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[5] = (HI_S32)(2 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[6] = (HI_S32)(3 * SAMPLE_SVP_QUANT_BASE);
+
+ pstSoftWareParam->au32Scales[0] = 2 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[1] = 3 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[2] = 5 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[3] = 9 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[4] = 16 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[5] = 32 * SAMPLE_SVP_QUANT_BASE;
+
+ /* set origin image height & width from src[0] shape */
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+
+ pstSoftWareParam->u32MinSize = 16;
+ pstSoftWareParam->u32SpatialScale = (HI_U32)(0.0625 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.7 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->u32FilterThresh = 0;
+ pstSoftWareParam->u32ValidNmsThresh = (HI_U32)(0.3 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->u32NumBeforeNms = 12000;
+ pstSoftWareParam->u32MaxRoiNum = 200;
+
+ for (i = 0; i < pstSoftWareParam->u32ClassNum; i++) {
+ pstSoftWareParam->au32ConfThresh[i] = 1;
+ }
+
+ pstSoftWareParam->stRpnBbox.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height = pstCfg->u32MaxRoiNum;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Width = SAMPLE_SVP_COORDI_NUM;
+ pstSoftWareParam->stRpnBbox.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(SAMPLE_SVP_COORDI_NUM * sizeof(HI_U32));
+ pstSoftWareParam->stRpnBbox.u32Num = 1;
+ for (i = 0; i < SAMPLE_SVP_NNIE_SEGMENT_NUM; i++) {
+ for (j = 0; j < pstNnieParam->pstModel->astSeg[0].u16DstNum; j++) {
+ if (strncmp(pstNnieParam->pstModel->astSeg[0].astDstNode[j].szName,
+ pstSoftWareParam->apcRpnDataLayerName[i], SVP_NNIE_NODE_NAME_LEN) == 0) {
+ pstSoftWareParam->aps32Conv[i] =
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstNnieParam->astSegData[0].astDst[j].u64VirAddr);
+ pstSoftWareParam->au32ConvHeight[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Height;
+ pstSoftWareParam->au32ConvWidth[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Width;
+ pstSoftWareParam->au32ConvChannel[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Chn;
+ break;
+ }
+ }
+ SAMPLE_SVP_CHECK_EXPR_RET((j == pstNnieParam->pstModel->astSeg[0].u16DstNum), HI_FAILURE,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,failed to find report node %s!\n",
+ pstSoftWareParam->apcRpnDataLayerName[i]);
+ if (i == 0) {
+ pstSoftWareParam->u32ConvStride = pstNnieParam->astSegData[0].astDst[j].u32Stride;
+ }
+ }
+ /* calculate software mem size */
+ u32ClassNum = pstSoftWareParam->u32ClassNum;
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_RpnTmpBufSize(pstSoftWareParam->u32NumRatioAnchors,
+ pstSoftWareParam->u32NumScaleAnchors, pstSoftWareParam->au32ConvHeight[0], pstSoftWareParam->au32ConvWidth[0]);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32RpnTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_RpnTmpBufSize failed!\n");
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32RpnTmpBufSize);
+ u32RpnBboxBufSize = pstSoftWareParam->stRpnBbox.u32Num * pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height *
+ pstSoftWareParam->stRpnBbox.u32Stride;
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_Pvanet_GetResultTmpBufSize(pstCfg->u32MaxRoiNum, u32ClassNum);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32GetResultTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Pvanet_GetResultTmpBufSize failed!\n");
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32GetResultTmpBufSize);
+ u32DstRoiSize =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32) * SAMPLE_SVP_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize +
+ u32ClassRoiNumSize;
+
+ /* malloc mem */
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_Pvanet_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set addr */
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u32Size = u32RpnTmpBufSize;
+
+ pstSoftWareParam->stRpnBbox.u64PhyAddr = u64PhyAddr + u32RpnTmpBufSize;
+ pstSoftWareParam->stRpnBbox.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr) + u32RpnTmpBufSize;
+
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize);
+ pstSoftWareParam->stGetResultTmpBuf.u32Size = u32GetResultTmpBufSize;
+
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize);
+ pstSoftWareParam->stDstRoi.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32) * SAMPLE_SVP_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width =
+ u32ClassNum * pstSoftWareParam->u32MaxRoiNum * SAMPLE_SVP_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr =
+ u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize +
+ u32GetResultTmpBufSize + u32DstRoiSize);
+ pstSoftWareParam->stDstScore.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * pstSoftWareParam->u32MaxRoiNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr =
+ u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64,
+ pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize);
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : Pvanet parameter initialization */
+static HI_S32 SAMPLE_SVP_NNIE_Pvanet_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstFasterRcnnCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam, SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware parameter */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstFasterRcnnCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software parameter */
+ s32Ret = SAMPLE_SVP_NNIE_Pvanet_SoftwareInit(pstFasterRcnnCfg, pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Pvanet_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_FasterRcnn_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+static hi_void SAMPLE_SVP_NNIE_Pvanet_Stop(hi_void)
+{
+ SAMPLE_SVP_NNIE_FasterRcnn_Deinit(&s_stPvanetNnieParam, &s_stPvanetSoftwareParam, &s_stPvanetModel);
+ (HI_VOID)memset_s(&s_stPvanetNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stPvanetSoftwareParam, sizeof(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stPvanetModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show Pvanet fasterRcnn sample(image 224x224 U8_C3) */
+void SAMPLE_SVP_NNIE_Pvanet(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/horse_dog_car_person_224x224.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_fasterrcnn_pvanet_inst.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 i = 0;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ s_enNetType = SAMPLE_SVP_NNIE_PVANET_FASTER_RCNN;
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.u32MaxInputNum = u32PicNum;
+ stNnieCfg.u32MaxRoiNum = 200;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0;
+ stNnieCfg.aenNnieCoreId[1] = SVP_NNIE_ID_0;
+ g_stop_signal = HI_FALSE;
+
+ /* Sys_init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+
+ /* FasterRcnn Load model */
+ SAMPLE_SVP_TRACE_INFO("Pvanet load Model!!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stPvanetModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "ERROR, SAMPLE_COMM_SVP_NNIE_LoadModel failed\n");
+
+ /* Pvanet para init */
+ /* apcRpnDataLayerName is used to set RPN data layer name
+ and search RPN input data,if user has changed network struct, please
+ make sure the data layer names are correct */
+ /* Pvanet parameters are set in SAMPLE_SVP_NNIE_Pvanet_SoftwareInit,
+ if user has changed network struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Pvanet parameter initialization!\n");
+ s_stPvanetNnieParam.pstModel = &s_stPvanetModel.stModel;
+ s_stPvanetSoftwareParam.apcRpnDataLayerName[0] = "rpn_cls_score";
+ s_stPvanetSoftwareParam.apcRpnDataLayerName[1] = "rpn_bbox_pred";
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Pvanet_ParamInit(&stNnieCfg, &s_stPvanetNnieParam, &s_stPvanetSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Pvanet_ParamInit failed!\n");
+
+ /* Fill 0-th input node of 0-th seg */
+ SAMPLE_SVP_TRACE_INFO("Pvanet start!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stPvanetNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "ERROR, SAMPLE_SVP_NNIE_FillSrcData Failed!!\n");
+
+ /* NNIE process 0-th seg */
+ stProcSegIdx.u32SegIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stPvanetNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* Do RPN */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Pvanet_Rpn(&s_stPvanetSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Pvanet_Rpn failed!\n");
+ if (s_stPvanetSoftwareParam.stRpnBbox.unShape.stWhc.u32Height != 0 && g_stop_signal == HI_FALSE) {
+ /* NNIE process 1-th seg, the input conv data comes from 0-th seg's 0-th report node,
+ the input roi comes from RPN results */
+ stInputDataIdx.u32NodeIdx = 0;
+ stInputDataIdx.u32SegIdx = 0;
+ stProcSegIdx.u32SegIdx = 1;
+ s32Ret = SAMPLE_SVP_NNIE_ForwardWithBbox(&s_stPvanetNnieParam, &stInputDataIdx,
+ &s_stPvanetSoftwareParam.stRpnBbox, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_ForwardWithBbox failed!\n");
+
+ /* GetResult */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_FasterRcnn_GetResult
+ function's input data are correct */
+ s32Ret = SAMPLE_SVP_NNIE_Pvanet_GetResult(&s_stPvanetNnieParam, &s_stPvanetSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "ERROR, SAMPLE_SVP_NNIE_Pvanet_GetResult Failed!\n");
+ } else {
+ for (i = 0; i < s_stPvanetSoftwareParam.stClassRoiNum.unShape.stWhc.u32Width; i++) {
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, s_stPvanetSoftwareParam.stClassRoiNum.u64VirAddr) + i) = 0;
+ }
+ }
+
+ /* print result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("Pvanet result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stPvanetSoftwareParam.stDstScore, &s_stPvanetSoftwareParam.stDstRoi,
+ &s_stPvanetSoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+PVANET_FAIL_0:
+ SAMPLE_SVP_NNIE_Pvanet_Deinit(&s_stPvanetNnieParam, &s_stPvanetSoftwareParam, &s_stPvanetModel);
+
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+void SAMPLE_SVP_NNIE_Pvanet_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/******************************************************************************
+* function : roi to rect
+******************************************************************************/
+HI_S32 SAMPLE_SVP_NNIE_RoiToRect_Yolov3(SVP_BLOB_S *pstDstScore,
+ SVP_BLOB_S *pstDstRoi, SVP_BLOB_S *pstClassRoiNum, HI_FLOAT *paf32ScoreThr,
+ HI_BOOL bRmBg,SAMPLE_SVP_NNIE_RECT_ARRAY_S *pstRect,
+ HI_U32 u32SrcWidth, HI_U32 u32SrcHeight,HI_U32 u32DstWidth,HI_U32 u32DstHeight)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RoiNumBias = 0;
+ HI_U32 u32ScoreBias = 0;
+ HI_U32 u32BboxBias = 0;
+ HI_FLOAT f32Score = 0.0f;
+ HI_S32* ps32Score = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstDstScore->u64VirAddr);
+ HI_S32* ps32Roi = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstDstRoi->u64VirAddr);
+ HI_S32* ps32ClassRoiNum = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstClassRoiNum->u64VirAddr);
+ HI_U32 u32ClassNum = pstClassRoiNum->unShape.stWhc.u32Width;
+ HI_U32 u32RoiNumTmp = 0;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(u32ClassNum > 82 ,HI_ERR_SVP_NNIE_ILLEGAL_PARAM,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),u32ClassNum(%u) must be less than or equal %u to!\n",HI_ERR_SVP_NNIE_ILLEGAL_PARAM,u32ClassNum, 82);
+
+
+ pstRect->u32TotalNum = 0;
+ pstRect->u32ClsNum = u32ClassNum;
+ if (bRmBg)
+ {
+ pstRect->au32RoiNum[0] = 0;
+ u32RoiNumBias += ps32ClassRoiNum[0];
+ for (i = 1; i < u32ClassNum; i++)
+ {
+ u32ScoreBias = u32RoiNumBias;
+ u32BboxBias = u32RoiNumBias * SAMPLE_SVP_NNIE_COORDI_NUM;
+ u32RoiNumTmp = 0;
+ /*if the confidence score greater than result thresh, the result will be drawed*/
+ if(((HI_FLOAT)ps32Score[u32ScoreBias] / SAMPLE_SVP_NNIE_QUANT_BASE >=
+ paf32ScoreThr[i]) && (ps32ClassRoiNum[i] != 0))
+ {
+ for (j = 0; j < (HI_U32)ps32ClassRoiNum[i]; j++)
+ {
+ /*Score is descend order*/
+ f32Score = (HI_FLOAT)ps32Score[u32ScoreBias + j] / SAMPLE_SVP_NNIE_QUANT_BASE;
+ if ((f32Score < paf32ScoreThr[i]) || (u32RoiNumTmp >= SAMPLE_SVP_NNIE_MAX_ROI_NUM_OF_CLASS))
+ {
+ break;
+ }
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM] / (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1) ;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 1] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 2]/ (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1);
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32Y = pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y;
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32X = pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 3] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32X = pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32Y = pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y;
+
+ u32RoiNumTmp++;
+ }
+
+ }
+
+ pstRect->au32RoiNum[i] = u32RoiNumTmp;
+ pstRect->u32TotalNum += u32RoiNumTmp;
+ u32RoiNumBias += ps32ClassRoiNum[i];
+ }
+
+ }
+ return HI_SUCCESS;
+}
+
+
+/******************************************************************************
+* function : Yolov3 Procession ViToVo
+******************************************************************************/
+static HI_S32 SAMPLE_SVP_NNIE_Yolov3_Proc_ViToVo(SAMPLE_SVP_NNIE_PARAM_S *pstParam,
+ SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSwParam, VIDEO_FRAME_INFO_S* pstExtFrmInfo,
+ HI_U32 u32BaseWidth,HI_U32 u32BaseHeight)
+{
+ HI_S32 s32Ret = HI_FAILURE;
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = {0};
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = {0};
+
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ HI_FLOAT f32PrintResultThresh = 0.8f;
+ /*SP420*/
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64VirAddr = pstExtFrmInfo->stVFrame.u64VirAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64PhyAddr = pstExtFrmInfo->stVFrame.u64PhyAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u32Stride = pstExtFrmInfo->stVFrame.u32Stride[0];
+
+
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stYolov3NnieParam,&stInputDataIdx,&stProcSegIdx,HI_TRUE);
+
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov3_Proc failed!\n");
+ /*draw result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor*/
+
+ /*Software process*/
+ /*if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Yolov3_GetResult
+ function input datas are correct*/
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_GetResult(&s_stYolov3NnieParam,&s_stYolov3SoftwareParam);
+
+
+ // (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&(pstSwParam->stDstScore), &(pstSwParam->stDstRoi), &(pstSwParam->stClassRoiNum),f32PrintResultThresh);
+
+ SAMPLE_SVP_TRACE_INFO("Yolov3 result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stYolov3SoftwareParam.stDstScore,
+ &s_stYolov3SoftwareParam.stDstRoi, &s_stYolov3SoftwareParam.stClassRoiNum,f32PrintResultThresh);
+
+ s32Ret = SAMPLE_SVP_NNIE_RoiToRect_Yolov3(&(pstSwParam->stDstScore),
+ &(pstSwParam->stDstRoi), &(pstSwParam->stClassRoiNum), pstSwParam->af32ScoreThr,HI_TRUE,&(pstSwParam->stRect),
+ pstExtFrmInfo->stVFrame.u32Width, pstExtFrmInfo->stVFrame.u32Height,u32BaseWidth,u32BaseHeight);
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_RoiToRect failed!\n",s32Ret);
+
+ return s32Ret;
+
+}
+/******************************************************************************
+* function : Yolov3 vi to vo thread entry
+******************************************************************************/
+static HI_VOID* SAMPLE_SVP_NNIE_Yolov3_ViToVo_thread(HI_VOID* pArgs)
+{
+ HI_S32 s32Ret;
+ SAMPLE_SVP_NNIE_PARAM_S *pstParam;
+ SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSwParam;
+ VIDEO_FRAME_INFO_S stBaseFrmInfo;
+ VIDEO_FRAME_INFO_S stExtFrmInfo;
+ HI_S32 s32MilliSec = 20000;
+ VO_LAYER voLayer = 0;
+ VO_CHN voChn = 0;
+ HI_S32 s32VpssGrp = 0;
+ HI_S32 as32VpssChn[] = {VPSS_CHN0, VPSS_CHN1};
+
+ pstParam = &s_stYolov3NnieParam;
+ pstSwParam = &s_stYolov3SoftwareParam;
+
+ struct timespec start_time,end_time;
+ float use_time =0;
+
+ while (HI_FALSE == s_bNnieStopSignal)
+ {
+ clock_gettime(CLOCK_REALTIME, &start_time);
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[1], &stExtFrmInfo, s32MilliSec);
+ if(HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
+ s32Ret,s32VpssGrp, as32VpssChn[1]);
+ continue;
+ }
+
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[0], &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, EXT_RELEASE,
+ "Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
+ s32Ret,s32VpssGrp, as32VpssChn[0]);
+
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_Proc_ViToVo(pstParam,pstSwParam, &stExtFrmInfo,
+ stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "Error(%#x),SAMPLE_SVP_NNIE_YOLOV3_Proc failed!\n", s32Ret);
+
+ // SAMPLE_SVP_TRACE_INFO("The Width is %d\n", stExtFrmInfo.stVFrame.u32Width);
+ // SAMPLE_SVP_TRACE_INFO("The Height is %d\n", stExtFrmInfo.stVFrame.u32Height);
+
+
+ //Draw rect
+ s32Ret = SAMPLE_COMM_SVP_NNIE_FillRect(&stBaseFrmInfo, &(pstSwParam->stRect), 0x0000FF00);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "SAMPLE_COMM_SVP_NNIE_FillRect failed, Error(%#x)!\n", s32Ret);
+
+ s32Ret = HI_MPI_VO_SendFrame(voLayer, voChn, &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "HI_MPI_VO_SendFrame failed, Error(%#x)!\n", s32Ret);
+
+ clock_gettime(CLOCK_REALTIME, &end_time);
+ use_time = (float)(end_time.tv_sec - start_time.tv_sec)*1000 + (end_time.tv_nsec - start_time.tv_nsec) / 1000000.0;
+ SAMPLE_SVP_TRACE_INFO("The use time is %f \n", use_time);
+
+
+
+ BASE_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[0], &stBaseFrmInfo);
+ if (HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
+ s32Ret,s32VpssGrp,as32VpssChn[0]);
+ }
+
+ EXT_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[1], &stExtFrmInfo);
+ if (HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
+ s32Ret,s32VpssGrp,as32VpssChn[1]);
+ }
+
+ }
+
+ return HI_NULL;
+}
+/******************************************************************************
+* function : Yolov3 vi to vo real time detection
+******************************************************************************/
+void SAMPLE_SVP_NNIE_Yolov3_Vivo(void)
+{
+ // HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/dog_bike_car_416x416.bgr";
+ HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_yolov3_cycle.wk";
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = {0};
+ SIZE_S stSize;
+ PIC_SIZE_E enSize = PIC_CIF;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_CHAR acThreadName[16] = {0};
+
+
+
+
+ /*Sys init*/
+ SAMPLE_COMM_SVP_CheckSysInit();
+
+ /******************************************
+ step 1: start vi vpss vo
+ ******************************************/
+ s_stYolov3Switch.bVenc = HI_FALSE;
+ s_stYolov3Switch.bVo = HI_TRUE;
+ s32Ret = SAMPLE_COMM_IVE_StartViVpssVencVo_Yolov3(&s_stViConfig,&s_stYolov3Switch,&enSize);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, YOLOV3_FAIL_1,
+ "Error(%#x),SAMPLE_COMM_IVE_StartViVpssVencVo failed!\n", s32Ret);
+
+ s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSize, &stSize);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, YOLOV3_FAIL_1,
+ "Error(%#x),SAMPLE_COMM_SYS_GetPicSize failed!\n", s32Ret);
+
+ stSize.u32Width = 640;
+ stSize.u32Height = 384;
+
+ /******************************************
+ step 2: init NNIE param
+ ******************************************/
+ stNnieCfg.pszPic= NULL;
+ stNnieCfg.u32MaxInputNum = 1;
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0;//set NNIE core
+
+ /*Yolov3 Load model*/
+ SAMPLE_SVP_TRACE_INFO("Yolov3 Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName,&s_stYolov3Model);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret,YOLOV3_FAIL_0,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /*Yolov3 parameter initialization*/
+ /*Yolov3 software parameters are set in SAMPLE_SVP_NNIE_Yolov3_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Yolov3_SoftwareInit function are correct*/
+ SAMPLE_SVP_TRACE_INFO("Yolov3 parameter initialization!\n");
+ s_stYolov3NnieParam.pstModel = &s_stYolov3Model.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_ParamInit(&stNnieCfg,&s_stYolov3NnieParam,&s_stYolov3SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret,YOLOV3_FAIL_0,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov3_ParamInit failed!\n");
+
+ /*Fill src data*/
+ SAMPLE_SVP_TRACE_INFO("Yolov3 start!\n");
+
+
+ s_bNnieStopSignal = HI_FALSE;
+ /******************************************
+ step 3: Create work thread
+ ******************************************/
+ snprintf(acThreadName, 16, "NNIE_ViToVo");
+ prctl(PR_SET_NAME, (unsigned long)acThreadName, 0,0,0);
+ pthread_create(&s_hNnieThread, 0, SAMPLE_SVP_NNIE_Yolov3_ViToVo_thread, NULL);
+ SAMPLE_PAUSE();
+
+ s_bNnieStopSignal = HI_TRUE;
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+
+
+
+YOLOV3_FAIL_1:
+ SAMPLE_SVP_NNIE_Yolov3_Deinit(&s_stYolov3NnieParam,&s_stYolov3SoftwareParam,&s_stYolov3Model);
+
+YOLOV3_FAIL_0:
+ SAMPLE_COMM_IVE_StopViVpssVencVo_Yolov3(&s_stViConfig,&s_stYolov3Switch);
+
+}
+
+void SAMPLE_SVP_NNIE_Yolov3_Vivo_HandleSig(void)
+{
+ s_bNnieStopSignal = HI_TRUE;
+ if (0 != s_hNnieThread)
+ {
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+ }
+
+ SAMPLE_SVP_NNIE_Yolov3_Deinit(&s_stYolov3NnieParam,&s_stYolov3SoftwareParam,&s_stYolov3Model);
+ memset(&s_stYolov3NnieParam,0,sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ memset(&s_stYolov3SoftwareParam,0,sizeof(SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S));
+ memset(&s_stYolov3Model,0,sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+
+ SAMPLE_COMM_IVE_StopViVpssVencVo_Yolov3(&s_stViConfig,&s_stYolov3Switch);
+
+}
+
+
+#define Net_FRM_WIDTH 640
+#define Net_FRM_HEIGHT 384
+/*===========================================================================*/
+/******************************************************************************
+* function : roi to rect Yolov2
+******************************************************************************/
+HI_S32 SAMPLE_SVP_NNIE_RoiToRect_Yolov2(SVP_BLOB_S *pstDstScore,
+ SVP_BLOB_S *pstDstRoi, SVP_BLOB_S *pstClassRoiNum, HI_FLOAT *paf32ScoreThr,
+ HI_BOOL bRmBg,SAMPLE_SVP_NNIE_RECT_ARRAY_S *pstRect,
+ HI_U32 u32SrcWidth, HI_U32 u32SrcHeight,HI_U32 u32DstWidth,HI_U32 u32DstHeight)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RoiNumBias = 0;
+ HI_U32 u32ScoreBias = 0;
+ HI_U32 u32BboxBias = 0;
+ HI_FLOAT f32Score = 0.0f;
+ HI_S32* ps32Score = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstDstScore->u64VirAddr);
+ HI_S32* ps32Roi = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstDstRoi->u64VirAddr);
+ HI_S32* ps32ClassRoiNum = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstClassRoiNum->u64VirAddr);
+ HI_U32 u32ClassNum = pstClassRoiNum->unShape.stWhc.u32Width;
+ HI_U32 u32RoiNumTmp = 0;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(u32ClassNum > 4 ,HI_ERR_SVP_NNIE_ILLEGAL_PARAM,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),u32ClassNum(%u) must be less than or equal %u to!\n",HI_ERR_SVP_NNIE_ILLEGAL_PARAM,u32ClassNum, 4);
+
+
+ pstRect->u32TotalNum = 0;
+ pstRect->u32ClsNum = u32ClassNum;
+ if (bRmBg)
+ {
+ pstRect->au32RoiNum[0] = 0;
+ u32RoiNumBias += ps32ClassRoiNum[0];
+ for (i = 1; i < u32ClassNum; i++)
+ {
+ u32ScoreBias = u32RoiNumBias;
+ u32BboxBias = u32RoiNumBias * SAMPLE_SVP_NNIE_COORDI_NUM;
+ u32RoiNumTmp = 0;
+ /*if the confidence score greater than result thresh, the result will be drawed*/
+ if(((HI_FLOAT)ps32Score[u32ScoreBias] / SAMPLE_SVP_NNIE_QUANT_BASE >=
+ paf32ScoreThr[i]) && (ps32ClassRoiNum[i] != 0))
+ {
+ for (j = 0; j < (HI_U32)ps32ClassRoiNum[i]; j++)
+ {
+ /*Score is descend order*/
+ f32Score = (HI_FLOAT)ps32Score[u32ScoreBias + j] / SAMPLE_SVP_NNIE_QUANT_BASE;
+ if ((f32Score < paf32ScoreThr[i]) || (u32RoiNumTmp >= SAMPLE_SVP_NNIE_MAX_ROI_NUM_OF_CLASS))
+ {
+ break;
+ }
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM] / (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1) ;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 1] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 2]/ (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1);
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32Y = pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y;
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32X = pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 3] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32X = pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32Y = pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y;
+
+ u32RoiNumTmp++;
+ }
+
+ }
+
+ pstRect->au32RoiNum[i] = u32RoiNumTmp;
+ pstRect->u32TotalNum += u32RoiNumTmp;
+ u32RoiNumBias += ps32ClassRoiNum[i];
+ }
+
+ }
+ return HI_SUCCESS;
+}
+
+#define FOCUS_LEN 25
+#define FOCUS_THRESH 12
+#define MISS_THRESH 3
+#define TRACK_TRESH 3
+#define MATCH_THRESH 0.4
+#define BUF_LEN 80
+
+typedef struct TRACK_ID {
+ // RectBox box_prev;
+ //Yolo2FetchRes得到的resBuf相当于current时刻的box,PERSON_ID中的box_curr相当于上一帧的box,所以不需要box_prev这个变量了
+ RectBox box_curr;
+ // HI_U32 cls_arr[FOCUS_LEN];
+ int cls;
+ HI_U32 box_ID;
+ HI_U32 miss_hits;
+ HI_BOOL matched_flag;
+ HI_U32 tracked_count;
+ HI_BOOL tracked_flag;
+ float focused_time[FOCUS_LEN]; //循环利用
+ float focused_time_total;
+ float live_time;
+ HI_BOOL accumulate_first_flag;
+} PERSON_ID;
+
+//这么写会重复累加,导致统计的注意力时长大于实际的
+// HI_VOID Accumulate_Focused_Time(float focused_time[], int len)
+// {
+// int i;
+// int focused_count=0;
+// float sum=0;
+// //static HI_U32 focused_time_total=0;
+// for(i=0;i0){
+// sum+=focused_time[i];
+// focused_count++;
+// }
+// }
+// if(focused_count>=FOCUS_THRESH)
+// focused_time_total+=sum;
+// }
+
+//应该对每一个ID维护一个accumulate_first_flag的标志,否则会造成统计的注意力时长偏小
+// HI_VOID Accumulate_Focused_Time(float focused_time[], int len, int frame_curr)
+// {
+// int i;
+// int focused_count=0;
+// if(accumulate_first_flag==HI_FALSE){
+// float sum=0;
+// for(i=0;i0){
+// sum+=focused_time[i];
+// focused_count++;
+// }
+// }
+// if(focused_count>=FOCUS_THRESH)
+// focused_time_total+=sum;
+// accumulate_first_flag=HI_TRUE;
+// }
+// else{
+// for(i=0;i0)
+// focused_count++;
+// if(focused_count>=FOCUS_THRESH)
+// focused_time_total+=focused_time[frame_curr];
+// }
+// }
+
+// HI_VOID Accumulate_Focused_Time(PERSON_ID *ID, int len, int frame_curr, float live_time_tmp)
+HI_VOID Accumulate_Focused_Time(PERSON_ID *ID, int len, int frame_curr)
+{
+ int i;
+ int focused_count=0;
+ if(ID->accumulate_first_flag==HI_FALSE){
+ float sum=0;
+ for(i=0;ifocused_time[i]>0){
+ sum+=ID->focused_time[i];
+ focused_count++;
+ }
+ }
+ if(focused_count>=FOCUS_THRESH){
+ focused_time_total+=sum;
+ ID->focused_time_total+=sum;
+ ID->accumulate_first_flag=HI_TRUE;
+ }
+ }
+ else{
+ for(i=0;ifocused_time[i]>0)
+ focused_count++;
+ if(focused_count>=FOCUS_THRESH){
+ focused_time_total+=ID->focused_time[frame_curr];
+ ID->focused_time_total+=ID->focused_time[frame_curr];
+ }
+ }
+ // ID->live_time += live_time_tmp;
+}
+
+HI_DOUBLE Track_Yolov2_Iou(RectBox *box1, RectBox *box2)
+{
+ HI_FLOAT f32InterWidth = 0.0;
+ HI_FLOAT f32InterHeight = 0.0;
+ HI_DOUBLE f64InterArea = 0.0;
+ HI_DOUBLE f64Box1Area = 0.0;
+ HI_DOUBLE f64Box2Area = 0.0;
+ HI_DOUBLE f64UnionArea = 0.0;
+
+ f32InterWidth = (HI_FLOAT)(SAMPLE_SVP_NNIE_MIN(box1->xmax,box2->xmax)-SAMPLE_SVP_NNIE_MAX(box1->xmin,box2->xmin));
+ f32InterHeight = (HI_FLOAT)(SAMPLE_SVP_NNIE_MIN(box1->ymax,box2->ymax)-SAMPLE_SVP_NNIE_MAX(box1->ymin,box2->ymin));
+ if (f32InterWidth <= 0 || f32InterHeight <= 0)
+ return 0;
+
+ f64InterArea = f32InterWidth * f32InterHeight;
+ f64Box1Area = (HI_DOUBLE)((box1->xmax - box1->xmin) * (box1->ymax - box1->ymin));
+ f64Box2Area = (HI_DOUBLE)((box2->xmax - box2->xmin) * (box2->ymax - box2->ymin));
+ f64UnionArea = f64Box1Area + f64Box2Area - f64InterArea;
+
+ return f64InterArea / f64UnionArea;
+}
+
+/*
+参数初始化放在SAMPLE_SVP_NNIE_Yolov2_ViToVo_thread()函数的前面
+注意:刚开始跟踪时box_prev为空
+对每一帧进行跟踪时,都将matched_flag置为False
+
+匹配成功:
+1、box_prev与box_curr两两之间计算IOU,匹配最大的那个,视为同一个目标ID,置其matched_flag为True
+匹配失败:
+2、漏检,不更新box_curr,miss_hits+=1,连续超过3帧漏检(miss_hits>3)则丢弃该目标ID,否则将miss_hits清零
+3、新增目标ID
+*/
+
+//resBuf把box信息传给ID_arr
+int Trivial_Track_Yolov2(DetectObjInfo resBuf[], int resLen, float usedTime, PERSON_ID ID_arr[], int prevBoxNum, HI_U32 frame, HI_FLOAT *AD_attractiveness_tmp)
+{
+ int i,j;
+ int frame_tmp=frame%FOCUS_LEN;
+ int box_curr_num=0;
+ // RectBox *box_tmp;
+ HI_DOUBLE max_IOU;
+ HI_DOUBLE IOU_tmp;
+ HI_BOOL matched_flag[DETECT_OBJ_MAX]={0};
+ int max_idx;
+ // HI_BOOL all_matched_flag;
+ //static HI_U32 ID_num_total=0; //被跟踪的总人数
+
+ //算法刚开始运行的第一帧或前面一帧没有目标(要么一直没有目标,要么目标因为恰好消失或漏检次数超过阈值而丢弃)的情况,不需要考虑box_prev,不需要进行IOU匹配
+ //前一帧prevBoxNum==0的情况说明当前帧的框都是新增的!所以根本没必要累积注意力时长
+ if (prevBoxNum==0){
+ for(i=0;ixmin = resBuf[i].box.xmin;
+ // box_tmp->ymin = resBuf[i].box.ymin;
+ // box_tmp->xmax = resBuf[i].box.xmax;
+ // box_tmp->ymax = resBuf[i].box.ymax;
+ ID_arr[i].box_curr=resBuf[i].box;
+ // ID_arr[i].box_ID = ID_num_total;
+ // ID_num_total++;
+ ID_arr[i].cls=resBuf[i].cls;
+ ID_arr[i].miss_hits=0;
+ // if(ID_arr[i].tracked_flag==HI_FALSE)
+ ID_arr[i].tracked_count=1;
+ ID_arr[i].tracked_flag=HI_FALSE;
+ ID_arr[i].focused_time_total=0;
+ ID_arr[i].live_time=usedTime;
+ ID_arr[i].accumulate_first_flag=HI_FALSE;
+ if(resBuf[i].cls==2){
+ ID_arr[i].focused_time[frame_tmp] = usedTime;
+ }
+ // else if (resBuf[i].cls==1){
+ else{
+ ID_arr[i].focused_time[frame_tmp] = 0;
+ }
+ // printf("boxcurr(%d,%d,%d,%d),ID:%d,cls%d,hitmiss%d",ID_arr[i].box_curr.xmin,ID_arr[i].box_curr.ymin,ID_arr[i].box_curr.xmax,
+ // ID_arr[i].box_curr.ymax,ID_arr[i].box_ID,ID_arr[i].cls,ID_arr[i].miss_hits);
+ // if(frame>1 && ID_arr[i].tracked_flag==HI_TRUE) //第一帧不需要累积注意力时长
+ // Accumulate_Focused_Time(ID_arr[i].focused_time,FOCUS_LEN,frame_tmp);
+ }
+ prevBoxNum = resLen;
+ }
+ else if (prevBoxNum>0)
+ {
+ //matched_flag初始化为False
+ for(i=0;iprevBoxNum: 丢失的目标数<新增的目标数(新进入画面或者连续超过3帧漏检)
+ //resLen==prevBoxNum: 刚好匹配;丢失的目标数==新增的目标数
+ //resLen新增的目标数
+ for(i=0;imax_IOU){
+ max_IOU=IOU_tmp;
+ max_idx=j;
+ }
+ }
+ }
+ //匹配成功
+ if(max_IOU>MATCH_THRESH){
+ matched_flag[max_idx]=HI_TRUE;
+ // ID_arr[i].box_prev=ID_arr[i].box_curr;
+ ID_arr[i].box_curr=resBuf[max_idx].box;
+ ID_arr[i].miss_hits=0;
+ ID_arr[i].matched_flag=HI_TRUE;
+ ID_arr[i].cls=resBuf[max_idx].cls;
+ if(resBuf[max_idx].cls==2)
+ ID_arr[i].focused_time[frame_tmp] = usedTime;
+ else if(resBuf[max_idx].cls==1)
+ ID_arr[i].focused_time[frame_tmp] = 0;
+ ID_arr[i].live_time += usedTime;
+ if(ID_arr[i].cls == 1 || ID_arr[i].cls ==2){
+ if(ID_arr[i].tracked_flag==HI_FALSE){
+ if(ID_arr[i].tracked_count<=TRACK_TRESH){
+ ID_arr[i].tracked_count++;
+ if(ID_arr[i].tracked_count>TRACK_TRESH){
+ ID_arr[i].tracked_flag=HI_TRUE;
+ ID_arr[i].box_ID = ID_num_total;
+ ID_num_total++;
+ }
+ }
+ }
+ }
+ }
+ }
+ //分三种情况来考虑,好像没必要
+ // if(prevBoxNum>resLen){
+ // for(i=0;iMISS_THRESH){
+ if(ID_arr[i].miss_hits>MISS_THRESH){
+ if(ID_arr[i].tracked_flag==HI_TRUE)
+ *AD_attractiveness_tmp=*AD_attractiveness_tmp + ID_arr[i].focused_time_total/ID_arr[i].live_time;
+ for(j=i;j New Unconfirmed Tracks
+ for(i=0;iastSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64VirAddr = pstExtFrmInfo->stVFrame.u64VirAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64PhyAddr = pstExtFrmInfo->stVFrame.u64PhyAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u32Stride = pstExtFrmInfo->stVFrame.u32Stride[0];
+
+
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stYolov2NnieParam,&stInputDataIdx,&stProcSegIdx,HI_TRUE);
+
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov2_Proc failed!\n");
+ /*draw result, this sample has 3 classes:
+ class 0:background class 1:focused class 2:unfocused
+*/
+
+
+ /*Software process*/
+ /*if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Yolov2_GetResult
+ function input datas are correct*/
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_GetResult(&s_stYolov2NnieParam,&s_stYolov2SoftwareParam);
+ //这一步把归一化的xywh转成s_stYolov2SoftwareParam.stDstRoi的xyxy了
+
+ // SAMPLE_SVP_TRACE_INFO("Yolov2 result:\n");
+ // (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stYolov2SoftwareParam.stDstScore, SAMPLE_SVP_NNIE_Yolov2_ViToVo_threads_bNnieStopSignal
+ // &s_stYolov2SoftwareParam.stDstRoi, &s_stYolov2SoftwareParam.stClassRoiNum,f32PrintResultThresh);
+
+ s32Ret = SAMPLE_SVP_NNIE_RoiToRect_Yolov2(&(pstSwParam->stDstScore),
+ &(pstSwParam->stDstRoi), &(pstSwParam->stClassRoiNum), pstSwParam->af32ScoreThr,HI_TRUE,&(pstSwParam->stRect),
+ pstExtFrmInfo->stVFrame.u32Width, pstExtFrmInfo->stVFrame.u32Height,u32BaseWidth,u32BaseHeight);
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_RoiToRect failed!\n",s32Ret);
+
+ //主要作用是把检测框的信息转为DetectObjInfo的格式,并且对低于置信度阈值的框进行了进一步过滤
+ Yolo2FetchRes(&s_stYolov2SoftwareParam.stDstScore,
+ &s_stYolov2SoftwareParam.stDstRoi, &s_stYolov2SoftwareParam.stClassRoiNum, resBuf, resSize, resLen);
+
+ return s32Ret;
+
+}
+/******************************************************************************
+* function : Yolov2 vi to vo thread entry
+******************************************************************************/
+static HI_VOID* SAMPLE_SVP_NNIE_Yolov2_ViToVo_thread(HI_VOID* pArgs)
+{
+ HI_S32 s32Ret;
+ SAMPLE_SVP_NNIE_PARAM_S *pstParam;
+ SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S *pstSwParam;
+ VIDEO_FRAME_INFO_S stBaseFrmInfo;
+ VIDEO_FRAME_INFO_S stExtFrmInfo;
+ HI_S32 s32MilliSec = 20000;
+ VO_LAYER voLayer = 0;
+ VO_CHN voChn = 0;
+ HI_S32 s32VpssGrp = 0;
+ HI_S32 as32VpssChn[] = {VPSS_CHN0, VPSS_CHN1};
+
+ pstParam = &s_stYolov2NnieParam;
+ pstSwParam = &s_stYolov2SoftwareParam;
+
+ struct timespec start_time,end_time;
+ float use_time =0;
+ float fps;
+
+ OsdSet *osds;
+ osds = OsdsCreate(HI_OSD_BINDMOD_VPSS, s32VpssGrp, as32VpssChn[0]);
+ s32Ret = OsdLibInit();
+ g_osdsPerson = osds;
+ HI_ASSERT(g_osdsPerson);
+ g_osd0Person = OsdsCreateRgn(g_osdsPerson);
+ HI_ASSERT(g_osd0Person >= 0);
+ memset_s(g_osd_Person_ID, sizeof(HI_S32)*DETECT_OBJ_MAX, -1, sizeof(HI_S32)*DETECT_OBJ_MAX); //或用0xFF
+
+ for(int i=0; i<15; i++){
+ g_osd_Person_ID[i] = OsdsCreateRgn(g_osdsPerson);
+ HI_ASSERT(g_osd_Person_ID[i]>=0);
+ }
+
+ PERSON_ID personID[DETECT_OBJ_MAX] = {0};
+ int prev_box_num=0;
+ // int max_ID_num=-1;
+ int prev_rgn_num=0;
+ //static HI_U32 focused_time_total=0;
+ //static HI_U32 ID_num_total=0; //被跟踪的总人数
+ HI_U32 frame=1; //从1计起
+ //广告吸引度
+ HI_FLOAT AD_attractiveness_total=0; //AD_attractiveness_dead_ID + 当前帧ID累计得到的吸引度
+ HI_FLOAT AD_attractiveness_dead_ID=0;//已经丢失的ID的AD_attractiveness_total
+ HI_FLOAT AD_attractiveness_mean=0; //对ID总数做平均,AD_attractiveness_total/ID_num_total
+ //AD_attractiveness_mean即对每个ID做平均的广告吸引度,其值域应为[0,1]
+
+ static HI_CHAR prevOsd[BUF_LEN];
+ HI_OSD_ATTR_S rgn;
+ HI_OSD_ATTR_S rgn_ID[DETECT_OBJ_MAX]={0};
+ int x_ID, y_ID;
+ HI_S32 offset = 0;
+ HI_CHAR osdBuf[BUF_LEN] = "";
+ HI_S32 offset_box=0;
+ HI_CHAR osdBuf_box[BUF_LEN] = "";
+
+ /*udp*/
+ struct sockaddr_in s;
+ int sock;
+ char buffsend[512];
+ char buffrecive[512];
+ //协议:IPv4、IPv6
+ //PF_INET PF_INET6
+ //SOCK_DGRAM 无连接的
+ //SOCK_STREAM TCP 面向连接的
+ if((sock = socket(AF_INET,SOCK_DGRAM,0))==-1){
+ perror("error");
+ }
+
+ memset(&s,0,sizeof(s));
+ s.sin_family = AF_INET;
+ s.sin_port = htons(3000);
+ //pc端口
+ s.sin_addr.s_addr = inet_addr("192.168.200.1");
+ //手机端口
+ //s.sin_addr.s_addr = inet_addr("192.168.12.2");
+ memset(buffsend,0,sizeof(buffsend));
+ /*udp*/
+
+ while (HI_FALSE == s_bNnieStopSignal)
+ {
+ offset=0;
+ offset_box=0;
+ memset_s(osdBuf,BUF_LEN,0,BUF_LEN);
+ memset_s(osdBuf_box,BUF_LEN,0,BUF_LEN);
+
+ // for(int i=0; i<5; i++){
+ // g_osd_Person_ID[i] = OsdsCreateRgn(g_osdsPerson);
+ // HI_ASSERT(g_osd_Person_ID[i]>=0);
+ // }
+
+ clock_gettime(CLOCK_REALTIME, &start_time);
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[1], &stExtFrmInfo, s32MilliSec);
+ if(HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
+ s32Ret,s32VpssGrp, as32VpssChn[1]);
+ continue;
+ }
+
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[0], &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, EXT_RELEASE,
+ "Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
+ s32Ret,s32VpssGrp, as32VpssChn[0]);
+
+ VIDEO_FRAME_INFO_S resizeFrm;
+ s32Ret = MppFrmResize(&stExtFrmInfo, &resizeFrm, Net_FRM_WIDTH, Net_FRM_HEIGHT);
+ int objNum;
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_Proc_ViToVo(pstParam,pstSwParam, &resizeFrm,
+ stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height,objs,DETECT_OBJ_MAX, &objNum);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "Error(%#x),SAMPLE_SVP_NNIE_YOLOV2_Proc failed!\n", s32Ret);
+
+
+ HI_U32 FocuseNum = 0;
+ HI_U32 UnfocuseNum = 0;
+
+ //printf("!!!!!!!!!!!!!!!!!!!!!!!! objNum: %d, focused_time: %.3f !!!!!!!!!!!!!!!!!!!!!!!!!!",objNum,focused_time_total);
+ // for (int i = 0; i < objNum; i++) {
+ // RectBox *box = &objs[i].box;
+ // RectBoxTran(box, Net_FRM_WIDTH, Net_FRM_HEIGHT,stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height);
+ // SAMPLE_PRT("yolo2_out: {%d, %d, %d, %d} \n score: %f \n class: %d\n", box->xmin, box->ymin, box->xmax, box->ymax, objs[i].score, objs[i].cls);
+ // //因为验证而打印的部分后续可以删了:包括SAMPLE_PRT、printf、HI_ASSERT
+ // // boxs[i] = *box;
+ // // if(objs[i].cls == 1){
+ // // UnfocuseNum++;
+ // // }
+ // // if(objs[i].cls == 2){
+ // // FocuseNum++;
+ // // }
+ // }
+ //SAMPLE_SVP_TRACE_INFO("The Width is %d\n", resizeFrm.stVFrame.u32Width);
+ //SAMPLE_SVP_TRACE_INFO("The Height is %d\n", resizeFrm.stVFrame.u32Height);
+
+ //s32Ret = HI_MPI_VO_SendFrame(voLayer, voChn, &resizeFrm, 0);
+ //SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, BASE_RELEASE,
+ //"HI_MPI_VO_SendFrame fail, Error(%#x)\n", s32Ret);
+
+
+ //后面画框用到的box信息要使用跟踪的PERSON_ID.box_curr,这样能够弥补漏检的情况
+ // MppFrmDestroy(&resizeFrm);
+ // //Draw rect
+ // int num = 0;
+ // for (int j = 0; j < objNum; j++) {
+ // remainingBoxs[num++] = boxs[j];
+ // if(objs[j].cls == 1){
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, objNum, RGB888_GREEN, DRAW_RETC_THICK);
+ // }
+ // else{
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, objNum, RGB888_RED, DRAW_RETC_THICK);
+ // }
+ // }
+ //之前不是讨论过MppFrmDrawRects是一次性画多个框的吗
+ //改成下面这样?
+ // for (int j = 0; j < objNum; j++) {
+ // remainingBoxs[0] = boxs[j];
+ // if(objs[j].cls == 1){
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_GREEN, DRAW_RETC_THICK);
+ // }
+ // else{
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_RED, DRAW_RETC_THICK);
+ // }
+ // }
+
+ clock_gettime(CLOCK_REALTIME, &end_time);
+ //单位是毫秒,hyc把这部分移到SendFrame前面了,因为Track要统计时间,统计的ID要显示在画面中
+ use_time = (float)(end_time.tv_sec - start_time.tv_sec)*1000 + (end_time.tv_nsec - start_time.tv_nsec) / 1000000.0;
+ //SAMPLE_SVP_TRACE_INFO("The use time is %f ms\n", use_time);
+ fps=1000/use_time;
+ prev_box_num = Trivial_Track_Yolov2(objs, objNum, use_time, personID, prev_box_num, frame, &AD_attractiveness_dead_ID);
+ frame++;
+
+ // if(prev_box_num>max_ID_num)
+ // max_ID_num=prev_box_num;
+
+ //实验发现会出现cls=0的情况,必须手动把它排除掉
+ //Draw rects; display ID number; print info for debugging
+ AD_attractiveness_total=AD_attractiveness_dead_ID;
+ // printf("dead%f\n",AD_attractiveness_total);
+ for (int i = 0; i < prev_box_num; i++) {
+ RectBox box = personID[i].box_curr;
+ RectBoxTran(&box, Net_FRM_WIDTH, Net_FRM_HEIGHT,stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height);
+ //SAMPLE_PRT("yolo2_out_track: box{%d, %d, %d, %d} \n class: %d\n miss_hits:%d,\n box_ID:%d,\n matched_flag:%d,\n tracked_count:%d,focuesed_time[%f,%f,%f,%f,%f,%f]",
+ //box.xmin, box.ymin, box.xmax, box.ymax, personID[i].cls, personID[i].miss_hits, personID[i].box_ID, personID[i].matched_flag, personID[i].tracked_count,personID[i].focused_time[0],personID[i].focused_time[1],personID[i].focused_time[2],personID[i].focused_time[3],personID[i].focused_time[4],personID[i].focused_time[5]);
+ //因为验证而打印的部分后续可以删了:包括SAMPLE_PRT、printf、HI_ASSERT
+ // boxs[i] = box;
+ remainingBoxs[0] = box;
+ BoxsIDprint[i] = box;
+ if(personID[i].tracked_flag==HI_TRUE){
+ memset_s(osdBuf_box,BUF_LEN,0,BUF_LEN);
+ offset_box=0;
+ if(personID[i].cls == 1){
+ UnfocuseNum++;
+ MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_GREEN, DRAW_RETC_THICK);
+ offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ "%u ", personID[i].box_ID);
+ offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ "Unfocused");
+ HI_ASSERT(offset_box < sizeof(osdBuf_box));
+ x_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].xmin)/2)*2,0),stBaseFrmInfo.stVFrame.u32Width-1);
+ y_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].ymin-40)/2)*2,0),stBaseFrmInfo.stVFrame.u32Height-1);
+ //字体大小的设置:sample\taurus\ai_sample\mpp_help\src\osd_img.c,OSD_FONT_WIDTH_DEF与OSD_FONT_HEIGHT_DEF
+ TxtRgnInit(&rgn_ID[i], osdBuf_box, x_ID, y_ID, ARGB1555_BLUE); // font width and heigt use default 40
+ OsdsSetRgn(g_osdsPerson, g_osd_Person_ID[i], &rgn_ID[i]);
+ }
+ else if(personID[i].cls == 2){
+ FocuseNum++;
+ MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_RED, DRAW_RETC_THICK);
+ offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ "%u ", personID[i].box_ID);
+ offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ "Focused");
+ HI_ASSERT(offset_box < sizeof(osdBuf_box));
+ x_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].xmin)/2)*2,0),stBaseFrmInfo.stVFrame.u32Width-1);
+ y_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].ymin-40)/2)*2,0),stBaseFrmInfo.stVFrame.u32Height-1);
+ //字体大小的设置:sample\taurus\ai_sample\mpp_help\src\osd_img.c,OSD_FONT_WIDTH_DEF与OSD_FONT_HEIGHT_DEF
+ TxtRgnInit(&rgn_ID[i], osdBuf_box, x_ID, y_ID, ARGB1555_BLUE); // font width and heigt use default 40
+ OsdsSetRgn(g_osdsPerson, g_osd_Person_ID[i], &rgn_ID[i]);
+ }
+ AD_attractiveness_total+= personID[i].focused_time_total/personID[i].live_time;
+ //printf("curlive id:%d,class:%d,totalfocustime:%f,livetime:%f\n",personID[i].box_ID,personID[i].cls,personID[i].focused_time_total,personID[i].live_time);
+ //每个框的左上角加ID文字
+ // memset_s(osdBuf_box,BUF_LEN,0,BUF_LEN);
+ // offset_box=0;
+ // offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ // "%u", personID[i].box_ID);
+ // HI_ASSERT(offset_box < sizeof(osdBuf_box));
+ // x_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].xmin)/2)*2,0),stBaseFrmInfo.stVFrame.u32Width);
+ // y_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].ymin-40)/2)*2,0),stBaseFrmInfo.stVFrame.u32Height);
+ // //字体大小的设置:sample\taurus\ai_sample\mpp_help\src\osd_img.c,OSD_FONT_WIDTH_DEF与OSD_FONT_HEIGHT_DEF
+ // TxtRgnInit(&rgn_ID[i], osdBuf_box, x_ID, y_ID, ARGB1555_BLUE); // font width and heigt use default 40
+ // OsdsSetRgn(g_osdsPerson, g_osd_Person_ID[i], &rgn_ID[i]);
+ }
+ //printf("g_osd_person_ID[%d]:%d\n",i,g_osd_Person_ID[i]);
+ //OsdsDestroyRgn(g_osdsPerson,g_osd_Person_ID[i]);
+ }
+ for(int i=prev_box_num;i>>g_osd_person_ID[%d]:%d\n",i,g_osd_Person_ID[i]);
+ }
+ prev_rgn_num=prev_box_num;
+ // for(int i=prev_box_num;i>>g_osd_person_ID[%d]:%d\n",i,g_osd_Person_ID[i]);
+ // }
+ // for(int i=0;i<5;i++)
+ // {
+ // printf("g_osd_person_ID[%d]:%d\n",i,g_osd_Person_ID[i]);
+ // OsdsDestroyRgn(g_osdsPerson,g_osd_Person_ID[i]);
+ // }
+
+
+
+ //Draw rect
+ // for (int j = 0; j < prev_box_num; j++) {
+ // remainingBoxs[0] = boxs[j];
+ // if(personID[j].tracked_flag==HI_TRUE){
+ // if(objs[j].cls == 1){
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_GREEN, DRAW_RETC_THICK);
+ // }
+ // else if(objs[j].cls == 2){
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_RED, DRAW_RETC_THICK);
+ // }
+ // }
+ // }
+ MppFrmDestroy(&resizeFrm);
+
+ /*OSD*/
+
+ offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1, "FocuseNum: %u", FocuseNum);
+ HI_ASSERT(offset < sizeof(osdBuf));
+ // offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1,
+ // "%u",FocuseNum);
+ // HI_ASSERT(offset < sizeof(osdBuf));
+
+ offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1, "; UnfocuseNum: %u", UnfocuseNum);
+ HI_ASSERT(offset < sizeof(osdBuf));
+ // offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1,
+ // "%u",UnfocuseNum);
+ // HI_ASSERT(offset < sizeof(osdBuf));
+
+ offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1, "; IDTotalNum: %u", ID_num_total);
+ HI_ASSERT(offset < sizeof(osdBuf));
+ // offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1,
+ // "%u",ID_num_total);
+ // HI_ASSERT(offset < sizeof(osdBuf));
+ // offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1, "; FPS: %.1f", fps);
+ // HI_ASSERT(offset < sizeof(osdBuf));
+
+ if (strcmp(osdBuf, prevOsd) != 0) {
+ HiStrxfrm(prevOsd, osdBuf, sizeof(prevOsd)); //就是把osdBuf字符串拷贝给prevOsd
+ // HI_OSD_ATTR_S rgn;
+ TxtRgnInit(&rgn, osdBuf, TXT_BEGX, TXT_BEGY, ARGB1555_RED); // font width and heigt use default 40
+ OsdsSetRgn(g_osdsPerson, g_osd0Person, &rgn);
+ }
+ if(ID_num_total>0)
+ AD_attractiveness_mean= AD_attractiveness_total/ID_num_total;
+ else
+ AD_attractiveness_mean=0;
+ //UdpSend
+ sprintf(buffsend,"Focus:%u,UnFocus:%u,Total:%f,Attractiveness:%f",
+ FocuseNum,UnfocuseNum,focused_time_total/1000, AD_attractiveness_mean);
+ sendto(sock,buffsend,strlen(buffsend),0,(struct sockaddr *)&s,sizeof(s));
+ //UdpRecive
+
+ s32Ret = HI_MPI_VO_SendFrame(voLayer, voChn, &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "HI_MPI_VO_SendFrame failed, Error(%#x)!\n", s32Ret);
+
+ //printf("SendstBaseFrmInfo:width:%d, height:%d, entype:%d\n",stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height,stBaseFrmInfo.stVFrame.enPixelFormat);
+ BASE_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[0], &stBaseFrmInfo);
+ if (HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
+ s32Ret,s32VpssGrp,as32VpssChn[0]);
+ }
+
+ EXT_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[1], &stExtFrmInfo);
+ if (HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
+ s32Ret,s32VpssGrp,as32VpssChn[1]);
+ }
+
+ }
+
+ return HI_NULL;
+}
+/******************************************************************************
+* function : Yolov2 vi to vo real time detection
+******************************************************************************/
+void SAMPLE_SVP_NNIE_Yolov2_Vivo(void)
+{
+ // HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/dog_bike_car_416x416.bgr";
+ HI_CHAR *pcModelName = "./data/nnie_model/detection/resnet18_best.wk";
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = {0};
+ SIZE_S stSize;
+ PIC_SIZE_E enSize = PIC_CIF;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_CHAR acThreadName[16] = {0};
+
+ /*udp*/
+ struct sockaddr_in s1;
+ int sock1;
+ char buff1[1024]="";
+ char buff2[1024]="";
+ //协议:IPv4、IPv6
+ //PF_INET PF_INET6
+ //SOCK_DGRAM 无连接的
+ //SOCK_STREAM TCP 面向连接的
+ if((sock1 = socket(AF_INET,SOCK_DGRAM,0))==-1){
+ perror("error");
+ }
+ memset(&s1,0,sizeof(s1));
+ s1.sin_family = AF_INET;
+ s1.sin_port = htons(3000);
+ s1.sin_addr.s_addr = INADDR_ANY;
+ if(bind(sock1,(struct sockaddr *)&s1,sizeof(s1))==-1)
+ {
+ perror("bind error");
+ }
+ socklen_t sock_len = sizeof(s1);
+
+
+
+
+ while(1){
+ int recvbyte1 = recvfrom(sock1,buff1,sizeof(buff1)-1,0,(struct sockaddr *)&s1,&sock_len);
+ buff1[recvbyte1]= 0;
+ if(!strcmp(buff1,"start_yolov2")){
+ /*Sys init*/
+ SAMPLE_COMM_SVP_CheckSysInit();
+
+ /******************************************
+ step 1: start vi vpss vo
+ ******************************************/
+ s_stYolov2Switch.bVenc = HI_FALSE;
+ s_stYolov2Switch.bVo = HI_TRUE;
+ s32Ret = SAMPLE_COMM_IVE_StartViVpssVencVo_Yolov2(&s_stViConfig,&s_stYolov2Switch,&enSize);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, YOLOV2_FAIL_1,
+ "Error(%#x),SAMPLE_COMM_IVE_StartViVpssVencVo failed!\n", s32Ret);
+
+ s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSize, &stSize);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, YOLOV2_FAIL_1,
+ "Error(%#x),SAMPLE_COMM_SYS_GetPicSize failed!\n", s32Ret);
+
+ stSize.u32Width = 640;
+ stSize.u32Height = 384;
+
+ /******************************************
+ step 2: init NNIE param
+ ******************************************/
+ stNnieCfg.pszPic= NULL;
+ stNnieCfg.u32MaxInputNum = 1;
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0;//set NNIE core
+
+ /*YOLOV2 */
+ SAMPLE_SVP_NNIE_CFG_S *self;
+ HI_U32 u32PicNum = 1;
+ //HI_S32 s32Ret;
+
+ self = (SAMPLE_SVP_NNIE_CFG_S*)malloc(sizeof(*self));
+ HI_ASSERT(self);
+ memset_s(self, sizeof(*self), 0x00, sizeof(*self));
+
+ /*
+ * 设置配置参数
+ * Set configuration parameter
+ */
+ self->pszPic = NULL;
+ self->u32MaxInputNum = u32PicNum; // max input image num in each batch
+ self->u32MaxRoiNum = 0;
+ self->aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+
+ /*Yolov2 Load model*/
+ SAMPLE_SVP_TRACE_INFO("Yolov2 Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName,&s_stYolov2Model);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret,YOLOV2_FAIL_0,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /*Yolov2 parameter initialization*/
+ /*Yolov2 software parameters are set in SAMPLE_SVP_NNIE_Yolov2_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Yolov2_SoftwareInit function are correct*/
+ SAMPLE_SVP_TRACE_INFO("Yolov2 parameter initialization!\n");
+ s_stYolov2NnieParam.pstModel = &s_stYolov2Model.stModel;
+ // s32Ret = SAMPLE_SVP_NNIE_Yolov2_ParamInit(&stNnieCfg,&s_stYolov2NnieParam,&s_stYolov2SoftwareParam);
+ // SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret,YOLOV2_FAIL_0,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ // "Error,SAMPLE_SVP_NNIE_Yolov2_ParamInit failed!\n");
+ s32Ret = SampleSvpNnieYolov2ParamInit(self, &s_stYolov2NnieParam, &s_stYolov2SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SampleSvpNnieYolov2ParamInit failed!\n");
+
+ /******************************************
+ step 3: Create work thread
+ ******************************************/
+ SAMPLE_SVP_TRACE_INFO("Yolov2 start!\n");
+ snprintf(acThreadName, 16, "NNIE_ViToVo");
+ prctl(PR_SET_NAME, (unsigned long)acThreadName, 0,0,0);
+ s_bNnieStopSignal = HI_FALSE;
+ /******************************************
+ step 3: Create work thread
+ ******************************************/
+ pthread_create(&s_hNnieThread, 0, SAMPLE_SVP_NNIE_Yolov2_ViToVo_thread, NULL);
+ while(strcmp(buff1,"stop_yolov2")){
+ int recvbyte1 = recvfrom(sock1,buff1,sizeof(buff1)-1,0,(struct sockaddr *)&s1,&sock_len);
+ buff1[recvbyte1]= 0;
+ }
+ //SAMPLE_PAUSE();
+ s_bNnieStopSignal = HI_TRUE;
+ // pthread_join(s_hNnieThread, HI_NULL);
+ // s_hNnieThread = 0;
+ usleep(200000);
+ OsdsClear(g_osdsPerson);
+ if (0 != s_hNnieThread)
+ {
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+ }
+
+ SAMPLE_SVP_NNIE_Yolov2_Deinit(&s_stYolov2NnieParam,&s_stYolov2SoftwareParam,&s_stYolov2Model);
+ memset(&s_stYolov2NnieParam,0,sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ memset(&s_stYolov2SoftwareParam,0,sizeof(SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S));
+ memset(&s_stYolov2Model,0,sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+
+ SAMPLE_COMM_IVE_StopViVpssVencVo_Yolov2(&s_stViConfig,&s_stYolov2Switch);
+ ID_num_total=0;
+ focused_time_total=0;
+ }
+ }
+ // s_bNnieStopSignal = HI_FALSE;
+ // /******************************************
+ // step 3: Create work thread
+ // ******************************************/
+ // snprintf(acThreadName, 16, "NNIE_ViToVo");
+ // prctl(PR_SET_NAME, (unsigned long)acThreadName, 0,0,0);
+ // pthread_create(&s_hNnieThread, 0, SAMPLE_SVP_NNIE_Yolov2_ViToVo_thread, NULL);
+ // SAMPLE_PAUSE();
+
+ // s_bNnieStopSignal = HI_TRUE;
+ // pthread_join(s_hNnieThread, HI_NULL);
+ // s_hNnieThread = 0;
+ // OsdsClear(g_osdsPerson);
+
+
+YOLOV2_FAIL_1:
+ SAMPLE_SVP_NNIE_Yolov2_Deinit(&s_stYolov2NnieParam,&s_stYolov2SoftwareParam,&s_stYolov2Model);
+
+YOLOV2_FAIL_0:
+ SAMPLE_COMM_IVE_StopViVpssVencVo_Yolov2(&s_stViConfig,&s_stYolov2Switch);
+
+}
+
+void SAMPLE_SVP_NNIE_Yolov2_Vivo_HandleSig(void)
+{
+ s_bNnieStopSignal = HI_TRUE;
+ if (0 != s_hNnieThread)
+ {
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+ }
+
+ SAMPLE_SVP_NNIE_Yolov2_Deinit(&s_stYolov2NnieParam,&s_stYolov2SoftwareParam,&s_stYolov2Model);
+ memset(&s_stYolov2NnieParam,0,sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ memset(&s_stYolov2SoftwareParam,0,sizeof(SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S));
+ memset(&s_stYolov2Model,0,sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+
+ SAMPLE_COMM_IVE_StopViVpssVencVo_Yolov2(&s_stViConfig,&s_stYolov2Switch);
+
+}
\ No newline at end of file
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample/sample_nnie_main.h b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample/sample_nnie_main.h
new file mode 100644
index 0000000000000000000000000000000000000000..3833e642a46fff81b50849dc52c3801e1aad6b1d
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample/sample_nnie_main.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef SAMPLE_SVP_MAIN_H
+#define SAMPLE_SVP_MAIN_H
+
+#include "hi_type.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+void SAMPLE_SVP_NNIE_Cnn(void);
+
+void SAMPLE_SVP_NNIE_Segnet(void);
+
+void SAMPLE_SVP_NNIE_FasterRcnn(void);
+
+void SAMPLE_SVP_NNIE_FasterRcnn_DoubleRoiPooling(void);
+
+void SAMPLE_SVP_NNIE_Rfcn(void);
+
+void SAMPLE_SVP_NNIE_Rfcn_File(void);
+
+void SAMPLE_SVP_NNIE_Ssd(void);
+
+void SAMPLE_SVP_NNIE_Yolov1(void);
+
+void SAMPLE_SVP_NNIE_Yolov2(void);
+
+void SAMPLE_SVP_NNIE_Yolov3(void);
+
+void SAMPLE_SVP_NNIE_Lstm(void);
+
+void SAMPLE_SVP_NNIE_Pvanet(void);
+
+void SAMPLE_SVP_NNIE_Yolov3_Vivo(void);
+
+void SAMPLE_SVP_NNIE_Yolov2_Vivo(void);
+
+void SAMPLE_SVP_NNIE_Cnn_HandleSig(void);
+
+void SAMPLE_SVP_NNIE_Segnet_HandleSig(void);
+
+void SAMPLE_SVP_NNIE_FasterRcnn_HandleSig(void);
+
+void SAMPLE_SVP_NNIE_Rfcn_HandleSig(void);
+
+void SAMPLE_SVP_NNIE_Rfcn_HandleSig_File(void);
+
+void SAMPLE_SVP_NNIE_Ssd_HandleSig(void);
+
+void SAMPLE_SVP_NNIE_Yolov1_HandleSig(void);
+
+void SAMPLE_SVP_NNIE_Yolov2_HandleSig(void);
+
+void SAMPLE_SVP_NNIE_Yolov3_HandleSig(void);
+
+void SAMPLE_SVP_NNIE_Lstm_HandleSig(void);
+
+void SAMPLE_SVP_NNIE_Pvanet_HandleSig(void);
+
+void SAMPLE_SVP_NNIE_Yolov3_Vivo_HandleSig(void);
+
+void SAMPLE_SVP_NNIE_Yolov2_Vivo_HandleSig(void);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* SAMPLE_SVP_MAIN_H */
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample/sample_nnie_yolov2_sort.c b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample/sample_nnie_yolov2_sort.c
new file mode 100644
index 0000000000000000000000000000000000000000..b41ac9383311b9a8caabe8ef202f85085103017c
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample/sample_nnie_yolov2_sort.c
@@ -0,0 +1,5589 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include "hi_common.h"
+#include "hi_comm_sys.h"
+#include "hi_comm_svp.h"
+#include "sample_comm.h"
+#include "sample_comm_svp.h"
+#include "sample_comm_nnie.h"
+#include "sample_nnie_main.h"
+#include "sample_svp_nnie_software.h"
+#include "sample_comm_ive.h"
+#include "vgs_img.h"
+#include "misc_util.h"
+#include "osd_img.h"
+#include "base_interface.h"
+
+#include "hi_debug.h"
+#include "hi_comm_ive.h"
+
+//SORT
+#include "SORT.h"
+
+#define THRESH_MIN 0.4
+#define ARRAY_SUBSCRIPT_OFFSET_1 1
+#define ARRAY_SUBSCRIPT_OFFSET_2 2
+#define ARRAY_SUBSCRIPT_OFFSET_3 3
+#define DETECT_OBJ_MAX 32
+#define DRAW_RETC_THICK 2 // Draw the width of the line
+#define ARRAY_SUBSCRIPT_0 0
+#define ARRAY_SUBSCRIPT_1 1
+#define ARRAY_SUBSCRIPT_2 2
+#define ARRAY_SUBSCRIPT_3 3
+#define ARRAY_SUBSCRIPT_4 4
+#define ARRAY_SUBSCRIPT_5 5
+#define ARRAY_SUBSCRIPT_6 6
+#define ARRAY_SUBSCRIPT_7 7
+#define ARRAY_SUBSCRIPT_8 8
+#define ARRAY_SUBSCRIPT_9 9
+
+#define ARGB1555_YELLOW2 0xFF00 // 1 11111 11111 00000
+#define ARGB1555_BLUE 0x801F // 1 00000 00000 11111
+#define ARGB1555_BLACK 0x8000 // 1 00000 00000 00000
+#define ARGB1555_RED 0xFC00 // 1 11111 00000 00000
+#define TXT_BEGX 20
+#define TXT_BEGY 20
+
+#define IMG_FULL_CHN 3 // Full channel / three channel, for YUV444, RGB888
+
+static DetectObjInfo objs[DETECT_OBJ_MAX] = {0};
+static RectBox boxs[DETECT_OBJ_MAX] = {0};
+static RectBox remainingBoxs[DETECT_OBJ_MAX] = {0};
+static VIDEO_FRAME_INFO_S *dstFrm;
+// static RectBox BoxsIDprint[DETECT_OBJ_MAX] = {0};
+
+static hi_bool g_stop_signal = HI_FALSE;
+/* cnn para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stCnnModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stCnnNnieParam = { 0 };
+static SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S s_stCnnSoftwareParam = { 0 };
+/* segment para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stSegnetModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stSegnetNnieParam = { 0 };
+/* fasterrcnn para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stFasterRcnnModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stFasterRcnnNnieParam = { 0 };
+static SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S s_stFasterRcnnSoftwareParam = { 0 };
+static SAMPLE_SVP_NNIE_NET_TYPE_E s_enNetType;
+/* rfcn para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stRfcnModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stRfcnNnieParam = { 0 };
+static SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S s_stRfcnSoftwareParam = { 0 };
+static SAMPLE_IVE_SWITCH_S s_stRfcnSwitch = { HI_FALSE, HI_FALSE };
+static HI_BOOL s_bNnieStopSignal = HI_FALSE;
+static pthread_t s_hNnieThread = 0;
+static SAMPLE_VI_CONFIG_S s_stViConfig = { 0 };
+
+/* ssd para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stSsdModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stSsdNnieParam = { 0 };
+static SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S s_stSsdSoftwareParam = { 0 };
+/* yolov1 para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stYolov1Model = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stYolov1NnieParam = { 0 };
+static SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S s_stYolov1SoftwareParam = { 0 };
+/* yolov2 para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stYolov2Model = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stYolov2NnieParam = { 0 };
+static SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S s_stYolov2SoftwareParam = { 0 };
+/* yolov3 para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stYolov3Model = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stYolov3NnieParam = { 0 };
+static SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S s_stYolov3SoftwareParam = { 0 };
+/* lstm para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stLstmModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stLstmNnieParam = { 0 };
+/* pvanet para */
+static SAMPLE_SVP_NNIE_MODEL_S s_stPvanetModel = { 0 };
+static SAMPLE_SVP_NNIE_PARAM_S s_stPvanetNnieParam = { 0 };
+static SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S s_stPvanetSoftwareParam = { 0 };
+
+/*yolov3 para*/
+static SAMPLE_IVE_SWITCH_S s_stYolov3Switch = {HI_FALSE,HI_FALSE};
+
+/*yolov2 para*/
+static SAMPLE_IVE_SWITCH_S s_stYolov2Switch = {HI_FALSE,HI_FALSE};
+/*print on screen(OSD)*/
+static OsdSet* g_osdsPerson = NULL;
+static HI_S32 g_osd0Person = -1;
+static HI_S32 g_osd_Person_ID[DETECT_OBJ_MAX];
+//memset_s(g_osd_Person_ID, sizeof(HI_S32)*DETECT_OBJ_MAX, -1, sizeof(HI_S32)*DETECT_OBJ_MAX); //或用0xFF
+/*track*/
+static HI_U32 ID_num_total=0; //被跟踪的总人数
+static HI_FLOAT focused_time_total=0.0;//人群注意力总时长
+// static HI_BOOL accumulate_first_flag=HI_FALSE;
+
+/* function : NNIE Forward */
+/*
+ * 获取结果
+ * Fetch result
+ */
+static void Yolo2FetchRes(SVP_BLOB_S *pstDstScore, SVP_BLOB_S *pstDstRoi, SVP_BLOB_S *pstClassRoiNum,
+ DetectObjInfo resBuf[], int resSize, int* resLen)
+{
+ HI_U32 i;
+ HI_U32 j;
+ HI_U32 u32RoiNumBias = 0;
+ HI_U32 u32ScoreBias;
+ HI_U32 u32BboxBias;
+ HI_FLOAT f32Score;
+ HI_S32* ps32Score = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstScore->u64VirAddr);
+ HI_S32* ps32Roi = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstRoi->u64VirAddr);
+ HI_S32* ps32ClassRoiNum = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstClassRoiNum->u64VirAddr);
+ HI_U32 u32ClassNum = pstClassRoiNum->unShape.stWhc.u32Width;
+
+ HI_ASSERT(u32ClassNum == 3); // 2: the number of class
+ HI_ASSERT(resSize > 0);
+ int current_cls =1;
+ int resId = 0;
+ *resLen = 0;
+ memset_s(resBuf, resSize * sizeof(resBuf[0]), 0x00, resSize * sizeof(resBuf[0]));
+
+ u32RoiNumBias += ps32ClassRoiNum[0];
+ for (i = 1; i < u32ClassNum; i++) {
+ current_cls = i;
+ u32ScoreBias = u32RoiNumBias;
+ u32BboxBias = u32RoiNumBias * SAMPLE_SVP_NNIE_COORDI_NUM;
+ /*
+ * 如果置信度分数大于结果阈值,则打印结果
+ * If the confidence score greater than result threshold, the result will be printed
+ */
+ if ((HI_FLOAT)ps32Score[u32ScoreBias] / SAMPLE_SVP_NNIE_QUANT_BASE >=
+ THRESH_MIN && ps32ClassRoiNum[i] != 0) {
+ }
+ for (j = 0; j < (HI_U32)ps32ClassRoiNum[i]; j++) {
+ f32Score = (HI_FLOAT)ps32Score[u32ScoreBias + j] / SAMPLE_SVP_NNIE_QUANT_BASE;
+ if (f32Score < THRESH_MIN) {
+ SAMPLE_PRT("f32Score:%.2f\n", f32Score);
+ break;
+ }
+ if (resId >= resSize) {
+ SAMPLE_PRT("yolo2 resBuf full\n");
+ break;
+ }
+ resBuf[resId].cls = current_cls; // class 1
+ resBuf[resId].score = f32Score;
+
+ RectBox *box = &resBuf[resId].box;
+ box->xmin = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM];
+ box->ymin = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + ARRAY_SUBSCRIPT_OFFSET_1];
+ box->xmax = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + ARRAY_SUBSCRIPT_OFFSET_2];
+ box->ymax = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + ARRAY_SUBSCRIPT_OFFSET_3];
+ if (box->xmin >= box->xmax || box->ymin >= box->ymax) {
+ // SAMPLE_PRT("yolo1_orig: {%d, %d, %d, %d}, discard for coord ERR\n",
+ // box->xmin, box->ymin, box->xmax, box->ymax);
+ } else {
+ resId++;
+ }
+ }
+ u32RoiNumBias += ps32ClassRoiNum[i];
+ }
+
+ *resLen = resId;
+}
+
+static HI_S32 SAMPLE_SVP_NNIE_Forward(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S *pstInputDataIdx, SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S *pstProcSegIdx,
+ HI_BOOL bInstant)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 i, j;
+ HI_BOOL bFinish = HI_FALSE;
+ SVP_NNIE_HANDLE hSvpNnieHandle = 0;
+ HI_U32 u32TotalStepNum = 0;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(pstProcSegIdx->u32SegIdx >= pstNnieParam->pstModel->u32NetSegNum ||
+ pstInputDataIdx->u32SegIdx >= pstNnieParam->pstModel->u32NetSegNum ||
+ pstNnieParam->pstModel->u32NetSegNum > SVP_NNIE_MAX_NET_SEG_NUM,
+ HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstProcSegIdx->u32SegIdx(%u) and pstInputDataIdx->u32SegIdx(%u) "
+ "should be less than %u, pstNnieParam->pstModel->u32NetSegNum(%u) can't be greater than %u!\n",
+ pstProcSegIdx->u32SegIdx, pstInputDataIdx->u32SegIdx, pstNnieParam->pstModel->u32NetSegNum,
+ pstNnieParam->pstModel->u32NetSegNum, SVP_NNIE_MAX_NET_SEG_NUM);
+
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u64VirAddr),
+ pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u32Size);
+
+ for (i = 0; i < pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].u32DstNum; i++) {
+ if (pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].enType == SVP_BLOB_TYPE_SEQ_S32) {
+ for (j = 0; j < pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num; j++) {
+ u32TotalStepNum += *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stSeq.u64VirAddrStep) +
+ j);
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ u32TotalStepNum * pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ } else {
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Chn *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Height *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ }
+ }
+
+ /* set input blob according to node name */
+ if (pstInputDataIdx->u32SegIdx != pstProcSegIdx->u32SegIdx) {
+ for (i = 0; i < pstNnieParam->pstModel->astSeg[pstProcSegIdx->u32SegIdx].u16SrcNum; i++) {
+ for (j = 0; j < pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].u16DstNum; j++) {
+ if (strncmp(pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].astDstNode[j].szName,
+ pstNnieParam->pstModel->astSeg[pstProcSegIdx->u32SegIdx].astSrcNode[i].szName,
+ SVP_NNIE_NODE_NAME_LEN) == 0) {
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astSrc[i] =
+ pstNnieParam->astSegData[pstInputDataIdx->u32SegIdx].astDst[j];
+ break;
+ }
+ }
+ SAMPLE_SVP_CHECK_EXPR_RET((j == pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].u16DstNum),
+ HI_FAILURE, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,can't find %d-th seg's %d-th src blob!\n",
+ pstProcSegIdx->u32SegIdx, i);
+ }
+ }
+
+ /* NNIE_Forward */
+ s32Ret = HI_MPI_SVP_NNIE_Forward(&hSvpNnieHandle, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astSrc,
+ pstNnieParam->pstModel, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst,
+ &pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx], bInstant);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,HI_MPI_SVP_NNIE_Forward failed!\n");
+
+ if (bInstant) {
+ /* Wait NNIE finish */
+ while (HI_ERR_SVP_NNIE_QUERY_TIMEOUT == (s32Ret = HI_MPI_SVP_NNIE_Query(
+ pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].enNnieId, hSvpNnieHandle, &bFinish, HI_TRUE))) {
+ usleep(100); /* sleep 100 micro_seconds */
+ SAMPLE_SVP_TRACE(SAMPLE_SVP_ERR_LEVEL_INFO, "HI_MPI_SVP_NNIE_Query Query timeout!\n");
+ }
+ }
+ u32TotalStepNum = 0;
+ for (i = 0; i < pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].u32DstNum; i++) {
+ if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].enType) {
+ for (j = 0; j < pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num; j++) {
+ u32TotalStepNum += *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stSeq.u64VirAddrStep) +
+ j);
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ u32TotalStepNum * pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ } else {
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Chn *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Height *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ }
+ }
+
+ return s32Ret;
+}
+
+/* function : NNIE ForwardWithBbox */
+static HI_S32 SAMPLE_SVP_NNIE_ForwardWithBbox(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S *pstInputDataIdx, SVP_SRC_BLOB_S astBbox[],
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S *pstProcSegIdx, HI_BOOL bInstant)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_BOOL bFinish = HI_FALSE;
+ SVP_NNIE_HANDLE hSvpNnieHandle = 0;
+ HI_U32 u32TotalStepNum = 0;
+ HI_U32 i, j;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(pstProcSegIdx->u32SegIdx >= pstNnieParam->pstModel->u32NetSegNum ||
+ pstInputDataIdx->u32SegIdx >= pstNnieParam->pstModel->u32NetSegNum ||
+ pstNnieParam->pstModel->u32NetSegNum > SVP_NNIE_MAX_NET_SEG_NUM,
+ HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstProcSegIdx->u32SegIdx(%u) and pstInputDataIdx->u32SegIdx(%u) "
+ "should be less than %u, pstNnieParam->pstModel->u32NetSegNum(%u) should be less than %u!\n",
+ pstProcSegIdx->u32SegIdx, pstInputDataIdx->u32SegIdx, pstNnieParam->pstModel->u32NetSegNum,
+ pstNnieParam->pstModel->u32NetSegNum, SVP_NNIE_MAX_NET_SEG_NUM);
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u64VirAddr),
+ pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].stTskBuf.u32Size);
+
+ for (i = 0; i < pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].u32DstNum; i++) {
+ if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].enType) {
+ for (j = 0; j < pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num; j++) {
+ u32TotalStepNum += *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stSeq.u64VirAddrStep) +
+ j);
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ u32TotalStepNum * pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ } else {
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Chn *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Height *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ }
+ }
+
+ /* set input blob according to node name */
+ if (pstInputDataIdx->u32SegIdx != pstProcSegIdx->u32SegIdx) {
+ for (i = 0; i < pstNnieParam->pstModel->astSeg[pstProcSegIdx->u32SegIdx].u16SrcNum; i++) {
+ for (j = 0; j < pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].u16DstNum; j++) {
+ if (strncmp(pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].astDstNode[j].szName,
+ pstNnieParam->pstModel->astSeg[pstProcSegIdx->u32SegIdx].astSrcNode[i].szName,
+ SVP_NNIE_NODE_NAME_LEN) == 0) {
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astSrc[i] =
+ pstNnieParam->astSegData[pstInputDataIdx->u32SegIdx].astDst[j];
+ break;
+ }
+ }
+ SAMPLE_SVP_CHECK_EXPR_RET((j == pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx].u16DstNum),
+ HI_FAILURE, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,can't find %d-th seg's %d-th src blob!\n",
+ pstProcSegIdx->u32SegIdx, i);
+ }
+ }
+ /* NNIE_ForwardWithBbox */
+ s32Ret = HI_MPI_SVP_NNIE_ForwardWithBbox(&hSvpNnieHandle, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astSrc,
+ astBbox, pstNnieParam->pstModel, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst,
+ &pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx], bInstant);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,HI_MPI_SVP_NNIE_ForwardWithBbox failed!\n");
+
+ if (bInstant) {
+ /* Wait NNIE finish */
+ while (HI_ERR_SVP_NNIE_QUERY_TIMEOUT ==
+ (s32Ret = HI_MPI_SVP_NNIE_Query(pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].enNnieId,
+ hSvpNnieHandle, &bFinish, HI_TRUE))) {
+ usleep(100); /* sleep 100 micro_seconds */
+ SAMPLE_SVP_TRACE(SAMPLE_SVP_ERR_LEVEL_INFO, "HI_MPI_SVP_NNIE_Query Query timeout!\n");
+ }
+ }
+ u32TotalStepNum = 0;
+
+ for (i = 0; i < pstNnieParam->astForwardWithBboxCtrl[pstProcSegIdx->u32SegIdx].u32DstNum; i++) {
+ if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].enType) {
+ for (j = 0; j < pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num; j++) {
+ u32TotalStepNum += *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stSeq.u64VirAddrStep) +
+ j);
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ u32TotalStepNum * pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ } else {
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u64VirAddr),
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Num *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Chn *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].unShape.stWhc.u32Height *
+ pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst[i].u32Stride);
+ }
+ }
+
+ return s32Ret;
+}
+
+/* function : Fill Src Data */
+static HI_S32 SAMPLE_SVP_NNIE_FillSrcData(SAMPLE_SVP_NNIE_CFG_S *pstNnieCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S *pstInputDataIdx)
+{
+ FILE *fp = NULL;
+ HI_U32 i = 0, j = 0, n = 0;
+ HI_U32 u32Height = 0, u32Width = 0, u32Chn = 0, u32Stride = 0, u32Dim = 0;
+ HI_U32 u32VarSize = 0;
+ HI_U8 *pu8PicAddr = NULL;
+ HI_U32 *pu32StepAddr = NULL;
+ HI_U32 u32SegIdx = pstInputDataIdx->u32SegIdx;
+ HI_U32 u32NodeIdx = pstInputDataIdx->u32NodeIdx;
+ HI_U32 u32TotalStepNum = 0;
+ HI_ULONG ulSize;
+ HI_CHAR path[PATH_MAX] = {0};
+
+ /* open file */
+ SAMPLE_SVP_CHECK_EXPR_RET(pstNnieCfg->pszPic == HI_NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstNnieCfg->pszPic is null!\n");
+ SAMPLE_SVP_CHECK_EXPR_RET(pstInputDataIdx->u32SegIdx >= SVP_NNIE_MAX_NET_SEG_NUM, HI_INVALID_VALUE,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error, u32SegIdx should be less than %u!\n", SVP_NNIE_MAX_NET_SEG_NUM);
+ SAMPLE_SVP_CHECK_EXPR_RET(pstInputDataIdx->u32NodeIdx >= SVP_NNIE_MAX_INPUT_NUM, HI_INVALID_VALUE,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error, u32NodeIdx should be less than %u!\n", SVP_NNIE_MAX_INPUT_NUM);
+
+ SAMPLE_SVP_CHECK_EXPR_RET((strlen(pstNnieCfg->pszPic) > PATH_MAX) ||
+ (realpath(pstNnieCfg->pszPic, path) == HI_NULL),
+ HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error, file_name is invalid!\n");
+ fp = fopen(path, "rb");
+ SAMPLE_SVP_CHECK_EXPR_RET(fp == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error, open file failed!\n");
+
+ /* get data size */
+ if (SVP_BLOB_TYPE_U8 <= pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType &&
+ SVP_BLOB_TYPE_YVU422SP >= pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType) {
+ u32VarSize = sizeof(HI_U8);
+ } else {
+ u32VarSize = sizeof(HI_U32);
+ }
+
+ /* fill src data */
+ if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType) {
+ u32Dim = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].unShape.stSeq.u32Dim;
+ u32Stride = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Stride;
+ pu32StepAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].unShape.stSeq.u64VirAddrStep);
+ pu8PicAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U8,
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64VirAddr);
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < *(pu32StepAddr + n); i++) {
+ ulSize = fread(pu8PicAddr, u32Dim * u32VarSize, 1, fp);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(ulSize != 1, FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Read image file failed!\n");
+ pu8PicAddr += u32Stride;
+ }
+ u32TotalStepNum += *(pu32StepAddr + n);
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64VirAddr),
+ u32TotalStepNum * u32Stride);
+ } else {
+ u32Height = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].unShape.stWhc.u32Height;
+ u32Width = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].unShape.stWhc.u32Width;
+ u32Chn = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].unShape.stWhc.u32Chn;
+ u32Stride = pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Stride;
+ pu8PicAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U8,
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64VirAddr);
+ if (SVP_BLOB_TYPE_YVU420SP == pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType) {
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < u32Chn * u32Height / 2; i++) { /* Brightness: 1 height, Chroma: 1/2 height */
+ ulSize = fread(pu8PicAddr, u32Width * u32VarSize, 1, fp);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(ulSize != 1, FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Read image file failed!\n");
+ pu8PicAddr += u32Stride;
+ }
+ }
+ } else if (SVP_BLOB_TYPE_YVU422SP == pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType) {
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < u32Height * 2; i++) { /* Brightness: 1 height, Chroma: 1 height */
+ ulSize = fread(pu8PicAddr, u32Width * u32VarSize, 1, fp);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(ulSize != 1, FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Read image file failed!\n");
+ pu8PicAddr += u32Stride;
+ }
+ }
+ } else {
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < u32Chn; i++) {
+ for (j = 0; j < u32Height; j++) {
+ ulSize = fread(pu8PicAddr, u32Width * u32VarSize, 1, fp);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(ulSize != 1, FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Read image file failed!\n");
+ pu8PicAddr += u32Stride;
+ }
+ }
+ }
+ }
+ SAMPLE_COMM_SVP_FlushCache(pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64PhyAddr,
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_VOID,
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64VirAddr),
+ pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num * u32Chn * u32Height * u32Stride);
+ }
+
+ (HI_VOID)fclose(fp);
+ return HI_SUCCESS;
+FAIL:
+
+ (HI_VOID)fclose(fp);
+ return HI_FAILURE;
+}
+
+/* function : print report result */
+static HI_S32 SAMPLE_SVP_NNIE_PrintReportResult(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam)
+{
+ HI_U32 u32SegNum = pstNnieParam->pstModel->u32NetSegNum;
+ HI_U32 i = 0, j = 0, k = 0, n = 0;
+ HI_U32 u32SegIdx = 0, u32NodeIdx = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_CHAR acReportFileName[SAMPLE_SVP_NNIE_REPORT_NAME_LENGTH] = {'\0'};
+ FILE *fp = NULL;
+ HI_U32 *pu32StepAddr = NULL;
+ HI_S32 *ps32ResultAddr = NULL;
+ HI_U32 u32Height = 0, u32Width = 0, u32Chn = 0, u32Stride = 0, u32Dim = 0;
+
+ for (u32SegIdx = 0; u32SegIdx < u32SegNum; u32SegIdx++) {
+ for (u32NodeIdx = 0; u32NodeIdx < pstNnieParam->pstModel->astSeg[u32SegIdx].u16DstNum; u32NodeIdx++) {
+ s32Ret = snprintf_s(acReportFileName, SAMPLE_SVP_NNIE_REPORT_NAME_LENGTH,
+ SAMPLE_SVP_NNIE_REPORT_NAME_LENGTH - 1, "seg%d_layer%d_output%d_inst.linear.hex", u32SegIdx,
+ pstNnieParam->pstModel->astSeg[u32SegIdx].astDstNode[u32NodeIdx].u32NodeId, 0);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret < 0, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,create file name failed!\n");
+
+ fp = fopen(acReportFileName, "w");
+ SAMPLE_SVP_CHECK_EXPR_RET(fp == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,open file failed!\n");
+
+ if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].enType) {
+ u32Dim = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].unShape.stSeq.u32Dim;
+ u32Stride = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u32Stride;
+ pu32StepAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32,
+ pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].unShape.stSeq.u64VirAddrStep);
+ ps32ResultAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,
+ pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u64VirAddr);
+
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < *(pu32StepAddr + n); i++) {
+ for (j = 0; j < u32Dim; j++) {
+ s32Ret = fprintf(fp, "%08x\n", *(ps32ResultAddr + j));
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret < 0, PRINT_FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,write report result file failed!\n");
+ }
+ ps32ResultAddr += u32Stride / sizeof(HI_U32);
+ }
+ }
+ } else {
+ u32Height = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].unShape.stWhc.u32Height;
+ u32Width = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].unShape.stWhc.u32Width;
+ u32Chn = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].unShape.stWhc.u32Chn;
+ u32Stride = pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u32Stride;
+ ps32ResultAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,
+ pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u64VirAddr);
+ for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u32Num; n++) {
+ for (i = 0; i < u32Chn; i++) {
+ for (j = 0; j < u32Height; j++) {
+ for (k = 0; k < u32Width; k++) {
+ s32Ret = fprintf(fp, "%08x\n", *(ps32ResultAddr + k));
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret < 0, PRINT_FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,write report result file failed!\n");
+ }
+ ps32ResultAddr += u32Stride / sizeof(HI_U32);
+ }
+ }
+ }
+ }
+ (HI_VOID)fclose(fp);
+ }
+ }
+ return HI_SUCCESS;
+
+PRINT_FAIL:
+ (HI_VOID)fclose(fp);
+ return HI_FAILURE;
+}
+
+/* function : Cnn software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Cnn_SoftwareDeinit(SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S *pstCnnSoftWarePara)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstCnnSoftWarePara == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstCnnSoftWarePara can't be NULL!\n");
+ if ((pstCnnSoftWarePara->stGetTopN.u64PhyAddr != 0) && (pstCnnSoftWarePara->stGetTopN.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstCnnSoftWarePara->stGetTopN.u64PhyAddr, pstCnnSoftWarePara->stGetTopN.u64VirAddr);
+ pstCnnSoftWarePara->stGetTopN.u64PhyAddr = 0;
+ pstCnnSoftWarePara->stGetTopN.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Cnn Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Cnn_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware para deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software para deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Cnn_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Cnn software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Cnn_SoftwareParaInit(SAMPLE_SVP_NNIE_CFG_S *pstNnieCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstCnnPara, SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S *pstCnnSoftWarePara)
+{
+ HI_U32 u32GetTopNMemSize = 0;
+ HI_U32 u32GetTopNAssistBufSize = 0;
+ HI_U32 u32GetTopNPerFrameSize = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32ClassNum = pstCnnPara->pstModel->astSeg[0].astDstNode[0].unShape.stWhc.u32Width;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U64 u64Tmp;
+
+ /* get mem size */
+ u64Tmp = (HI_U64)pstCnnSoftWarePara->u32TopN * sizeof(SAMPLE_SVP_NNIE_CNN_GETTOPN_UNIT_S);
+ SAMPLE_SVP_CHECK_EXPR_RET(u64Tmp > SAMPLE_SVP_NNIE_MAX_MEM, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,u64Tmp should be less than %u!\n", SAMPLE_SVP_NNIE_MAX_MEM);
+ u32GetTopNPerFrameSize = (HI_U32)u64Tmp;
+
+ u64Tmp = SAMPLE_SVP_NNIE_ALIGN16(u32GetTopNPerFrameSize) * (HI_U64)pstNnieCfg->u32MaxInputNum;
+ SAMPLE_SVP_CHECK_EXPR_RET(u64Tmp > SAMPLE_SVP_NNIE_MAX_MEM, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,u64Tmp should be less than %u!\n", SAMPLE_SVP_NNIE_MAX_MEM);
+ u32GetTopNMemSize = (HI_U32)u64Tmp;
+
+ u64Tmp = (HI_U64)u32ClassNum * sizeof(SAMPLE_SVP_NNIE_CNN_GETTOPN_UNIT_S);
+ SAMPLE_SVP_CHECK_EXPR_RET(u64Tmp > SAMPLE_SVP_NNIE_MAX_MEM, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,u64Tmp should be less than %u!\n", SAMPLE_SVP_NNIE_MAX_MEM);
+ u32GetTopNAssistBufSize = (HI_U32)u64Tmp;
+
+ SAMPLE_SVP_CHECK_EXPR_RET((HI_U64)u32GetTopNMemSize + u32GetTopNAssistBufSize > SAMPLE_SVP_NNIE_MAX_MEM,
+ HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,total size should be less than %u!\n",
+ SAMPLE_SVP_NNIE_MAX_MEM);
+ u32TotalSize = u32GetTopNMemSize + u32GetTopNAssistBufSize;
+
+ /* malloc mem */
+ s32Ret =
+ SAMPLE_COMM_SVP_MallocMem("SAMPLE_CNN_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr, u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+
+ /* init GetTopn */
+ pstCnnSoftWarePara->stGetTopN.u32Num = pstNnieCfg->u32MaxInputNum;
+ pstCnnSoftWarePara->stGetTopN.unShape.stWhc.u32Chn = 1;
+ pstCnnSoftWarePara->stGetTopN.unShape.stWhc.u32Height = 1;
+ pstCnnSoftWarePara->stGetTopN.unShape.stWhc.u32Width = u32GetTopNPerFrameSize / sizeof(HI_U32);
+ pstCnnSoftWarePara->stGetTopN.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32GetTopNPerFrameSize);
+ pstCnnSoftWarePara->stGetTopN.u64PhyAddr = u64PhyAddr;
+ pstCnnSoftWarePara->stGetTopN.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr);
+
+ /* init AssistBuf */
+ pstCnnSoftWarePara->stAssistBuf.u32Size = u32GetTopNAssistBufSize;
+ pstCnnSoftWarePara->stAssistBuf.u64PhyAddr = u64PhyAddr + u32GetTopNMemSize;
+ pstCnnSoftWarePara->stAssistBuf.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32GetTopNMemSize;
+
+ return s32Ret;
+}
+
+/* function : Cnn init */
+static HI_S32 SAMPLE_SVP_NNIE_Cnn_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstNnieCfg, SAMPLE_SVP_NNIE_PARAM_S *pstCnnPara,
+ SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S *pstCnnSoftWarePara)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstNnieCfg, pstCnnPara);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software para */
+ if (pstCnnSoftWarePara != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_SoftwareParaInit(pstNnieCfg, pstCnnPara, pstCnnSoftWarePara);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Cnn_SoftwareParaInit failed!\n", s32Ret);
+ }
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_Deinit(pstCnnPara, pstCnnSoftWarePara, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Cnn_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+
+/* function : Cnn process */
+static HI_S32 SAMPLE_SVP_NNIE_Cnn_PrintResult(SVP_BLOB_S *pstGetTopN, HI_U32 u32TopN)
+{
+ HI_U32 i, j;
+ HI_U32 *pu32Tmp = NULL;
+ HI_U32 u32Stride;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstGetTopN == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,pstGetTopN can't be NULL!\n");
+
+ u32Stride = pstGetTopN->u32Stride;
+ for (j = 0; j < pstGetTopN->u32Num; j++) {
+ SAMPLE_SVP_TRACE_INFO("==== The %dth image info====\n", j);
+ pu32Tmp = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, ((HI_UL)pstGetTopN->u64VirAddr + j * u32Stride));
+ for (i = 0; i < u32TopN * 2; i += 2) { /* leave a space */
+ SAMPLE_SVP_TRACE_INFO("%d:%d\n", pu32Tmp[i], pu32Tmp[i + 1]);
+ }
+ }
+ return HI_SUCCESS;
+}
+static hi_void SAMPLE_SVP_NNIE_Cnn_Stop(void)
+{
+ SAMPLE_SVP_NNIE_Cnn_Deinit(&s_stCnnNnieParam, &s_stCnnSoftwareParam, &s_stCnnModel);
+ (HI_VOID)memset_s(&s_stCnnNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stCnnSoftwareParam, sizeof(SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stCnnModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show Cnn sample(image 28x28 U8_C1) */
+void SAMPLE_SVP_NNIE_Cnn(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/y/0_28x28.y";
+ const HI_CHAR *pcModelName = "./data/nnie_model/classification/inst_mnist_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ s_stCnnSoftwareParam.u32TopN = 5; /* to get 5 highest results */
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Cnn_Stop();
+ return;
+ }
+
+ /* CNN Load model */
+ SAMPLE_SVP_TRACE_INFO("Cnn Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stCnnModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* CNN parameter initialization */
+ /* Cnn software parameters are set in SAMPLE_SVP_NNIE_Cnn_SoftwareParaInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Cnn_SoftwareParaInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Cnn parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Cnn_Stop();
+ return;
+ }
+ s_stCnnNnieParam.pstModel = &s_stCnnModel.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_ParamInit(&stNnieCfg, &s_stCnnNnieParam, &s_stCnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Cnn_ParamInit failed!\n");
+
+ /* record tskBuf */
+ s32Ret = HI_MPI_SVP_NNIE_AddTskBuf(&(s_stCnnNnieParam.astForwardCtrl[0].stTskBuf));
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,HI_MPI_SVP_NNIE_AddTskBuf failed!\n");
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Cnn start!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Cnn_Stop();
+ return;
+ }
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stCnnNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Cnn_Stop();
+ return;
+ }
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stCnnNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* Software process */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Cnn_GetTopN
+ function's input data are correct */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Cnn_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_GetTopN(&s_stCnnNnieParam, &s_stCnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_CnnGetTopN failed!\n");
+
+ /* Print result */
+ SAMPLE_SVP_TRACE_INFO("Cnn result:\n");
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_PrintResult(&(s_stCnnSoftwareParam.stGetTopN), s_stCnnSoftwareParam.u32TopN);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Cnn_PrintResult failed!\n");
+
+CNN_FAIL_1:
+ /* Remove TskBuf */
+ s32Ret = HI_MPI_SVP_NNIE_RemoveTskBuf(&(s_stCnnNnieParam.astForwardCtrl[0].stTskBuf));
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, CNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,HI_MPI_SVP_NNIE_RemoveTskBuf failed!\n");
+CNN_FAIL_0:
+ SAMPLE_SVP_NNIE_Cnn_Deinit(&s_stCnnNnieParam, &s_stCnnSoftwareParam, &s_stCnnModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+hi_void SAMPLE_SVP_NNIE_Cnn_HandleSig(hi_void)
+{
+ g_stop_signal = HI_TRUE;
+}
+static void SAMPLE_SVP_NNIE_Segnet_Stop(void)
+{
+ SAMPLE_SVP_NNIE_Cnn_Deinit(&s_stSegnetNnieParam, NULL, &s_stSegnetModel);
+ (HI_VOID)memset_s(&s_stSegnetNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stSegnetModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show Segnet sample(image 224x224 U8_C3) */
+void SAMPLE_SVP_NNIE_Segnet(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/segnet_image_224x224.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/segmentation/inst_segnet_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0;
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Segnet_Stop();
+ return;
+ }
+ /* Segnet Load model */
+ SAMPLE_SVP_TRACE_INFO("Segnet Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stSegnetModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SEGNET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* Segnet parameter initialization */
+ SAMPLE_SVP_TRACE_INFO("Segnet parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Segnet_Stop();
+ return;
+ }
+ s_stSegnetNnieParam.pstModel = &s_stSegnetModel.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Cnn_ParamInit(&stNnieCfg, &s_stSegnetNnieParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SEGNET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Cnn_ParamInit failed!\n");
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Segnet start!\n");
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Segnet_Stop();
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stSegnetNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SEGNET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Segnet_Stop();
+ return;
+ }
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stSegnetNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SEGNET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* print report result */
+ s32Ret = SAMPLE_SVP_NNIE_PrintReportResult(&s_stSegnetNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SEGNET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_PrintReportResult failed!\n");
+
+ SAMPLE_SVP_TRACE_INFO("Segnet is successfully processed!\n");
+
+SEGNET_FAIL_0:
+ SAMPLE_SVP_NNIE_Cnn_Deinit(&s_stSegnetNnieParam, NULL, &s_stSegnetModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : Segnet sample signal handle */
+hi_void SAMPLE_SVP_NNIE_Segnet_HandleSig(hi_void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : print detection result */
+static HI_S32 SAMPLE_SVP_NNIE_Detection_PrintResult(SVP_BLOB_S *pstDstScore, SVP_BLOB_S *pstDstRoi,
+ SVP_BLOB_S *pstClassRoiNum, HI_FLOAT f32PrintResultThresh)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RoiNumBias = 0;
+ HI_U32 u32ScoreBias = 0;
+ HI_U32 u32BboxBias = 0;
+ HI_FLOAT f32Score = 0.0f;
+ HI_S32 *ps32Score = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstScore->u64VirAddr);
+ HI_S32 *ps32Roi = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstRoi->u64VirAddr);
+ HI_S32 *ps32ClassRoiNum = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstClassRoiNum->u64VirAddr);
+ HI_U32 u32ClassNum = pstClassRoiNum->unShape.stWhc.u32Width;
+ HI_S32 s32XMin = 0, s32YMin = 0, s32XMax = 0, s32YMax = 0;
+
+ u32RoiNumBias += ps32ClassRoiNum[0];
+ for (i = 1; i < u32ClassNum; i++) {
+ u32ScoreBias = u32RoiNumBias;
+ u32BboxBias = u32RoiNumBias * SAMPLE_SVP_NNIE_COORDI_NUM;
+ /* if the confidence score greater than result threshold, the result will be printed */
+ if ((HI_FLOAT)ps32Score[u32ScoreBias] / SAMPLE_SVP_NNIE_QUANT_BASE >= f32PrintResultThresh &&
+ ps32ClassRoiNum[i] != 0) {
+ SAMPLE_SVP_TRACE_INFO("==== The %dth class box info====\n", i);
+ }
+ for (j = 0; j < (HI_U32)ps32ClassRoiNum[i]; j++) {
+ f32Score = (HI_FLOAT)ps32Score[u32ScoreBias + j] / SAMPLE_SVP_NNIE_QUANT_BASE;
+ if (f32Score < f32PrintResultThresh) {
+ break;
+ }
+ s32XMin = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM];
+ s32YMin = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + 1]; /* to get next element of this array */
+ s32XMax = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + 2]; /* to get next element of this array */
+ s32YMax = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + 3]; /* to get next element of this array */
+ SAMPLE_SVP_TRACE_INFO("%d %d %d %d %f\n", s32XMin, s32YMin, s32XMax, s32YMax, f32Score);
+ }
+ u32RoiNumBias += ps32ClassRoiNum[i];
+ }
+ return HI_SUCCESS;
+}
+
+/* function : FasterRcnn software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_FasterRcnn_SoftwareDeinit(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stRpnTmpBuf.u64PhyAddr != 0) && (pstSoftWareParam->stRpnTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stRpnTmpBuf.u64PhyAddr, pstSoftWareParam->stRpnTmpBuf.u64VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : FasterRcnn Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_FasterRcnn_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : FasterRcnn software para init */
+static HI_S32 SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam, SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RpnTmpBufSize = 0;
+ HI_U32 u32RpnBboxBufSize = 0;
+ HI_U32 u32GetResultTmpBufSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* RPN parameter init */
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->u32MaxRoiNum = pstCfg->u32MaxRoiNum;
+ if (SAMPLE_SVP_NNIE_VGG16_FASTER_RCNN == s_enNetType) {
+ pstSoftWareParam->u32ClassNum = 4;
+ pstSoftWareParam->u32NumRatioAnchors = 3;
+ pstSoftWareParam->u32NumScaleAnchors = 3;
+ pstSoftWareParam->au32Scales[0] = 8 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[1] = 16 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[2] = 32 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[0] = 0.5 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[1] = 1 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[2] = 2 * SAMPLE_SVP_QUANT_BASE;
+ } else {
+ pstSoftWareParam->u32ClassNum = 2;
+ pstSoftWareParam->u32NumRatioAnchors = 1;
+ pstSoftWareParam->u32NumScaleAnchors = 9;
+ pstSoftWareParam->au32Scales[0] = 1.5 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[1] = 2.1 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[2] = 2.9 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[3] = 4.1 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[4] = 5.8 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[5] = 8.0 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[6] = 11.3 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[7] = 15.8 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[8] = 22.1 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[0] = 2.44 * SAMPLE_SVP_QUANT_BASE;
+ }
+
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32MinSize = 16;
+ pstSoftWareParam->u32FilterThresh = 16;
+ pstSoftWareParam->u32SpatialScale = (HI_U32)(0.0625 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.7 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->u32FilterThresh = 0;
+ pstSoftWareParam->u32NumBeforeNms = 6000;
+ for (i = 0; i < pstSoftWareParam->u32ClassNum; i++) {
+ pstSoftWareParam->au32ConfThresh[i] = 1;
+ }
+ pstSoftWareParam->u32ValidNmsThresh = (HI_U32)(0.3 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->stRpnBbox.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height = pstCfg->u32MaxRoiNum;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Width = SAMPLE_SVP_COORDI_NUM;
+ pstSoftWareParam->stRpnBbox.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(SAMPLE_SVP_COORDI_NUM * sizeof(HI_U32));
+ pstSoftWareParam->stRpnBbox.u32Num = 1;
+ for (i = 0; i < SAMPLE_SVP_NNIE_SEGMENT_NUM; i++) {
+ for (j = 0; j < pstNnieParam->pstModel->astSeg[0].u16DstNum; j++) {
+ if (strncmp(pstNnieParam->pstModel->astSeg[0].astDstNode[j].szName,
+ pstSoftWareParam->apcRpnDataLayerName[i], SVP_NNIE_NODE_NAME_LEN) == 0) {
+ pstSoftWareParam->aps32Conv[i] =
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstNnieParam->astSegData[0].astDst[j].u64VirAddr);
+ pstSoftWareParam->au32ConvHeight[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Height;
+ pstSoftWareParam->au32ConvWidth[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Width;
+ pstSoftWareParam->au32ConvChannel[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Chn;
+ break;
+ }
+ }
+ SAMPLE_SVP_CHECK_EXPR_RET((j == pstNnieParam->pstModel->astSeg[0].u16DstNum), HI_FAILURE,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,failed to find report node %s!\n",
+ pstSoftWareParam->apcRpnDataLayerName[i]);
+ if (i == 0) {
+ pstSoftWareParam->u32ConvStride = pstNnieParam->astSegData[0].astDst[j].u32Stride;
+ }
+ }
+
+ /* calculate software mem size */
+ u32ClassNum = pstSoftWareParam->u32ClassNum;
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_RpnTmpBufSize(pstSoftWareParam->u32NumRatioAnchors,
+ pstSoftWareParam->u32NumScaleAnchors, pstSoftWareParam->au32ConvHeight[0], pstSoftWareParam->au32ConvWidth[0]);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32RpnTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_RpnTmpBufSize failed!\n");
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32RpnTmpBufSize);
+ u32RpnBboxBufSize = pstSoftWareParam->stRpnBbox.u32Num * pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height *
+ pstSoftWareParam->stRpnBbox.u32Stride;
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_FasterRcnn_GetResultTmpBufSize(pstCfg->u32MaxRoiNum, u32ClassNum);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32GetResultTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_GetResultTmpBufSize failed!\n");
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32GetResultTmpBufSize);
+ u32DstRoiSize =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32) * SAMPLE_SVP_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize +
+ u32ClassRoiNumSize;
+
+ /* malloc mem */
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_RCNN_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set addr */
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u32Size = u32RpnTmpBufSize;
+
+ pstSoftWareParam->stRpnBbox.u64PhyAddr = u64PhyAddr + u32RpnTmpBufSize;
+ pstSoftWareParam->stRpnBbox.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr) + u32RpnTmpBufSize;
+
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize);
+ pstSoftWareParam->stGetResultTmpBuf.u32Size = u32GetResultTmpBufSize;
+
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize);
+ pstSoftWareParam->stDstRoi.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32) * SAMPLE_SVP_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width =
+ u32ClassNum * pstSoftWareParam->u32MaxRoiNum * SAMPLE_SVP_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr =
+ u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) +
+ u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * pstSoftWareParam->u32MaxRoiNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr =
+ u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) +
+ u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : FasterRcnn parameter initialization */
+static HI_S32 SAMPLE_SVP_NNIE_FasterRcnn_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstFasterRcnnCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam, SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware parameter */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstFasterRcnnCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software parameter */
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit(pstFasterRcnnCfg, pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_FasterRcnn_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+static hi_void SAMPLE_SVP_NNIE_FasterRcnn_Stop(hi_void)
+{
+ SAMPLE_SVP_NNIE_FasterRcnn_Deinit(&s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam, &s_stFasterRcnnModel);
+ (HI_VOID)memset_s(&s_stFasterRcnnNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stFasterRcnnSoftwareParam, sizeof(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stFasterRcnnModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show fasterRcnn sample(image 1240x375 U8_C3) */
+void SAMPLE_SVP_NNIE_FasterRcnn(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/single_person_1240x375.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_alexnet_frcnn_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 i = 0;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+ g_stop_signal = HI_FALSE;
+
+ /* Set configuration parameter */
+ s_enNetType = SAMPLE_SVP_NNIE_ALEXNET_FASTER_RCNN;
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 300; // set maxmum 300 ROIs
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core for 0-th Seg
+ stNnieCfg.aenNnieCoreId[1] = SVP_NNIE_ID_0; // set NNIE core for 1-th Seg
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ /* FasterRcnn Load model */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stFasterRcnnModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* FasterRcnn para init */
+ /* apcRpnDataLayerName is used to set RPN data layer name
+ and search RPN input data,if user has changed network struct, please
+ make sure the data layer names are correct */
+ /* FasterRcnn parameters are set in SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit,
+ if user has changed network struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s_stFasterRcnnNnieParam.pstModel = &s_stFasterRcnnModel.stModel;
+ s_stFasterRcnnSoftwareParam.apcRpnDataLayerName[0] = "rpn_cls_score";
+ s_stFasterRcnnSoftwareParam.apcRpnDataLayerName[1] = "rpn_bbox_pred";
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_ParamInit(&stNnieCfg, &s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_ParamInit failed!\n");
+
+ /* Fill 0-th input node of 0-th seg */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn start!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stFasterRcnnNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process 0-th seg */
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stFasterRcnnNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* RPN */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_Rpn(&s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_Rpn failed!\n");
+
+ if (s_stFasterRcnnSoftwareParam.stRpnBbox.unShape.stWhc.u32Height != 0) {
+ /* NNIE process 1-th seg, the input conv data comes from 0-th seg's 0-th report node,
+ the input roi comes from RPN results */
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ stProcSegIdx.u32SegIdx = 1;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_ForwardWithBbox(&s_stFasterRcnnNnieParam, &stInputDataIdx,
+ &s_stFasterRcnnSoftwareParam.stRpnBbox, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* GetResult */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_FasterRcnn_GetResult
+ function's input data are correct */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_GetResult(&s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_GetResult failed!\n");
+ } else {
+ for (i = 0; i < s_stFasterRcnnSoftwareParam.stClassRoiNum.unShape.stWhc.u32Width; i++) {
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, s_stFasterRcnnSoftwareParam.stClassRoiNum.u64VirAddr) + i) = 0;
+ }
+ }
+ /* print result, Alexnet_FasterRcnn has 2 classes:
+ class 0:background class 1:pedestrian */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stFasterRcnnSoftwareParam.stDstScore,
+ &s_stFasterRcnnSoftwareParam.stDstRoi, &s_stFasterRcnnSoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+FRCNN_FAIL_0:
+ SAMPLE_SVP_NNIE_FasterRcnn_Deinit(&s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam, &s_stFasterRcnnModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function :show fasterrcnn double_roipooling sample(image 224x224 U8_C3) */
+void SAMPLE_SVP_NNIE_FasterRcnn_DoubleRoiPooling(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/double_roipooling_224_224.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_fasterrcnn_double_roipooling_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 i = 0;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ s_enNetType = SAMPLE_SVP_NNIE_VGG16_FASTER_RCNN;
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 300; // set maxmum 300 ROIs
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core for 0-th Seg
+ stNnieCfg.aenNnieCoreId[1] = SVP_NNIE_ID_0; // set NNIE core for 1-th Seg
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ /* FasterRcnn Load model */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stFasterRcnnModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* FasterRcnn para init */
+ /* apcRpnDataLayerName is used to set RPN data layer name
+ and search RPN input data,if user has changed network struct, please
+ make sure the data layer names are correct */
+ /* FasterRcnn parameters are set in SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit,
+ if user has changed network struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_FaasterRcnn_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s_stFasterRcnnNnieParam.pstModel = &s_stFasterRcnnModel.stModel;
+ s_stFasterRcnnSoftwareParam.apcRpnDataLayerName[0] = "rpn_cls_score";
+ s_stFasterRcnnSoftwareParam.apcRpnDataLayerName[1] = "rpn_bbox_pred";
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_ParamInit(&stNnieCfg, &s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_ParamInit failed!\n");
+
+ /* Fill 0-th input node of 0-th seg */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn start!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stFasterRcnnNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process 0-th seg */
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stFasterRcnnNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* RPN */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_FasterRcnn_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_Rpn(&s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_Rpn failed!\n");
+ if (s_stFasterRcnnSoftwareParam.stRpnBbox.unShape.stWhc.u32Height != 0) {
+ /* NNIE process 1-st seg, the input conv data comes from 0-th seg's 0-th and
+ 1-st report node,the input roi comes from RPN results */
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ stProcSegIdx.u32SegIdx = 1;
+ s32Ret = SAMPLE_SVP_NNIE_ForwardWithBbox(&s_stFasterRcnnNnieParam, &stInputDataIdx,
+ &s_stFasterRcnnSoftwareParam.stRpnBbox, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* GetResult */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_FasterRcnn_GetResult
+ function's input data are correct */
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_GetResult(&s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FRCNN_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_GetResult failed!\n");
+ } else {
+ for (i = 0; i < s_stFasterRcnnSoftwareParam.stClassRoiNum.unShape.stWhc.u32Width; i++) {
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, s_stFasterRcnnSoftwareParam.stClassRoiNum.u64VirAddr) + i) = 0;
+ }
+ }
+ /* print result, FasterRcnn has 4 classes:
+ class 0:background class 1:person class 2:people class 3:person sitting */
+ SAMPLE_SVP_TRACE_INFO("FasterRcnn result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stFasterRcnnSoftwareParam.stDstScore,
+ &s_stFasterRcnnSoftwareParam.stDstRoi, &s_stFasterRcnnSoftwareParam.stClassRoiNum, f32PrintResultThresh);
+FRCNN_FAIL_0:
+ SAMPLE_SVP_NNIE_FasterRcnn_Deinit(&s_stFasterRcnnNnieParam, &s_stFasterRcnnSoftwareParam, &s_stFasterRcnnModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : fasterRcnn sample signal handle */
+hi_void SAMPLE_SVP_NNIE_FasterRcnn_HandleSig(hi_void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Rfcn software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_SoftwareDeinit(SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if (pstSoftWareParam->stRpnTmpBuf.u64PhyAddr != 0 && pstSoftWareParam->stRpnTmpBuf.u64VirAddr != 0) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stRpnTmpBuf.u64PhyAddr, pstSoftWareParam->stRpnTmpBuf.u64VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Rfcn Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Rfcn software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_SoftwareInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RpnTmpBufSize = 0;
+ HI_U32 u32RpnBboxBufSize = 0;
+ HI_U32 u32GetResultTmpBufSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* init Rpn para */
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->u32MaxRoiNum = pstCfg->u32MaxRoiNum;
+ pstSoftWareParam->u32ClassNum = 21;
+ pstSoftWareParam->u32NumRatioAnchors = 3;
+ pstSoftWareParam->u32NumScaleAnchors = 3;
+ pstSoftWareParam->au32Scales[0] = 8 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->au32Scales[1] = 16 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->au32Scales[2] = 32 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[0] = 0.5 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[1] = 1 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->au32Ratios[2] = 2 * SAMPLE_SVP_NNIE_QUANT_BASE;
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32MinSize = 16;
+ pstSoftWareParam->u32FilterThresh = 0;
+ pstSoftWareParam->u32SpatialScale = (HI_U32)(0.0625 * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.7 * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32FilterThresh = 0;
+ pstSoftWareParam->u32NumBeforeNms = 6000;
+ for (i = 0; i < pstSoftWareParam->u32ClassNum; i++) {
+ pstSoftWareParam->au32ConfThresh[i] = 1;
+ pstSoftWareParam->af32ScoreThr[i] = 0.8f;
+ }
+ pstSoftWareParam->u32ValidNmsThresh = (HI_U32)(0.3 * 4096);
+
+ /* set rpn input data info, the input info is set according to RPN data layers' name */
+ for (i = 0; i < SAMPLE_SVP_NNIE_SEGMENT_NUM; i++) {
+ for (j = 0; j < pstNnieParam->pstModel->astSeg[0].u16DstNum; j++) {
+ if (strncmp(pstNnieParam->pstModel->astSeg[0].astDstNode[j].szName,
+ pstSoftWareParam->apcRpnDataLayerName[i], SVP_NNIE_NODE_NAME_LEN) == 0) {
+ pstSoftWareParam->aps32Conv[i] =
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstNnieParam->astSegData[0].astDst[j].u64VirAddr);
+ pstSoftWareParam->au32ConvHeight[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Height;
+ pstSoftWareParam->au32ConvWidth[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Width;
+ pstSoftWareParam->au32ConvChannel[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Chn;
+ break;
+ }
+ }
+ SAMPLE_SVP_CHECK_EXPR_RET((j == pstNnieParam->pstModel->astSeg[0].u16DstNum), HI_FAILURE,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,failed to find report node %s!\n",
+ pstSoftWareParam->apcRpnDataLayerName[i]);
+ if (i == 0) {
+ pstSoftWareParam->u32ConvStride = pstNnieParam->astSegData[0].astDst[j].u32Stride;
+ }
+ }
+
+ pstSoftWareParam->stRpnBbox.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height = pstCfg->u32MaxRoiNum;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Width = SAMPLE_SVP_COORDI_NUM;
+ pstSoftWareParam->stRpnBbox.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(SAMPLE_SVP_COORDI_NUM * sizeof(HI_U32));
+ pstSoftWareParam->stRpnBbox.u32Num = 1;
+
+ /* malloc software mem */
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_RpnTmpBufSize(pstSoftWareParam->u32NumRatioAnchors,
+ pstSoftWareParam->u32NumScaleAnchors, pstSoftWareParam->au32ConvHeight[0], pstSoftWareParam->au32ConvWidth[0]);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32RpnTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_RpnTmpBufSize failed!\n");
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32RpnTmpBufSize);
+ u32RpnBboxBufSize = pstSoftWareParam->stRpnBbox.u32Num * pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height *
+ pstSoftWareParam->stRpnBbox.u32Stride;
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_Rfcn_GetResultTmpBuf(pstCfg->u32MaxRoiNum, pstSoftWareParam->u32ClassNum);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32GetResultTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_GetResultTmpBuf failed!\n");
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32GetResultTmpBufSize);
+ u32ClassNum = pstSoftWareParam->u32ClassNum;
+ u32DstRoiSize =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize +
+ u32ClassRoiNumSize;
+
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_RFCN_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u32Size = u32RpnTmpBufSize;
+
+ pstSoftWareParam->stRpnBbox.u64PhyAddr = u64PhyAddr + u32RpnTmpBufSize;
+ pstSoftWareParam->stRpnBbox.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr) + u32RpnTmpBufSize;
+
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr + u32RpnTmpBufSize + u32RpnBboxBufSize;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnTmpBufSize + u32RpnBboxBufSize);
+ pstSoftWareParam->stGetResultTmpBuf.u32Size = u32GetResultTmpBufSize;
+
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize);
+ pstSoftWareParam->stDstRoi.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum *
+ sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width =
+ u32ClassNum * pstSoftWareParam->u32MaxRoiNum * SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr =
+ u64PhyAddr + u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) +
+ u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * pstSoftWareParam->u32MaxRoiNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr =
+ u64PhyAddr + u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) +
+ u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+ return s32Ret;
+}
+
+/* function : Rfcn init */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);SAMPLE_SVP_NNIE_MAX_CLASS_NUM;
+
+ /* init software para */
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_SoftwareInit(pstCfg, pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Rfcn_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Rfcn_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+
+/* function : roi to rect */
+static HI_S32 SAMPLE_SVP_NNIE_RoiToRect(SVP_BLOB_S *pstDstScore, SVP_BLOB_S *pstDstRoi, SVP_BLOB_S *pstClassRoiNum,
+ HI_FLOAT *paf32ScoreThr, HI_BOOL bRmBg, SAMPLE_SVP_NNIE_RECT_ARRAY_S *pstRect, HI_U32 u32SrcWidth,
+ HI_U32 u32SrcHeight, HI_U32 u32DstWidth, HI_U32 u32DstHeight)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RoiNumBias = 0;
+ HI_U32 u32ScoreBias = 0;
+ HI_U32 u32BboxBias = 0;
+ HI_FLOAT f32Score = 0.0f;
+ HI_S32 *ps32Score = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstScore->u64VirAddr);
+ HI_S32 *ps32Roi = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstRoi->u64VirAddr);
+ HI_S32 *ps32ClassRoiNum = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstClassRoiNum->u64VirAddr);
+ HI_U32 u32ClassNum = pstClassRoiNum->unShape.stWhc.u32Width;
+ HI_U32 u32RoiNumTmp = 0;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(u32ClassNum > SAMPLE_SVP_NNIE_MAX_CLASS_NUM, HI_ERR_SVP_NNIE_ILLEGAL_PARAM,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error(%#x),u32ClassNum(%u) must be less than or equal %u to!\n",
+ HI_ERR_SVP_NNIE_ILLEGAL_PARAM, u32ClassNum, SAMPLE_SVP_NNIE_MAX_CLASS_NUM);
+ pstRect->u32TotalNum = 0;
+ pstRect->u32ClsNum = u32ClassNum;
+ if (bRmBg) {
+ pstRect->au32RoiNum[0] = 0;
+ u32RoiNumBias += ps32ClassRoiNum[0];
+ for (i = 1; i < u32ClassNum; i++) {
+ u32ScoreBias = u32RoiNumBias;
+ u32BboxBias = u32RoiNumBias * SAMPLE_SVP_NNIE_COORDI_NUM;
+ u32RoiNumTmp = 0;
+ /* if the confidence score greater than result thresh, the result will be drew */
+ if (((HI_FLOAT)ps32Score[u32ScoreBias] / SAMPLE_SVP_NNIE_QUANT_BASE >= paf32ScoreThr[i]) &&
+ (ps32ClassRoiNum[i] != 0)) {
+ for (j = 0; j < (HI_U32)ps32ClassRoiNum[i]; j++) {
+ /* Score is descend order */
+ f32Score = (HI_FLOAT)ps32Score[u32ScoreBias + j] / SAMPLE_SVP_NNIE_QUANT_BASE;
+ if ((f32Score < paf32ScoreThr[i]) || (u32RoiNumTmp >= SAMPLE_SVP_NNIE_MAX_ROI_NUM_OF_CLASS)) {
+ break;
+ }
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X =
+ (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM] /
+ (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1);
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y =
+ (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + \
+ SAMPLE_SVP_NNIE_Y_MIN_OFFSET] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X =
+ (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + \
+ SAMPLE_SVP_NNIE_X_MAX_OFFSET] / (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1);
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32Y =
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y;
+
+ /* get the third point coordinate */
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32X =
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y =
+ (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + \
+ SAMPLE_SVP_NNIE_Y_MAX_OFFSET] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+
+ /* get the fourth point coordinate */
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32X =
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32Y =
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y;
+
+ u32RoiNumTmp++;
+ }
+ }
+
+ pstRect->au32RoiNum[i] = u32RoiNumTmp;
+ pstRect->u32TotalNum += u32RoiNumTmp;
+ u32RoiNumBias += ps32ClassRoiNum[i];
+ }
+ }
+ return HI_SUCCESS;
+}
+
+/* function : Rfcn Proc */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_Proc(SAMPLE_SVP_NNIE_PARAM_S *pstParam,
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSwParam)
+{
+ HI_S32 s32Ret = HI_FAILURE;
+ HI_U32 i = 0;
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+
+ /* NNIE process 0-th seg */
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(pstParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* RPN */
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Rpn(pstSwParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_RFCN_Rpn failed!\n");
+
+ if (pstSwParam->stRpnBbox.unShape.stWhc.u32Height != 0) {
+ /* NNIE process 1-th seg, the input data comes from 3-rd report node of 0-th seg,
+ the input roi comes from RPN results */
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 3;
+ stProcSegIdx.u32SegIdx = 1;
+ s32Ret =
+ SAMPLE_SVP_NNIE_ForwardWithBbox(pstParam, &stInputDataIdx, &pstSwParam->stRpnBbox, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* NNIE process 2-nd seg, the input data comes from 4-th report node of 0-th seg
+ the input roi comes from RPN results */
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 4;
+ stProcSegIdx.u32SegIdx = 2;
+ s32Ret =
+ SAMPLE_SVP_NNIE_ForwardWithBbox(pstParam, &stInputDataIdx, &pstSwParam->stRpnBbox, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* GetResult */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Rfcn_GetResult
+ function's input data are correct */
+
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_GetResult(pstParam, pstSwParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_GetResult failed!\n");
+ } else {
+ for (i = 0; i < pstSwParam->stClassRoiNum.unShape.stWhc.u32Width; i++) {
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, pstSwParam->stClassRoiNum.u64VirAddr) + i) = 0;
+ }
+ }
+ return s32Ret;
+}
+
+/* function : Rfcn Proc */
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_Proc_ViToVo(SAMPLE_SVP_NNIE_PARAM_S *pstParam,
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSwParam, VIDEO_FRAME_INFO_S *pstExtFrmInfo, HI_U32 u32BaseWidth,
+ HI_U32 u32BaseHeight)
+{
+ HI_S32 s32Ret = HI_FAILURE;
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ /* SP420 */
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64VirAddr =
+ pstExtFrmInfo->stVFrame.u64VirAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64PhyAddr =
+ pstExtFrmInfo->stVFrame.u64PhyAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u32Stride =
+ pstExtFrmInfo->stVFrame.u32Stride[0];
+
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Proc(pstParam, pstSwParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_Proc failed!\n");
+ /* draw result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor */
+ s32Ret = SAMPLE_SVP_NNIE_RoiToRect(&(pstSwParam->stDstScore), &(pstSwParam->stDstRoi), &(pstSwParam->stClassRoiNum),
+ pstSwParam->af32ScoreThr, HI_TRUE, &(pstSwParam->stRect), pstExtFrmInfo->stVFrame.u32Width,
+ pstExtFrmInfo->stVFrame.u32Height, u32BaseWidth, u32BaseHeight);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_RoiToRect failed!\n", s32Ret);
+
+ return s32Ret;
+}
+
+static HI_VOID SAMPLE_SVP_NNIE_Rfcn_Stop(hi_void)
+{
+ s_bNnieStopSignal = HI_TRUE;
+ if (s_hNnieThread != 0) {
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+ }
+
+ SAMPLE_SVP_NNIE_Rfcn_Deinit(&s_stRfcnNnieParam, &s_stRfcnSoftwareParam, &s_stRfcnModel);
+ (HI_VOID)memset_s(&s_stRfcnNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stRfcnSoftwareParam, sizeof(SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stRfcnModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+
+ SAMPLE_COMM_IVE_StopViVpssVencVo(&s_stViConfig, &s_stRfcnSwitch);
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+static HI_S32 SAMPLE_SVP_NNIE_Rfcn_Pause(hi_void)
+{
+ printf("---------------press Enter key to exit!---------------\n");
+ if (s_bNnieStopSignal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop();
+ return HI_FAILURE;
+ }
+ (hi_void)getchar();
+ if (s_bNnieStopSignal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop();
+ return HI_FAILURE;
+ }
+ return HI_SUCCESS;
+}
+
+/* function : Rfcn vi to vo thread entry */
+static HI_VOID *SAMPLE_SVP_NNIE_Rfcn_ViToVo(HI_VOID *pArgs)
+{
+ HI_S32 s32Ret;
+ SAMPLE_SVP_NNIE_PARAM_S *pstParam = NULL;
+ SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S *pstSwParam = NULL;
+ VIDEO_FRAME_INFO_S stBaseFrmInfo;
+ VIDEO_FRAME_INFO_S stExtFrmInfo;
+ const HI_S32 s32MilliSec = 20000; /* 20000ms timeout */
+ const VO_LAYER voLayer = 0;
+ const VO_CHN voChn = 0;
+ const HI_S32 s32VpssGrp = 0;
+ const HI_S32 as32VpssChn[] = {VPSS_CHN0, VPSS_CHN1};
+
+ hi_unused(pArgs);
+ pstParam = &s_stRfcnNnieParam;
+ pstSwParam = &s_stRfcnSoftwareParam;
+
+ struct timespec start_time1,end_time1;
+ float use_time1 =0;
+
+ while (HI_FALSE == s_bNnieStopSignal) {
+ clock_gettime(CLOCK_REALTIME, &start_time1);
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[1], &stExtFrmInfo, s32MilliSec);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n", s32Ret, s32VpssGrp,
+ as32VpssChn[1]);
+ continue;
+ }
+
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[0], &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, EXT_RELEASE,
+ "Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n", s32Ret, s32VpssGrp,
+ as32VpssChn[0]);
+
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Proc_ViToVo(pstParam, pstSwParam, &stExtFrmInfo, stBaseFrmInfo.stVFrame.u32Width,
+ stBaseFrmInfo.stVFrame.u32Height);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, BASE_RELEASE, "Error(%#x),SAMPLE_SVP_NNIE_Rfcn_Proc failed!\n",
+ s32Ret);
+
+ // Draw rect
+ s32Ret = SAMPLE_COMM_SVP_NNIE_FillRect(&stBaseFrmInfo, &(pstSwParam->stRect), 0x0000FF00);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, BASE_RELEASE,
+ "SAMPLE_COMM_SVP_NNIE_FillRect failed, Error(%#x)!\n", s32Ret);
+
+ s32Ret = HI_MPI_VO_SendFrame(voLayer, voChn, &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, BASE_RELEASE, "HI_MPI_VO_SendFrame failed, Error(%#x)!\n", s32Ret);
+
+ clock_gettime(CLOCK_REALTIME, &end_time1);
+ use_time1 = (float)(end_time1.tv_sec - start_time1.tv_sec)*1000 + (end_time1.tv_nsec - start_time1.tv_nsec) / 1000000.0;
+ SAMPLE_SVP_TRACE_INFO("The use time is %f \n", use_time1);
+
+ BASE_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp, as32VpssChn[0], &stBaseFrmInfo);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n", s32Ret, s32VpssGrp,
+ as32VpssChn[0]);
+ }
+
+ EXT_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp, as32VpssChn[1], &stExtFrmInfo);
+ if (s32Ret != HI_SUCCESS) {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n", s32Ret, s32VpssGrp,
+ as32VpssChn[1]);
+ }
+ }
+
+ return HI_NULL;
+}
+
+/* function : Rfcn Vi->VO */
+void SAMPLE_SVP_NNIE_Rfcn(void)
+{
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_rfcn_resnet50_cycle_352x288.wk";
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SIZE_S stSize;
+ PIC_SIZE_E enSize = PIC_CIF;
+ HI_S32 s32Ret = HI_SUCCESS;
+
+ (HI_VOID)memset_s(&s_stRfcnModel, sizeof(s_stRfcnModel), 0, sizeof(s_stRfcnModel));
+ (HI_VOID)memset_s(&s_stRfcnNnieParam, sizeof(s_stRfcnNnieParam), 0, sizeof(s_stRfcnNnieParam));
+ (HI_VOID)memset_s(&s_stRfcnSoftwareParam, sizeof(s_stRfcnSoftwareParam), 0, sizeof(s_stRfcnSoftwareParam));
+
+ /* step 1: start vi vpss vo */
+ s_stRfcnSwitch.bVenc = HI_FALSE;
+ s_stRfcnSwitch.bVo = HI_TRUE;
+ s32Ret = SAMPLE_COMM_IVE_StartViVpssVencVo(&s_stViConfig, &s_stRfcnSwitch, &enSize);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, "Error(%#x),SAMPLE_COMM_IVE_StartViVpssVencVo failed!\n",
+ s32Ret);
+
+ s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSize, &stSize);
+ SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, "Error(%#x),SAMPLE_COMM_SYS_GetPicSize failed!\n", s32Ret);
+
+ /* step 2: init NNIE param */
+ stNnieCfg.pszPic = NULL;
+ stNnieCfg.u32MaxInputNum = 1; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 300; // set maxmum 300 ROIs
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core for 0-th Seg
+ stNnieCfg.aenNnieCoreId[1] = SVP_NNIE_ID_0; // set NNIE core for 1-th Seg
+ stNnieCfg.aenNnieCoreId[2] = SVP_NNIE_ID_0; // set NNIE core for 2-th Seg
+
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stRfcnModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* apcRpnDataLayerName is used to set RPN data layer name
+ and search RPN input data,if user has changed network struct, please
+ make sure the data layer names are correct */
+ s_stRfcnNnieParam.pstModel = &s_stRfcnModel.stModel;
+ s_stRfcnSoftwareParam.apcRpnDataLayerName[0] = "rpn_cls_score";
+ s_stRfcnSoftwareParam.apcRpnDataLayerName[1] = "rpn_bbox_pred";
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_ParamInit(&stNnieCfg, &s_stRfcnNnieParam, &s_stRfcnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_ParamInit failed!\n");
+
+ s_bNnieStopSignal = HI_FALSE;
+
+ /* step 3: Create work thread */
+ s32Ret = prctl(PR_SET_NAME, "NNIE_ViToVo", 0, 0, 0);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_1, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "thread set name failed!\n");
+ s32Ret = pthread_create(&s_hNnieThread, 0, SAMPLE_SVP_NNIE_Rfcn_ViToVo, NULL);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_1, SAMPLE_SVP_ERR_LEVEL_ERROR, "thread create failed!\n");
+
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Pause();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR, "vi_rfcn_vo exit!\n");
+
+ s_bNnieStopSignal = HI_TRUE;
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+END_RFCN_1:
+
+ SAMPLE_SVP_NNIE_Rfcn_Deinit(&s_stRfcnNnieParam, &s_stRfcnSoftwareParam, &s_stRfcnModel);
+END_RFCN_0:
+ SAMPLE_COMM_IVE_StopViVpssVencVo(&s_stViConfig, &s_stRfcnSwitch);
+ return;
+}
+
+/* function : rfcn sample signal handle */
+void SAMPLE_SVP_NNIE_Rfcn_HandleSig(void)
+{
+ s_bNnieStopSignal = HI_TRUE;
+}
+
+/* function : rfcn sample signal handle */
+static hi_void SAMPLE_SVP_NNIE_Rfcn_Stop_File(hi_void)
+{
+ SAMPLE_SVP_NNIE_Rfcn_Deinit(&s_stRfcnNnieParam, &s_stRfcnSoftwareParam, &s_stRfcnModel);
+ (HI_VOID)memset_s(&s_stRfcnModel, sizeof(s_stRfcnModel), 0, sizeof(s_stRfcnModel));
+ (HI_VOID)memset_s(&s_stRfcnNnieParam, sizeof(s_stRfcnNnieParam), 0, sizeof(s_stRfcnNnieParam));
+ (HI_VOID)memset_s(&s_stRfcnSoftwareParam, sizeof(s_stRfcnSoftwareParam), 0, sizeof(s_stRfcnSoftwareParam));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+void SAMPLE_SVP_NNIE_Rfcn_HandleSig_File(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Rfcn Read file */
+void SAMPLE_SVP_NNIE_Rfcn_File(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/hoser_dog_car_person_800x600.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_rfcn_resnet50_cycle.wk";
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+
+ (HI_VOID)memset_s(&s_stRfcnModel, sizeof(s_stRfcnModel), 0, sizeof(s_stRfcnModel));
+ (HI_VOID)memset_s(&s_stRfcnNnieParam, sizeof(s_stRfcnNnieParam), 0, sizeof(s_stRfcnNnieParam));
+ (HI_VOID)memset_s(&s_stRfcnSoftwareParam, sizeof(s_stRfcnSoftwareParam), 0, sizeof(s_stRfcnSoftwareParam));
+
+ stNnieCfg.pszPic = pcSrcFile;
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.u32MaxInputNum = 1; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 300; // set maxmum 300 ROIs
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core for 0-th Seg
+ stNnieCfg.aenNnieCoreId[1] = SVP_NNIE_ID_0; // set NNIE core for 1-th Seg
+ stNnieCfg.aenNnieCoreId[2] = SVP_NNIE_ID_0; // set NNIE core for 2-th Seg
+ g_stop_signal = HI_FALSE;
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop_File();
+ return;
+ }
+
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stRfcnModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* apcRpnDataLayerName is used to set RPN data layer name
+ and search RPN input data,if user has changed network struct, please
+ make sure the data layer names are correct */
+ s_stRfcnNnieParam.pstModel = &s_stRfcnModel.stModel;
+ s_stRfcnSoftwareParam.apcRpnDataLayerName[0] = "rpn_cls_score";
+ s_stRfcnSoftwareParam.apcRpnDataLayerName[1] = "rpn_bbox_pred";
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop_File();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_ParamInit(&stNnieCfg, &s_stRfcnNnieParam, &s_stRfcnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_ParamInit failed!\n");
+
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop_File();
+ return;
+ }
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stRfcnNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop_File();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Rfcn_Proc(&s_stRfcnNnieParam, &s_stRfcnSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, END_RFCN_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Rfcn_Proc failed!\n");
+
+ /* print result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor */
+
+ SAMPLE_SVP_TRACE_INFO("Rfcn result:\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Rfcn_Stop_File();
+ return;
+ }
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stRfcnSoftwareParam.stDstScore, &s_stRfcnSoftwareParam.stDstRoi,
+ &s_stRfcnSoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+END_RFCN_0:
+
+ SAMPLE_SVP_NNIE_Rfcn_Deinit(&s_stRfcnNnieParam, &s_stRfcnSoftwareParam, &s_stRfcnModel);
+ (HI_VOID)memset_s(&s_stRfcnModel, sizeof(s_stRfcnModel), 0, sizeof(s_stRfcnModel));
+ (HI_VOID)memset_s(&s_stRfcnNnieParam, sizeof(s_stRfcnNnieParam), 0, sizeof(s_stRfcnNnieParam));
+ (HI_VOID)memset_s(&s_stRfcnSoftwareParam, sizeof(s_stRfcnSoftwareParam), 0, sizeof(s_stRfcnSoftwareParam));
+ SAMPLE_COMM_SVP_CheckSysExit();
+
+ return;
+}
+
+/* function : SSD software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Ssd_SoftwareDeinit(SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stPriorBoxTmpBuf.u64PhyAddr != 0) && (pstSoftWareParam->stPriorBoxTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stPriorBoxTmpBuf.u64PhyAddr,
+ pstSoftWareParam->stPriorBoxTmpBuf.u64VirAddr);
+ pstSoftWareParam->stPriorBoxTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stPriorBoxTmpBuf.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Ssd Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Ssd_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Ssd_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Ssd_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Ssd software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Ssd_SoftwareInit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_U32 i = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32TmpBufTotalSize = 0;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* Set Conv Parameters */
+ /* the SSD sample report resule is after permute operation,
+ conv result is (C, H, W), after permute, the report node's
+ (C1, H1, W1) is (H, W, C), the stride of report result is aligned according to C dim */
+ for (i = 0; i < SAMPLE_SVP_NNIE_SSD_REPORT_NODE_NUM; i++) {
+ pstSoftWareParam->au32ConvHeight[i] = pstNnieParam->pstModel->astSeg[0].astDstNode[i].unShape.stWhc.u32Chn;
+ pstSoftWareParam->au32ConvWidth[i] = pstNnieParam->pstModel->astSeg[0].astDstNode[i].unShape.stWhc.u32Height;
+ pstSoftWareParam->au32ConvChannel[i] = pstNnieParam->pstModel->astSeg[0].astDstNode[i].unShape.stWhc.u32Width;
+ if (i % 2 == 1) { // only need to set the odd index parameter
+ pstSoftWareParam->au32ConvStride[i / 2] =
+ SAMPLE_SVP_NNIE_ALIGN16(pstSoftWareParam->au32ConvChannel[i] * sizeof(HI_U32)) / sizeof(HI_U32);
+ }
+ }
+
+ /* Set PriorBox Parameters */
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->au32PriorBoxWidth[0] = 38;
+ pstSoftWareParam->au32PriorBoxWidth[1] = 19;
+ pstSoftWareParam->au32PriorBoxWidth[2] = 10;
+ pstSoftWareParam->au32PriorBoxWidth[3] = 5;
+ pstSoftWareParam->au32PriorBoxWidth[4] = 3;
+ pstSoftWareParam->au32PriorBoxWidth[5] = 1;
+
+ pstSoftWareParam->au32PriorBoxHeight[0] = 38;
+ pstSoftWareParam->au32PriorBoxHeight[1] = 19;
+ pstSoftWareParam->au32PriorBoxHeight[2] = 10;
+ pstSoftWareParam->au32PriorBoxHeight[3] = 5;
+ pstSoftWareParam->au32PriorBoxHeight[4] = 3;
+ pstSoftWareParam->au32PriorBoxHeight[5] = 1;
+
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+
+ pstSoftWareParam->af32PriorBoxMinSize[0][0] = 30.0f;
+ pstSoftWareParam->af32PriorBoxMinSize[1][0] = 60.0f;
+ pstSoftWareParam->af32PriorBoxMinSize[2][0] = 111.0f;
+ pstSoftWareParam->af32PriorBoxMinSize[3][0] = 162.0f;
+ pstSoftWareParam->af32PriorBoxMinSize[4][0] = 213.0f;
+ pstSoftWareParam->af32PriorBoxMinSize[5][0] = 264.0f;
+
+ pstSoftWareParam->af32PriorBoxMaxSize[0][0] = 60.0f;
+ pstSoftWareParam->af32PriorBoxMaxSize[1][0] = 111.0f;
+ pstSoftWareParam->af32PriorBoxMaxSize[2][0] = 162.0f;
+ pstSoftWareParam->af32PriorBoxMaxSize[3][0] = 213.0f;
+ pstSoftWareParam->af32PriorBoxMaxSize[4][0] = 264.0f;
+ pstSoftWareParam->af32PriorBoxMaxSize[5][0] = 315.0f;
+
+ pstSoftWareParam->u32MinSizeNum = 1;
+ pstSoftWareParam->u32MaxSizeNum = 1;
+ pstSoftWareParam->bFlip = HI_TRUE;
+ pstSoftWareParam->bClip = HI_FALSE;
+
+ pstSoftWareParam->au32InputAspectRatioNum[0] = 1;
+ pstSoftWareParam->au32InputAspectRatioNum[1] = 2;
+ pstSoftWareParam->au32InputAspectRatioNum[2] = 2;
+ pstSoftWareParam->au32InputAspectRatioNum[3] = 2;
+ pstSoftWareParam->au32InputAspectRatioNum[4] = 1;
+ pstSoftWareParam->au32InputAspectRatioNum[5] = 1;
+
+ pstSoftWareParam->af32PriorBoxAspectRatio[0][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[0][1] = 0;
+ pstSoftWareParam->af32PriorBoxAspectRatio[1][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[1][1] = 3;
+ pstSoftWareParam->af32PriorBoxAspectRatio[2][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[2][1] = 3;
+ pstSoftWareParam->af32PriorBoxAspectRatio[3][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[3][1] = 3;
+ pstSoftWareParam->af32PriorBoxAspectRatio[4][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[4][1] = 0;
+ pstSoftWareParam->af32PriorBoxAspectRatio[5][0] = 2;
+ pstSoftWareParam->af32PriorBoxAspectRatio[5][1] = 0;
+
+ pstSoftWareParam->af32PriorBoxStepWidth[0] = 8;
+ pstSoftWareParam->af32PriorBoxStepWidth[1] = 16;
+ pstSoftWareParam->af32PriorBoxStepWidth[2] = 32;
+ pstSoftWareParam->af32PriorBoxStepWidth[3] = 64;
+ pstSoftWareParam->af32PriorBoxStepWidth[4] = 100;
+ pstSoftWareParam->af32PriorBoxStepWidth[5] = 300;
+
+ pstSoftWareParam->af32PriorBoxStepHeight[0] = 8;
+ pstSoftWareParam->af32PriorBoxStepHeight[1] = 16;
+ pstSoftWareParam->af32PriorBoxStepHeight[2] = 32;
+ pstSoftWareParam->af32PriorBoxStepHeight[3] = 64;
+ pstSoftWareParam->af32PriorBoxStepHeight[4] = 100;
+ pstSoftWareParam->af32PriorBoxStepHeight[5] = 300;
+
+ pstSoftWareParam->f32Offset = 0.5f;
+
+ pstSoftWareParam->as32PriorBoxVar[0] = (HI_S32)(0.1f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->as32PriorBoxVar[1] = (HI_S32)(0.1f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->as32PriorBoxVar[2] = (HI_S32)(0.2f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->as32PriorBoxVar[3] = (HI_S32)(0.2f * SAMPLE_SVP_NNIE_QUANT_BASE);
+
+ /* Set Softmax Parameters */
+ pstSoftWareParam->u32SoftMaxInHeight = 21;
+ pstSoftWareParam->au32SoftMaxInChn[0] = 121296;
+ pstSoftWareParam->au32SoftMaxInChn[1] = 45486;
+ pstSoftWareParam->au32SoftMaxInChn[2] = 12600;
+ pstSoftWareParam->au32SoftMaxInChn[3] = 3150;
+ pstSoftWareParam->au32SoftMaxInChn[4] = 756;
+ pstSoftWareParam->au32SoftMaxInChn[5] = 84;
+
+ pstSoftWareParam->u32ConcatNum = 6;
+ pstSoftWareParam->u32SoftMaxOutWidth = 1;
+ pstSoftWareParam->u32SoftMaxOutHeight = 21;
+ pstSoftWareParam->u32SoftMaxOutChn = 8732;
+
+ /* Set DetectionOut Parameters */
+ pstSoftWareParam->u32ClassNum = 21;
+ pstSoftWareParam->u32TopK = 400;
+ pstSoftWareParam->u32KeepTopK = 200;
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.3f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32ConfThresh = (HI_U32)(0.000245f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->au32DetectInputChn[0] = 23104;
+ pstSoftWareParam->au32DetectInputChn[1] = 8664;
+ pstSoftWareParam->au32DetectInputChn[2] = 2400;
+ pstSoftWareParam->au32DetectInputChn[3] = 600;
+ pstSoftWareParam->au32DetectInputChn[4] = 144;
+ pstSoftWareParam->au32DetectInputChn[5] = 16;
+
+ /* Malloc assist buffer memory */
+ u32ClassNum = pstSoftWareParam->u32ClassNum;
+ u32TotalSize = SAMPLE_SVP_NNIE_Ssd_GetResultTmpBuf(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32TotalSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, SAMPLE_SVP_NNIE_Ssd_GetResultTmpBuf failed!\n");
+ u32DstRoiSize =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32TopK * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32TopK * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32TotalSize + u32DstRoiSize + u32DstScoreSize + u32ClassRoiNumSize;
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_SSD_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set each tmp buffer addr */
+ pstSoftWareParam->stPriorBoxTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stPriorBoxTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+
+ pstSoftWareParam->stSoftMaxTmpBuf.u64PhyAddr = u64PhyAddr + pstSoftWareParam->stPriorBoxTmpBuf.u32Size;
+ pstSoftWareParam->stSoftMaxTmpBuf.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + pstSoftWareParam->stPriorBoxTmpBuf.u32Size);
+
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr =
+ u64PhyAddr + pstSoftWareParam->stPriorBoxTmpBuf.u32Size + pstSoftWareParam->stSoftMaxTmpBuf.u32Size;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr +
+ pstSoftWareParam->stPriorBoxTmpBuf.u32Size + pstSoftWareParam->stSoftMaxTmpBuf.u32Size);
+
+ u32TmpBufTotalSize = pstSoftWareParam->stPriorBoxTmpBuf.u32Size + pstSoftWareParam->stSoftMaxTmpBuf.u32Size +
+ pstSoftWareParam->stGetResultTmpBuf.u32Size;
+
+ /* set result blob */
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32TmpBufTotalSize);
+ pstSoftWareParam->stDstRoi.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32TopK * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width =
+ u32ClassNum * pstSoftWareParam->u32TopK * SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32TopK * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * pstSoftWareParam->u32TopK;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : Ssd init */
+static HI_S32 SAMPLE_SVP_NNIE_Ssd_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software para */
+ s32Ret = SAMPLE_SVP_NNIE_Ssd_SoftwareInit(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Ssd_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Ssd_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Ssd_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+
+static void SAMPLE_SVP_NNIE_Ssd_Stop(void)
+{
+ SAMPLE_SVP_NNIE_Ssd_Deinit(&s_stSsdNnieParam, &s_stSsdSoftwareParam, &s_stSsdModel);
+ (HI_VOID)memset_s(&s_stSsdNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stSsdSoftwareParam, sizeof(SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stSsdModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show SSD sample(image 300x300 U8_C3) */
+void SAMPLE_SVP_NNIE_Ssd(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/dog_bike_car_300x300.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_ssd_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+ /* Ssd Load model */
+ SAMPLE_SVP_TRACE_INFO("Ssd Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stSsdModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SSD_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* Ssd parameter initialization */
+ /* Ssd parameters are set in SAMPLE_SVP_NNIE_Ssd_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Ssd_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Ssd parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+ s_stSsdNnieParam.pstModel = &s_stSsdModel.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Ssd_ParamInit(&stNnieCfg, &s_stSsdNnieParam, &s_stSsdSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SSD_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Ssd_ParamInit failed!\n");
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Ssd start!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stSsdNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SSD_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stSsdNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SSD_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+ /* software process */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Ssd_GetResult
+ function's input data are correct */
+
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Ssd_GetResult(&s_stSsdNnieParam, &s_stSsdSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, SSD_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Ssd_GetResult failed!\n");
+
+ /* print result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Ssd_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("Ssd result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stSsdSoftwareParam.stDstScore, &s_stSsdSoftwareParam.stDstRoi,
+ &s_stSsdSoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+SSD_FAIL_0:
+ SAMPLE_SVP_NNIE_Ssd_Deinit(&s_stSsdNnieParam, &s_stSsdSoftwareParam, &s_stSsdModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : SSD sample signal handle */
+void SAMPLE_SVP_NNIE_Ssd_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Yolov1 software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov1_SoftwareDeinit(SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr != 0) &&
+ (pstSoftWareParam->stGetResultTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr,
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr);
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = 0;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = 0;
+ pstSoftWareParam->stDstRoi.u64VirAddr = 0;
+ pstSoftWareParam->stDstScore.u64PhyAddr = 0;
+ pstSoftWareParam->stDstScore.u64VirAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Yolov1 Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov1_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Yolov1_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov1_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Yolov1 software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov1_SoftwareInit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32BboxNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32TmpBufTotalSize = 0;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32BboxNumEachGrid = 2;
+ pstSoftWareParam->u32ClassNum = 20;
+ pstSoftWareParam->u32GridNumHeight = 7;
+ pstSoftWareParam->u32GridNumWidth = 7;
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.5f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32ConfThresh = (HI_U32)(0.2f * SAMPLE_SVP_NNIE_QUANT_BASE);
+
+ /* Malloc assist buffer memory */
+ u32ClassNum = pstSoftWareParam->u32ClassNum + 1;
+ u32BboxNum =
+ pstSoftWareParam->u32BboxNumEachGrid * pstSoftWareParam->u32GridNumHeight * pstSoftWareParam->u32GridNumWidth;
+ u32TmpBufTotalSize = SAMPLE_SVP_NNIE_Yolov1_GetResultTmpBuf(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32TmpBufTotalSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, SAMPLE_SVP_NNIE_Yolov1_GetResultTmpBuf failed!\n");
+ u32DstRoiSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32TotalSize + u32DstRoiSize + u32DstScoreSize + u32ClassRoiNumSize + u32TmpBufTotalSize;
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_YOLOV1_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set each tmp buffer addr */
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+
+ /* set result blob */
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32TmpBufTotalSize);
+ pstSoftWareParam->stDstRoi.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width = u32ClassNum * u32BboxNum * SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32TmpBufTotalSize + u32DstRoiSize);
+ pstSoftWareParam->stDstScore.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * u32BboxNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : Yolov1 init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov1_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software para */
+ s32Ret = SAMPLE_SVP_NNIE_Yolov1_SoftwareInit(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov1_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Yolov1_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov1_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+
+static hi_void SAMPLE_SVP_NNIE_Yolov1_Stop(hi_void)
+{
+ SAMPLE_SVP_NNIE_Yolov1_Deinit(&s_stYolov1NnieParam, &s_stYolov1SoftwareParam, &s_stYolov1Model);
+ (HI_VOID)memset_s(&s_stYolov1NnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov1SoftwareParam, sizeof(SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov1Model, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show YOLOV1 sample(image 448x448 U8_C3) */
+void SAMPLE_SVP_NNIE_Yolov1(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/dog_bike_car_448x448.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_yolov1_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ f32PrintResultThresh = 0.3f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+
+ /* Yolov1 Load model */
+ SAMPLE_SVP_TRACE_INFO("Yolov1 Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stYolov1Model);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV1_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* Yolov1 parameter initialization */
+ /* Yolov1 software parameters are set in SAMPLE_SVP_NNIE_Yolov1_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Yolov1_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Yolov1 parameter initialization!\n");
+ s_stYolov1NnieParam.pstModel = &s_stYolov1Model.stModel;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Yolov1_ParamInit(&stNnieCfg, &s_stYolov1NnieParam, &s_stYolov1SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV1_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov1_ParamInit failed!\n");
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Yolov1 start!\n");
+
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stYolov1NnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV1_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ stProcSegIdx.u32SegIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stYolov1NnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV1_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+ /* software process */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Yolov1_GetResult
+ function input data are correct */
+
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Yolov1_GetResult(&s_stYolov1NnieParam, &s_stYolov1SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV1_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov1_GetResult failed!\n");
+
+ /* print result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov1_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("Yolov1 result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stYolov1SoftwareParam.stDstScore, &s_stYolov1SoftwareParam.stDstRoi,
+ &s_stYolov1SoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+YOLOV1_FAIL_0:
+ SAMPLE_SVP_NNIE_Yolov1_Deinit(&s_stYolov1NnieParam, &s_stYolov1SoftwareParam, &s_stYolov1Model);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : Yolov1 sample signal handle */
+void SAMPLE_SVP_NNIE_Yolov1_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/*----------------------------------*/
+/* function : Yolov2 software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov2_SoftwareDeinit(SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr != 0) &&
+ (pstSoftWareParam->stGetResultTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr,
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr);
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = 0;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = 0;
+ pstSoftWareParam->stDstRoi.u64VirAddr = 0;
+ pstSoftWareParam->stDstScore.u64PhyAddr = 0;
+ pstSoftWareParam->stDstScore.u64VirAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Yolov2 Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov2_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov2_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Yolov2 software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov2_SoftwareInit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32BboxNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32TmpBufTotalSize = 0;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32BboxNumEachGrid = 5;
+ pstSoftWareParam->u32ClassNum = 2;
+ pstSoftWareParam->u32GridNumHeight = 13;
+ pstSoftWareParam->u32GridNumWidth = 13;
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.3f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32ConfThresh = (HI_U32)(0.25f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32MaxRoiNum = 10;
+ pstSoftWareParam->af32Bias[0] = 1.08;
+ pstSoftWareParam->af32Bias[1] = 1.19;
+ pstSoftWareParam->af32Bias[2] = 3.42;
+ pstSoftWareParam->af32Bias[3] = 4.41;
+ pstSoftWareParam->af32Bias[4] = 6.63;
+ pstSoftWareParam->af32Bias[5] = 11.38;
+ pstSoftWareParam->af32Bias[6] = 9.42;
+ pstSoftWareParam->af32Bias[7] = 5.11;
+ pstSoftWareParam->af32Bias[8] = 16.62;
+ pstSoftWareParam->af32Bias[9] = 10.52;
+
+ /* Malloc assist buffer memory */
+ u32ClassNum = pstSoftWareParam->u32ClassNum + 1;
+ u32BboxNum =
+ pstSoftWareParam->u32BboxNumEachGrid * pstSoftWareParam->u32GridNumHeight * pstSoftWareParam->u32GridNumWidth;
+ u32TmpBufTotalSize = SAMPLE_SVP_NNIE_Yolov2_GetResultTmpBuf(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32TmpBufTotalSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, SAMPLE_SVP_NNIE_Yolov2_GetResultTmpBuf failed!\n");
+ u32DstRoiSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32TotalSize + u32DstRoiSize + u32DstScoreSize + u32ClassRoiNumSize + u32TmpBufTotalSize;
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_YOLOV2_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set each tmp buffer addr */
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+
+ /* set result blob */
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32TmpBufTotalSize);
+ pstSoftWareParam->stDstRoi.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width = u32ClassNum * u32BboxNum * SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * u32BboxNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr) + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : Yolov1 init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov2_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software para */
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_SoftwareInit(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov2_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov2_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+/*----------------------------------*/
+
+/*=================================*/
+static HI_S32 SampleSvpNnieYolov2SoftwareInit(SAMPLE_SVP_NNIE_CFG_S* pstCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam, SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S* pstSoftWareParam)
+{
+ HI_S32 s32Ret;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32BboxNum;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32DstRoiSize;
+ HI_U32 u32DstScoreSize;
+ HI_U32 u32ClassRoiNumSize;
+ HI_U32 u32TmpBufTotalSize;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8* pu8VirAddr = NULL;
+
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32BboxNumEachGrid = 5; // 5: 2BboxNumEachGrid
+ pstSoftWareParam->u32ClassNum = 2; // 5: class number
+ pstSoftWareParam->u32GridNumHeight = 12; // 12: GridNumHeight
+ pstSoftWareParam->u32GridNumWidth = 20; // 20: GridNumWidth
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.45f*SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32ConfThresh = (HI_U32)(0.4f*SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32MaxRoiNum = 10; // 10: MaxRoiNum
+ pstSoftWareParam->af32Bias[0] = 0.52; // 0.52: af32Bias[0] value
+ pstSoftWareParam->af32Bias[1] = 0.61; // 0.61: af32Bias[1] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_2] = 1.05; // 1.05: af32Bias[ARRAY_SUBSCRIPT_2] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_3] = 1.12; // 1.12: af32Bias[ARRAY_SUBSCRIPT_3] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_4] = 1.85; // 1.85: af32Bias[ARRAY_SUBSCRIPT_4] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_5] = 2.05; // 2.05: af32Bias[ARRAY_SUBSCRIPT_5] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_6] = 4.63; // 4.63: af32Bias[ARRAY_SUBSCRIPT_6] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_7] = 4.49; // 4.49: af32Bias[ARRAY_SUBSCRIPT_7] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_8] = 7.15; // 7.15: af32Bias[ARRAY_SUBSCRIPT_8] value
+ pstSoftWareParam->af32Bias[ARRAY_SUBSCRIPT_9] = 7.56; // 7.56: af32Bias[ARRAY_SUBSCRIPT_9] value
+
+ /*
+ * 申请辅助内存空间
+ * Malloc assist buffer memory
+ */
+ u32ClassNum = pstSoftWareParam->u32ClassNum + 1;
+ u32BboxNum = pstSoftWareParam->u32BboxNumEachGrid*pstSoftWareParam->u32GridNumHeight*
+ pstSoftWareParam->u32GridNumWidth;
+ u32TmpBufTotalSize = SAMPLE_SVP_NNIE_Yolov2_GetResultTmpBuf(pstSoftWareParam);
+ u32DstRoiSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32TotalSize + u32DstRoiSize + u32DstScoreSize + u32ClassRoiNumSize + u32TmpBufTotalSize;
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_YOLOV2_INIT", NULL, (HI_U64*)&u64PhyAddr,
+ (void**)&pu8VirAddr, u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void*)pu8VirAddr, u32TotalSize);
+
+ /*
+ * 设置每个tmp buffer地址
+ * Set each tmp buffer addr
+ */
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = (HI_U64)((HI_UL)pu8VirAddr);
+
+ /*
+ * 设置结果blob
+ * Set result blob
+ */
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr = (HI_U64)((HI_UL)pu8VirAddr + u32TmpBufTotalSize);
+ pstSoftWareParam->stDstRoi.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum *
+ u32BboxNum * sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width = u32ClassNum *
+ u32BboxNum*SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr = (HI_U64)((HI_UL)pu8VirAddr + u32TmpBufTotalSize + u32DstRoiSize);
+ pstSoftWareParam->stDstScore.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * u32BboxNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum*u32BboxNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize +
+ u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = (HI_U64)((HI_UL)pu8VirAddr + u32TmpBufTotalSize +
+ u32DstRoiSize + u32DstScoreSize);
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum*sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+static HI_S32 SampleSvpNnieYolov2SoftwareDeinit(SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S* pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if (pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr != 0 && pstSoftWareParam->stGetResultTmpBuf.u64VirAddr != 0) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr,
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr);
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = 0;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = 0;
+ pstSoftWareParam->stDstRoi.u64VirAddr = 0;
+ pstSoftWareParam->stDstScore.u64PhyAddr = 0;
+ pstSoftWareParam->stDstScore.u64VirAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+static HI_S32 SampleSvpNnieYolov2Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S* pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /*
+ * SAMPLE_SVP_NNIE_PARAM_S参数去初始化
+ * Hardware param deinit
+ */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(HI_SUCCESS != s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /*
+ * SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S参数去初始化
+ * Software deinit
+ */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SampleSvpNnieYolov2SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(HI_SUCCESS != s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SampleSvpNnieYolov2SoftwareDeinit failed!\n");
+ }
+
+ /*
+ * SAMPLE_SVP_NNIE_MODEL_S参数去初始化
+ * Model deinit
+ */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(HI_SUCCESS != s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+static HI_S32 SampleSvpNnieYolov2ParamInit(SAMPLE_SVP_NNIE_CFG_S* pstCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam, SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S* pstSoftWareParam)
+{
+ HI_S32 s32Ret;
+ /*
+ * 初始化hardware参数
+ * Init hardware param
+ */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /*
+ * 初始化software参数
+ * Init software param
+ */
+ s32Ret = SampleSvpNnieYolov2SoftwareInit(pstCfg, pstNnieParam,
+ pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov1_SoftwareInit failed!\n", s32Ret);
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SampleSvpNnieYolov2Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov1_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+/*=================================*/
+
+static void SAMPLE_SVP_NNIE_Yolov2_Stop(void)
+{
+ SAMPLE_SVP_NNIE_Yolov2_Deinit(&s_stYolov2NnieParam, &s_stYolov2SoftwareParam, &s_stYolov2Model);
+ (HI_VOID)memset_s(&s_stYolov2NnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov2SoftwareParam, sizeof(SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov2Model, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show YOLOV2 sample(image 416x416 U8_C3) */
+void SAMPLE_SVP_NNIE_Yolov2(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/2008_001538_640x384.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/resnet18_best_inst.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ f32PrintResultThresh = 0.2f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+
+ /* Yolov2 Load model */
+ SAMPLE_SVP_TRACE_INFO("Yolov2 Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stYolov2Model);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* Yolov2 parameter initialization */
+ /* Yolov2 software parameters are set in SAMPLE_SVP_NNIE_Yolov2_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Yolov2_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Yolov2 parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+ s_stYolov2NnieParam.pstModel = &s_stYolov2Model.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_ParamInit(&stNnieCfg, &s_stYolov2NnieParam, &s_stYolov2SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov2_ParamInit failed!\n");
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Yolov2 start!\n");
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stYolov2NnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ stProcSegIdx.u32SegIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stYolov2NnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* Software process */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Yolov2_GetResult
+ function input data are correct */
+
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_GetResult(&s_stYolov2NnieParam, &s_stYolov2SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov2_GetResult failed!\n");
+
+ /* print result, this sample has 6 classes:
+ class 0:background class 1:Carclass class 2:Vanclass
+ class 3:Truckclass class 4:Pedestrianclass class 5:Cyclist */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov2_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("Yolov2 result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stYolov2SoftwareParam.stDstScore, &s_stYolov2SoftwareParam.stDstRoi,
+ &s_stYolov2SoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+YOLOV2_FAIL_0:
+ SAMPLE_SVP_NNIE_Yolov2_Deinit(&s_stYolov2NnieParam, &s_stYolov2SoftwareParam, &s_stYolov2Model);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : Yolov2 sample signal handle */
+void SAMPLE_SVP_NNIE_Yolov2_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Yolov3 software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov3_SoftwareDeinit(SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr != 0) &&
+ (pstSoftWareParam->stGetResultTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr,
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr);
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = 0;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = 0;
+ pstSoftWareParam->stDstRoi.u64VirAddr = 0;
+ pstSoftWareParam->stDstScore.u64PhyAddr = 0;
+ pstSoftWareParam->stDstScore.u64VirAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = 0;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Yolov3 Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov3_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov3_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Yolov3 software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov3_SoftwareInit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32TmpBufTotalSize = 0;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+ pstSoftWareParam->u32BboxNumEachGrid = 3;
+ pstSoftWareParam->u32ClassNum = 80;
+ pstSoftWareParam->au32GridNumHeight[0] = 13;
+ pstSoftWareParam->au32GridNumHeight[1] = 26;
+ pstSoftWareParam->au32GridNumHeight[2] = 52;
+ pstSoftWareParam->au32GridNumWidth[0] = 13;
+ pstSoftWareParam->au32GridNumWidth[1] = 26;
+ pstSoftWareParam->au32GridNumWidth[2] = 52;
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.3f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32ConfThresh = (HI_U32)(0.5f * SAMPLE_SVP_NNIE_QUANT_BASE);
+ pstSoftWareParam->u32MaxRoiNum = 10;
+ pstSoftWareParam->af32Bias[0][0] = 116;
+ pstSoftWareParam->af32Bias[0][1] = 90;
+ pstSoftWareParam->af32Bias[0][2] = 156;
+ pstSoftWareParam->af32Bias[0][3] = 198;
+ pstSoftWareParam->af32Bias[0][4] = 373;
+ pstSoftWareParam->af32Bias[0][5] = 326;
+ pstSoftWareParam->af32Bias[1][0] = 30;
+ pstSoftWareParam->af32Bias[1][1] = 61;
+ pstSoftWareParam->af32Bias[1][2] = 62;
+ pstSoftWareParam->af32Bias[1][3] = 45;
+ pstSoftWareParam->af32Bias[1][4] = 59;
+ pstSoftWareParam->af32Bias[1][5] = 119;
+ pstSoftWareParam->af32Bias[2][0] = 10;
+ pstSoftWareParam->af32Bias[2][1] = 13;
+ pstSoftWareParam->af32Bias[2][2] = 16;
+ pstSoftWareParam->af32Bias[2][3] = 30;
+ pstSoftWareParam->af32Bias[2][4] = 33;
+ pstSoftWareParam->af32Bias[2][5] = 23;
+
+ /* Malloc assist buffer memory */
+ u32ClassNum = pstSoftWareParam->u32ClassNum + 1;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(SAMPLE_SVP_NNIE_YOLOV3_REPORT_BLOB_NUM != pstNnieParam->pstModel->astSeg[0].u16DstNum,
+ HI_FAILURE, SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,pstNnieParam->pstModel->astSeg[0].u16DstNum(%d) should be %d!\n",
+ pstNnieParam->pstModel->astSeg[0].u16DstNum, SAMPLE_SVP_NNIE_YOLOV3_REPORT_BLOB_NUM);
+ u32TmpBufTotalSize = SAMPLE_SVP_NNIE_Yolov3_GetResultTmpBuf(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32TmpBufTotalSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, SAMPLE_SVP_NNIE_Yolov3_GetResultTmpBuf failed!\n");
+ u32DstRoiSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32) *
+ SAMPLE_SVP_NNIE_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32TotalSize + u32DstRoiSize + u32DstScoreSize + u32ClassRoiNumSize + u32TmpBufTotalSize;
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_YOLOV3_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set each tmp buffer addr */
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr);
+
+ /* set result blob */
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr + u32TmpBufTotalSize);
+ pstSoftWareParam->stDstRoi.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum *
+ sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width =
+ u32ClassNum * pstSoftWareParam->u32MaxRoiNum * SAMPLE_SVP_NNIE_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr + u32TmpBufTotalSize + u32DstRoiSize);
+ pstSoftWareParam->stDstScore.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * pstSoftWareParam->u32MaxRoiNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr =
+ SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64, pu8VirAddr + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize);
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : Yolov3 init */
+static HI_S32 SAMPLE_SVP_NNIE_Yolov3_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software para */
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_SoftwareInit(pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov3_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Yolov3_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+
+static hi_void SAMPLE_SVP_NNIE_Yolov3_Stop(hi_void)
+{
+ SAMPLE_SVP_NNIE_Yolov3_Deinit(&s_stYolov3NnieParam, &s_stYolov3SoftwareParam, &s_stYolov3Model);
+ (HI_VOID)memset_s(&s_stYolov3NnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov3SoftwareParam, sizeof(SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stYolov3Model, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show YOLOV3 sample(image 416x416 U8_C3) */
+void SAMPLE_SVP_NNIE_Yolov3(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/dog_bike_car_416x416.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_yolov3_cycle.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };//初始化结构体
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.u32MaxInputNum = u32PicNum; // max input image num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov3_Stop();
+ return;
+ }
+
+ /* Yolov3 Load model */
+ SAMPLE_SVP_TRACE_INFO("Yolov3 Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stYolov3Model);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV3_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+
+ clock_t start,end;
+ double time_used;
+ start = clock();
+ /* Yolov3 parameter initialization */
+ /* Yolov3 software parameters are set in SAMPLE_SVP_NNIE_Yolov3_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Yolov3_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Yolov3 parameter initialization!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov3_Stop();
+ return;
+ }
+ s_stYolov3NnieParam.pstModel = &s_stYolov3Model.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_ParamInit(&stNnieCfg, &s_stYolov3NnieParam, &s_stYolov3SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV3_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov3_ParamInit failed!\n");
+
+
+ /* Fill src data */
+ SAMPLE_SVP_TRACE_INFO("Yolov3 start!\n");
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov3_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stYolov3NnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV3_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+
+ /* NNIE process(process the 0-th segment) */
+ stProcSegIdx.u32SegIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov3_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stYolov3NnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV3_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* Software process */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Yolov3_GetResult
+ function input data are correct */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Yolov3_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_GetResult(&s_stYolov3NnieParam, &s_stYolov3SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, YOLOV3_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov3_GetResult failed!\n");
+
+ /* print result, this sample has 81 classes:
+ class 0:background class 1:person class 2:bicycle class 3:car class 4:motorbike class
+ 5:aeroplane class 6:bus class 7:train class 8:truck class 9:boat class
+ 10:traffic light class 11:fire hydrant class 12:stop sign class 13:parking meter class 14:bench class
+ 15:bird class 16:cat class 17:dog class 18:horse class 19:sheep class 20:cow
+ class 21:elephant class 22:bear class 23:zebra class 24:giraffe class 25:backpack
+ class 26:umbrella class 27:handbag class 28:tie class 29:suitcase class 30:frisbee
+ class 31:skis class 32:snowboard class 33:sports ball class 34:kite class 35:baseball bat
+ class 36:baseball glove class 37:skateboard class 38:surfboard class 39:tennis racket class 40bottle
+ class 41:wine glass class 42:cup class 43:fork class 44:knife class 45:spoon
+ class 46:bowl class 47:banana class 48:apple class 49:sandwich class 50orange
+ class 51:broccoli class 52:carrot class 53:hot dog class 54:pizza class 55:donut
+ class 56:cake class 57:chair class 58:sofa class 59:pottedplant class 60bed
+ class 61:diningtable class 62:toilet class 63:vmonitor class 64:laptop class 65:mouse
+ class 66:remote class 67:keyboard class 68:cell phone class 69:microwave class 70:oven
+ class 71:toaster class 72:sink class 73:refrigerator class 74:book class 75:clock
+ class 76:vase class 77:scissors class 78:teddy bear class 79:hair drier class 80:toothbrush */
+ SAMPLE_SVP_TRACE_INFO("Yolov3 result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stYolov3SoftwareParam.stDstScore, &s_stYolov3SoftwareParam.stDstRoi,
+ &s_stYolov3SoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+ end = clock();
+ time_used = ((double)(end-start))/CLOCKS_PER_SEC;
+ printf("process time : %f ms\n",time_used/1000);
+
+YOLOV3_FAIL_0:
+ SAMPLE_SVP_NNIE_Yolov3_Deinit(&s_stYolov3NnieParam, &s_stYolov3SoftwareParam, &s_stYolov3Model);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : Yolov3 sample signal handle */
+void SAMPLE_SVP_NNIE_Yolov3_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Lstm Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Lstm_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParamm, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParamm != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParamm);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Lstm init */
+static HI_S32 SAMPLE_SVP_NNIE_Lstm_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstNnieCfg, SAMPLE_SVP_NNIE_PARAM_S *pstLstmPara)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware para */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstNnieCfg, pstLstmPara);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_Lstm_Deinit(pstLstmPara, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Lstm_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+static hi_void SAMPLE_SVP_NNIE_Lstm_Stop(hi_void)
+{
+ SAMPLE_SVP_NNIE_Lstm_Deinit(&s_stLstmNnieParam, &s_stLstmModel);
+ (HI_VOID)memset_s(&s_stLstmNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stLstmModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show Lstm sample(vector) */
+void SAMPLE_SVP_NNIE_Lstm(void)
+{
+ const HI_CHAR *apcSrcFile[3] = {"./data/nnie_image/vector/Seq.SEQ_S32",
+ "./data/nnie_image/vector/Vec1.VEC_S32",
+ "./data/nnie_image/vector/Vec2.VEC_S32"};
+ const HI_CHAR *pchModelName = "./data/nnie_model/recurrent/lstm_3_3.wk";
+ HI_U8 *pu8VirAddr = NULL;
+ HI_U32 u32SegNum = 0;
+ HI_U32 u32Step = 0;
+ HI_U32 u32Offset = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_U32 i = 0, j = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ stNnieCfg.u32MaxInputNum = 16; // max input data num in each batch
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+ u32Step = 20; // time step
+ g_stop_signal = HI_FALSE;
+
+ /* Sys init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Lstm_Stop();
+ return;
+ }
+
+ /* Lstm Load model */
+ SAMPLE_SVP_TRACE_INFO("Lstm Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pchModelName, &s_stLstmModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /* Lstm step initialization */
+ u32SegNum = s_stLstmModel.stModel.u32NetSegNum;
+ u32TotalSize = stNnieCfg.u32MaxInputNum * sizeof(HI_S32) * u32SegNum * 2;
+ s32Ret = SAMPLE_COMM_SVP_MallocMem("SVP_NNIE_STEP", NULL, (HI_U64 *)&s_stLstmNnieParam.stStepBuf.u64PhyAddr,
+ (void **)&pu8VirAddr, u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ /* Get step virtual addr */
+ s_stLstmNnieParam.stStepBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+ for (i = 0; i < u32SegNum * SAMPLE_SVP_NNIE_EACH_SEG_STEP_ADDR_NUM; i++) {
+ stNnieCfg.au64StepVirAddr[i] =
+ s_stLstmNnieParam.stStepBuf.u64VirAddr + i * stNnieCfg.u32MaxInputNum * sizeof(HI_S32);
+ }
+ /* Set step value, in this sample, the step values are set to be 20,
+ if user has changed input network, please set correct step
+ values according to the input network */
+ for (i = 0; i < u32SegNum; i++) {
+ u32Offset = i * SAMPLE_SVP_NNIE_EACH_SEG_STEP_ADDR_NUM;
+ for (j = 0; j < stNnieCfg.u32MaxInputNum; j++) {
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, stNnieCfg.au64StepVirAddr[u32Offset]) + j) =
+ u32Step; // step of input x_t
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, stNnieCfg.au64StepVirAddr[u32Offset + 1]) + j) =
+ u32Step; // step of output h_t
+ }
+ }
+
+ /* Lstm parameter initialization */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Lstm_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("Lstm parameter initialization!\n");
+ s_stLstmNnieParam.pstModel = &(s_stLstmModel.stModel);
+ s32Ret = SAMPLE_SVP_NNIE_Lstm_ParamInit(&stNnieCfg, &s_stLstmNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Lstm_ParamInit failed!\n");
+
+ /* Fill src data, in this sample, the 0-th seg is lstm network,if user has
+ changed input network,please make sure the value of stInputDataIdx.u32SegIdx
+ is correct */
+ SAMPLE_SVP_TRACE_INFO("Lstm start!\n");
+ stInputDataIdx.u32SegIdx = 0;
+ for (i = 0;
+ i < (s_stLstmNnieParam.pstModel->astSeg[stInputDataIdx.u32SegIdx].u16SrcNum) && (g_stop_signal == HI_FALSE);
+ i++) {
+ stNnieCfg.pszPic = apcSrcFile[i];
+ stInputDataIdx.u32NodeIdx = i;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stLstmNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FillSrcData failed!\n");
+ }
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Lstm_Stop();
+ return;
+ }
+
+ /* NNIE process(process the 0-th segment) */
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ stProcSegIdx.u32SegIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stLstmNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* print report result */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Lstm_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_PrintReportResult(&s_stLstmNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, LSTM_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_PrintReportResult failed!\n");
+
+ SAMPLE_SVP_TRACE_INFO("Lstm is successfully processed!\n");
+
+LSTM_FAIL_0:
+ SAMPLE_SVP_NNIE_Lstm_Deinit(&s_stLstmNnieParam, &s_stLstmModel);
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+/* function : Lstm sample signal handle */
+void SAMPLE_SVP_NNIE_Lstm_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/* function : Pavnet software deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Pvanet_SoftwareDeinit(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ SAMPLE_SVP_CHECK_EXPR_RET(pstSoftWareParam == NULL, HI_INVALID_VALUE, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error, pstSoftWareParam can't be NULL!\n");
+ if ((pstSoftWareParam->stRpnTmpBuf.u64PhyAddr != 0) && (pstSoftWareParam->stRpnTmpBuf.u64VirAddr != 0)) {
+ SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stRpnTmpBuf.u64PhyAddr, pstSoftWareParam->stRpnTmpBuf.u64VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = 0;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = 0;
+ }
+ return s32Ret;
+}
+
+/* function : Pvanet Deinit */
+static HI_S32 SAMPLE_SVP_NNIE_Pvanet_Deinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam, SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* hardware deinit */
+ if (pstNnieParam != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
+ }
+ /* software deinit */
+ if (pstSoftWareParam != NULL) {
+ s32Ret = SAMPLE_SVP_NNIE_Pvanet_SoftwareDeinit(pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_FasterRcnn_SoftwareDeinit failed!\n");
+ }
+ /* model deinit */
+ if (pstNnieModel != NULL) {
+ s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
+ SAMPLE_SVP_CHECK_EXPR_TRACE(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
+ }
+ return s32Ret;
+}
+
+/* function : Pvanet software para init */
+static HI_S32 SAMPLE_SVP_NNIE_Pvanet_SoftwareInit(SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
+ SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RpnTmpBufSize = 0;
+ HI_U32 u32RpnBboxBufSize = 0;
+ HI_U32 u32GetResultTmpBufSize = 0;
+ HI_U32 u32DstRoiSize = 0;
+ HI_U32 u32DstScoreSize = 0;
+ HI_U32 u32ClassRoiNumSize = 0;
+ HI_U32 u32ClassNum = 0;
+ HI_U32 u32TotalSize = 0;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U64 u64PhyAddr = 0;
+ HI_U8 *pu8VirAddr = NULL;
+
+ /* RPN parameter init */
+ /* The values of the following parameters are related to algorithm principles.
+ For details, see related algorithms. */
+ pstSoftWareParam->u32MaxRoiNum = pstCfg->u32MaxRoiNum;
+ pstSoftWareParam->u32ClassNum = 21;
+ pstSoftWareParam->u32NumRatioAnchors = 7;
+ pstSoftWareParam->u32NumScaleAnchors = 6;
+ pstSoftWareParam->au32Ratios[0] = (HI_S32)(0.333 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[1] = (HI_S32)(0.5 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[2] = (HI_S32)(0.667 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[3] = (HI_S32)(1 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[4] = (HI_S32)(1.5 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[5] = (HI_S32)(2 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->au32Ratios[6] = (HI_S32)(3 * SAMPLE_SVP_QUANT_BASE);
+
+ pstSoftWareParam->au32Scales[0] = 2 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[1] = 3 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[2] = 5 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[3] = 9 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[4] = 16 * SAMPLE_SVP_QUANT_BASE;
+ pstSoftWareParam->au32Scales[5] = 32 * SAMPLE_SVP_QUANT_BASE;
+
+ /* set origin image height & width from src[0] shape */
+ pstSoftWareParam->u32OriImHeight = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
+ pstSoftWareParam->u32OriImWidth = pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
+
+ pstSoftWareParam->u32MinSize = 16;
+ pstSoftWareParam->u32SpatialScale = (HI_U32)(0.0625 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->u32NmsThresh = (HI_U32)(0.7 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->u32FilterThresh = 0;
+ pstSoftWareParam->u32ValidNmsThresh = (HI_U32)(0.3 * SAMPLE_SVP_QUANT_BASE);
+ pstSoftWareParam->u32NumBeforeNms = 12000;
+ pstSoftWareParam->u32MaxRoiNum = 200;
+
+ for (i = 0; i < pstSoftWareParam->u32ClassNum; i++) {
+ pstSoftWareParam->au32ConfThresh[i] = 1;
+ }
+
+ pstSoftWareParam->stRpnBbox.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height = pstCfg->u32MaxRoiNum;
+ pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Width = SAMPLE_SVP_COORDI_NUM;
+ pstSoftWareParam->stRpnBbox.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(SAMPLE_SVP_COORDI_NUM * sizeof(HI_U32));
+ pstSoftWareParam->stRpnBbox.u32Num = 1;
+ for (i = 0; i < SAMPLE_SVP_NNIE_SEGMENT_NUM; i++) {
+ for (j = 0; j < pstNnieParam->pstModel->astSeg[0].u16DstNum; j++) {
+ if (strncmp(pstNnieParam->pstModel->astSeg[0].astDstNode[j].szName,
+ pstSoftWareParam->apcRpnDataLayerName[i], SVP_NNIE_NODE_NAME_LEN) == 0) {
+ pstSoftWareParam->aps32Conv[i] =
+ SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstNnieParam->astSegData[0].astDst[j].u64VirAddr);
+ pstSoftWareParam->au32ConvHeight[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Height;
+ pstSoftWareParam->au32ConvWidth[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Width;
+ pstSoftWareParam->au32ConvChannel[i] =
+ pstNnieParam->pstModel->astSeg[0].astDstNode[j].unShape.stWhc.u32Chn;
+ break;
+ }
+ }
+ SAMPLE_SVP_CHECK_EXPR_RET((j == pstNnieParam->pstModel->astSeg[0].u16DstNum), HI_FAILURE,
+ SAMPLE_SVP_ERR_LEVEL_ERROR, "Error,failed to find report node %s!\n",
+ pstSoftWareParam->apcRpnDataLayerName[i]);
+ if (i == 0) {
+ pstSoftWareParam->u32ConvStride = pstNnieParam->astSegData[0].astDst[j].u32Stride;
+ }
+ }
+ /* calculate software mem size */
+ u32ClassNum = pstSoftWareParam->u32ClassNum;
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_RpnTmpBufSize(pstSoftWareParam->u32NumRatioAnchors,
+ pstSoftWareParam->u32NumScaleAnchors, pstSoftWareParam->au32ConvHeight[0], pstSoftWareParam->au32ConvWidth[0]);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32RpnTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_RpnTmpBufSize failed!\n");
+ u32RpnTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32RpnTmpBufSize);
+ u32RpnBboxBufSize = pstSoftWareParam->stRpnBbox.u32Num * pstSoftWareParam->stRpnBbox.unShape.stWhc.u32Height *
+ pstSoftWareParam->stRpnBbox.u32Stride;
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_Pvanet_GetResultTmpBufSize(pstCfg->u32MaxRoiNum, u32ClassNum);
+ SAMPLE_SVP_CHECK_EXPR_RET(u32GetResultTmpBufSize == 0, HI_ERR_SVP_NNIE_ILLEGAL_PARAM, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Pvanet_GetResultTmpBufSize failed!\n");
+ u32GetResultTmpBufSize = SAMPLE_SVP_NNIE_ALIGN16(u32GetResultTmpBufSize);
+ u32DstRoiSize =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32) * SAMPLE_SVP_COORDI_NUM);
+ u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstCfg->u32MaxRoiNum * sizeof(HI_U32));
+ u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ u32TotalSize = u32RpnTmpBufSize + u32RpnBboxBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize +
+ u32ClassRoiNumSize;
+
+ /* malloc mem */
+ s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_Pvanet_INIT", NULL, (HI_U64 *)&u64PhyAddr, (void **)&pu8VirAddr,
+ u32TotalSize);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,Malloc memory failed!\n");
+ (HI_VOID)memset_s(pu8VirAddr, u32TotalSize, 0, u32TotalSize);
+ SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
+
+ /* set addr */
+ pstSoftWareParam->stRpnTmpBuf.u64PhyAddr = u64PhyAddr;
+ pstSoftWareParam->stRpnTmpBuf.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr);
+ pstSoftWareParam->stRpnTmpBuf.u32Size = u32RpnTmpBufSize;
+
+ pstSoftWareParam->stRpnBbox.u64PhyAddr = u64PhyAddr + u32RpnTmpBufSize;
+ pstSoftWareParam->stRpnBbox.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr) + u32RpnTmpBufSize;
+
+ pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize;
+ pstSoftWareParam->stGetResultTmpBuf.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize);
+ pstSoftWareParam->stGetResultTmpBuf.u32Size = u32GetResultTmpBufSize;
+
+ pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize;
+ pstSoftWareParam->stDstRoi.u64VirAddr =
+ (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize);
+ pstSoftWareParam->stDstRoi.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32) * SAMPLE_SVP_COORDI_NUM);
+ pstSoftWareParam->stDstRoi.u32Num = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width =
+ u32ClassNum * pstSoftWareParam->u32MaxRoiNum * SAMPLE_SVP_COORDI_NUM;
+
+ pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stDstScore.u64PhyAddr =
+ u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize;
+ pstSoftWareParam->stDstScore.u64VirAddr = (HI_U64)((HI_UINTPTR_T)pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize +
+ u32GetResultTmpBufSize + u32DstRoiSize);
+ pstSoftWareParam->stDstScore.u32Stride =
+ SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
+ pstSoftWareParam->stDstScore.u32Num = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stDstScore.unShape.stWhc.u32Width = u32ClassNum * pstSoftWareParam->u32MaxRoiNum;
+
+ pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
+ pstSoftWareParam->stClassRoiNum.u64PhyAddr =
+ u64PhyAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize;
+ pstSoftWareParam->stClassRoiNum.u64VirAddr = SAMPLE_SVP_NNIE_CONVERT_PTR_TO_ADDR(HI_U64,
+ pu8VirAddr + u32RpnBboxBufSize + u32RpnTmpBufSize + u32GetResultTmpBufSize + u32DstRoiSize + u32DstScoreSize);
+ pstSoftWareParam->stClassRoiNum.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
+ pstSoftWareParam->stClassRoiNum.u32Num = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
+ pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
+
+ return s32Ret;
+}
+
+/* function : Pvanet parameter initialization */
+static HI_S32 SAMPLE_SVP_NNIE_Pvanet_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstFasterRcnnCfg,
+ SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam, SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S *pstSoftWareParam)
+{
+ HI_S32 s32Ret = HI_SUCCESS;
+ /* init hardware parameter */
+ s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstFasterRcnnCfg, pstNnieParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
+
+ /* init software parameter */
+ s32Ret = SAMPLE_SVP_NNIE_Pvanet_SoftwareInit(pstFasterRcnnCfg, pstNnieParam, pstSoftWareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_Pvanet_SoftwareInit failed!\n", s32Ret);
+
+ return s32Ret;
+INIT_FAIL_0:
+ s32Ret = SAMPLE_SVP_NNIE_FasterRcnn_Deinit(pstNnieParam, pstSoftWareParam, NULL);
+ SAMPLE_SVP_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_FasterRcnn_Deinit failed!\n", s32Ret);
+ return HI_FAILURE;
+}
+static hi_void SAMPLE_SVP_NNIE_Pvanet_Stop(hi_void)
+{
+ SAMPLE_SVP_NNIE_FasterRcnn_Deinit(&s_stPvanetNnieParam, &s_stPvanetSoftwareParam, &s_stPvanetModel);
+ (HI_VOID)memset_s(&s_stPvanetNnieParam, sizeof(SAMPLE_SVP_NNIE_PARAM_S), 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ (HI_VOID)memset_s(&s_stPvanetSoftwareParam, sizeof(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S), 0,
+ sizeof(SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S));
+ (HI_VOID)memset_s(&s_stPvanetModel, sizeof(SAMPLE_SVP_NNIE_MODEL_S), 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+ SAMPLE_COMM_SVP_CheckSysExit();
+ printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
+}
+
+/* function : show Pvanet fasterRcnn sample(image 224x224 U8_C3) */
+void SAMPLE_SVP_NNIE_Pvanet(void)
+{
+ const HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/horse_dog_car_person_224x224.bgr";
+ const HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_fasterrcnn_pvanet_inst.wk";
+ const HI_U32 u32PicNum = 1;
+ HI_FLOAT f32PrintResultThresh = 0.0f;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_U32 i = 0;
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = { 0 };
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = { 0 };
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = { 0 };
+
+ /* Set configuration parameter */
+ s_enNetType = SAMPLE_SVP_NNIE_PVANET_FASTER_RCNN;
+ f32PrintResultThresh = 0.8f;
+ stNnieCfg.u32MaxInputNum = u32PicNum;
+ stNnieCfg.u32MaxRoiNum = 200;
+ stNnieCfg.pszPic = pcSrcFile;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0;
+ stNnieCfg.aenNnieCoreId[1] = SVP_NNIE_ID_0;
+ g_stop_signal = HI_FALSE;
+
+ /* Sys_init */
+ s32Ret = SAMPLE_COMM_SVP_CheckSysInit();
+ SAMPLE_SVP_CHECK_EXPR_RET_VOID(s32Ret != HI_SUCCESS, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_CheckSysInit failed!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+
+ /* FasterRcnn Load model */
+ SAMPLE_SVP_TRACE_INFO("Pvanet load Model!!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName, &s_stPvanetModel);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "ERROR, SAMPLE_COMM_SVP_NNIE_LoadModel failed\n");
+
+ /* Pvanet para init */
+ /* apcRpnDataLayerName is used to set RPN data layer name
+ and search RPN input data,if user has changed network struct, please
+ make sure the data layer names are correct */
+ /* Pvanet parameters are set in SAMPLE_SVP_NNIE_Pvanet_SoftwareInit,
+ if user has changed network struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_FasterRcnn_SoftwareInit function are correct */
+ SAMPLE_SVP_TRACE_INFO("Pvanet parameter initialization!\n");
+ s_stPvanetNnieParam.pstModel = &s_stPvanetModel.stModel;
+ s_stPvanetSoftwareParam.apcRpnDataLayerName[0] = "rpn_cls_score";
+ s_stPvanetSoftwareParam.apcRpnDataLayerName[1] = "rpn_bbox_pred";
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Pvanet_ParamInit(&stNnieCfg, &s_stPvanetNnieParam, &s_stPvanetSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Pvanet_ParamInit failed!\n");
+
+ /* Fill 0-th input node of 0-th seg */
+ SAMPLE_SVP_TRACE_INFO("Pvanet start!\n");
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ s32Ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &s_stPvanetNnieParam, &stInputDataIdx);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "ERROR, SAMPLE_SVP_NNIE_FillSrcData Failed!!\n");
+
+ /* NNIE process 0-th seg */
+ stProcSegIdx.u32SegIdx = 0;
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stPvanetNnieParam, &stInputDataIdx, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Forward failed!\n");
+
+ /* Do RPN */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+ s32Ret = SAMPLE_SVP_NNIE_Pvanet_Rpn(&s_stPvanetSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Pvanet_Rpn failed!\n");
+ if (s_stPvanetSoftwareParam.stRpnBbox.unShape.stWhc.u32Height != 0 && g_stop_signal == HI_FALSE) {
+ /* NNIE process 1-th seg, the input conv data comes from 0-th seg's 0-th report node,
+ the input roi comes from RPN results */
+ stInputDataIdx.u32NodeIdx = 0;
+ stInputDataIdx.u32SegIdx = 0;
+ stProcSegIdx.u32SegIdx = 1;
+ s32Ret = SAMPLE_SVP_NNIE_ForwardWithBbox(&s_stPvanetNnieParam, &stInputDataIdx,
+ &s_stPvanetSoftwareParam.stRpnBbox, &stProcSegIdx, HI_TRUE);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_ForwardWithBbox failed!\n");
+
+ /* GetResult */
+ /* if user has changed net struct, please make sure SAMPLE_SVP_NNIE_FasterRcnn_GetResult
+ function's input data are correct */
+ s32Ret = SAMPLE_SVP_NNIE_Pvanet_GetResult(&s_stPvanetNnieParam, &s_stPvanetSoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, PVANET_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "ERROR, SAMPLE_SVP_NNIE_Pvanet_GetResult Failed!\n");
+ } else {
+ for (i = 0; i < s_stPvanetSoftwareParam.stClassRoiNum.unShape.stWhc.u32Width; i++) {
+ *(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_U32, s_stPvanetSoftwareParam.stClassRoiNum.u64VirAddr) + i) = 0;
+ }
+ }
+
+ /* print result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor */
+ if (g_stop_signal == HI_TRUE) {
+ SAMPLE_SVP_NNIE_Pvanet_Stop();
+ return;
+ }
+ SAMPLE_SVP_TRACE_INFO("Pvanet result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stPvanetSoftwareParam.stDstScore, &s_stPvanetSoftwareParam.stDstRoi,
+ &s_stPvanetSoftwareParam.stClassRoiNum, f32PrintResultThresh);
+
+PVANET_FAIL_0:
+ SAMPLE_SVP_NNIE_Pvanet_Deinit(&s_stPvanetNnieParam, &s_stPvanetSoftwareParam, &s_stPvanetModel);
+
+ SAMPLE_COMM_SVP_CheckSysExit();
+}
+
+void SAMPLE_SVP_NNIE_Pvanet_HandleSig(void)
+{
+ g_stop_signal = HI_TRUE;
+}
+
+/******************************************************************************
+* function : roi to rect
+******************************************************************************/
+HI_S32 SAMPLE_SVP_NNIE_RoiToRect_Yolov3(SVP_BLOB_S *pstDstScore,
+ SVP_BLOB_S *pstDstRoi, SVP_BLOB_S *pstClassRoiNum, HI_FLOAT *paf32ScoreThr,
+ HI_BOOL bRmBg,SAMPLE_SVP_NNIE_RECT_ARRAY_S *pstRect,
+ HI_U32 u32SrcWidth, HI_U32 u32SrcHeight,HI_U32 u32DstWidth,HI_U32 u32DstHeight)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RoiNumBias = 0;
+ HI_U32 u32ScoreBias = 0;
+ HI_U32 u32BboxBias = 0;
+ HI_FLOAT f32Score = 0.0f;
+ HI_S32* ps32Score = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstDstScore->u64VirAddr);
+ HI_S32* ps32Roi = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstDstRoi->u64VirAddr);
+ HI_S32* ps32ClassRoiNum = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstClassRoiNum->u64VirAddr);
+ HI_U32 u32ClassNum = pstClassRoiNum->unShape.stWhc.u32Width;
+ HI_U32 u32RoiNumTmp = 0;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(u32ClassNum > 82 ,HI_ERR_SVP_NNIE_ILLEGAL_PARAM,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),u32ClassNum(%u) must be less than or equal %u to!\n",HI_ERR_SVP_NNIE_ILLEGAL_PARAM,u32ClassNum, 82);
+
+
+ pstRect->u32TotalNum = 0;
+ pstRect->u32ClsNum = u32ClassNum;
+ if (bRmBg)
+ {
+ pstRect->au32RoiNum[0] = 0;
+ u32RoiNumBias += ps32ClassRoiNum[0];
+ for (i = 1; i < u32ClassNum; i++)
+ {
+ u32ScoreBias = u32RoiNumBias;
+ u32BboxBias = u32RoiNumBias * SAMPLE_SVP_NNIE_COORDI_NUM;
+ u32RoiNumTmp = 0;
+ /*if the confidence score greater than result thresh, the result will be drawed*/
+ if(((HI_FLOAT)ps32Score[u32ScoreBias] / SAMPLE_SVP_NNIE_QUANT_BASE >=
+ paf32ScoreThr[i]) && (ps32ClassRoiNum[i] != 0))
+ {
+ for (j = 0; j < (HI_U32)ps32ClassRoiNum[i]; j++)
+ {
+ /*Score is descend order*/
+ f32Score = (HI_FLOAT)ps32Score[u32ScoreBias + j] / SAMPLE_SVP_NNIE_QUANT_BASE;
+ if ((f32Score < paf32ScoreThr[i]) || (u32RoiNumTmp >= SAMPLE_SVP_NNIE_MAX_ROI_NUM_OF_CLASS))
+ {
+ break;
+ }
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM] / (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1) ;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 1] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 2]/ (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1);
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32Y = pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y;
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32X = pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 3] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32X = pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32Y = pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y;
+
+ u32RoiNumTmp++;
+ }
+
+ }
+
+ pstRect->au32RoiNum[i] = u32RoiNumTmp;
+ pstRect->u32TotalNum += u32RoiNumTmp;
+ u32RoiNumBias += ps32ClassRoiNum[i];
+ }
+
+ }
+ return HI_SUCCESS;
+}
+
+
+/******************************************************************************
+* function : Yolov3 Procession ViToVo
+******************************************************************************/
+static HI_S32 SAMPLE_SVP_NNIE_Yolov3_Proc_ViToVo(SAMPLE_SVP_NNIE_PARAM_S *pstParam,
+ SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSwParam, VIDEO_FRAME_INFO_S* pstExtFrmInfo,
+ HI_U32 u32BaseWidth,HI_U32 u32BaseHeight)
+{
+ HI_S32 s32Ret = HI_FAILURE;
+ SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = {0};
+ SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = {0};
+
+ stInputDataIdx.u32SegIdx = 0;
+ stInputDataIdx.u32NodeIdx = 0;
+ HI_FLOAT f32PrintResultThresh = 0.8f;
+ /*SP420*/
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64VirAddr = pstExtFrmInfo->stVFrame.u64VirAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64PhyAddr = pstExtFrmInfo->stVFrame.u64PhyAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u32Stride = pstExtFrmInfo->stVFrame.u32Stride[0];
+
+
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stYolov3NnieParam,&stInputDataIdx,&stProcSegIdx,HI_TRUE);
+
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov3_Proc failed!\n");
+ /*draw result, this sample has 21 classes:
+ class 0:background class 1:plane class 2:bicycle
+ class 3:bird class 4:boat class 5:bottle
+ class 6:bus class 7:car class 8:cat
+ class 9:chair class10:cow class11:diningtable
+ class 12:dog class13:horse class14:motorbike
+ class 15:person class16:pottedplant class17:sheep
+ class 18:sofa class19:train class20:tvmonitor*/
+
+ /*Software process*/
+ /*if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Yolov3_GetResult
+ function input datas are correct*/
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_GetResult(&s_stYolov3NnieParam,&s_stYolov3SoftwareParam);
+
+
+ // (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&(pstSwParam->stDstScore), &(pstSwParam->stDstRoi), &(pstSwParam->stClassRoiNum),f32PrintResultThresh);
+
+ SAMPLE_SVP_TRACE_INFO("Yolov3 result:\n");
+ (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stYolov3SoftwareParam.stDstScore,
+ &s_stYolov3SoftwareParam.stDstRoi, &s_stYolov3SoftwareParam.stClassRoiNum,f32PrintResultThresh);
+
+ s32Ret = SAMPLE_SVP_NNIE_RoiToRect_Yolov3(&(pstSwParam->stDstScore),
+ &(pstSwParam->stDstRoi), &(pstSwParam->stClassRoiNum), pstSwParam->af32ScoreThr,HI_TRUE,&(pstSwParam->stRect),
+ pstExtFrmInfo->stVFrame.u32Width, pstExtFrmInfo->stVFrame.u32Height,u32BaseWidth,u32BaseHeight);
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_RoiToRect failed!\n",s32Ret);
+
+ return s32Ret;
+
+}
+/******************************************************************************
+* function : Yolov3 vi to vo thread entry
+******************************************************************************/
+static HI_VOID* SAMPLE_SVP_NNIE_Yolov3_ViToVo_thread(HI_VOID* pArgs)
+{
+ HI_S32 s32Ret;
+ SAMPLE_SVP_NNIE_PARAM_S *pstParam;
+ SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSwParam;
+ VIDEO_FRAME_INFO_S stBaseFrmInfo;
+ VIDEO_FRAME_INFO_S stExtFrmInfo;
+ HI_S32 s32MilliSec = 20000;
+ VO_LAYER voLayer = 0;
+ VO_CHN voChn = 0;
+ HI_S32 s32VpssGrp = 0;
+ HI_S32 as32VpssChn[] = {VPSS_CHN0, VPSS_CHN1};
+
+ pstParam = &s_stYolov3NnieParam;
+ pstSwParam = &s_stYolov3SoftwareParam;
+
+ struct timespec start_time,end_time;
+ float use_time =0;
+
+ while (HI_FALSE == s_bNnieStopSignal)
+ {
+ clock_gettime(CLOCK_REALTIME, &start_time);
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[1], &stExtFrmInfo, s32MilliSec);
+ if(HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
+ s32Ret,s32VpssGrp, as32VpssChn[1]);
+ continue;
+ }
+
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[0], &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, EXT_RELEASE,
+ "Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
+ s32Ret,s32VpssGrp, as32VpssChn[0]);
+
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_Proc_ViToVo(pstParam,pstSwParam, &stExtFrmInfo,
+ stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "Error(%#x),SAMPLE_SVP_NNIE_YOLOV3_Proc failed!\n", s32Ret);
+
+ // SAMPLE_SVP_TRACE_INFO("The Width is %d\n", stExtFrmInfo.stVFrame.u32Width);
+ // SAMPLE_SVP_TRACE_INFO("The Height is %d\n", stExtFrmInfo.stVFrame.u32Height);
+
+
+ //Draw rect
+ s32Ret = SAMPLE_COMM_SVP_NNIE_FillRect(&stBaseFrmInfo, &(pstSwParam->stRect), 0x0000FF00);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "SAMPLE_COMM_SVP_NNIE_FillRect failed, Error(%#x)!\n", s32Ret);
+
+ s32Ret = HI_MPI_VO_SendFrame(voLayer, voChn, &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "HI_MPI_VO_SendFrame failed, Error(%#x)!\n", s32Ret);
+
+ clock_gettime(CLOCK_REALTIME, &end_time);
+ use_time = (float)(end_time.tv_sec - start_time.tv_sec)*1000 + (end_time.tv_nsec - start_time.tv_nsec) / 1000000.0;
+ SAMPLE_SVP_TRACE_INFO("The use time is %f \n", use_time);
+
+
+
+ BASE_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[0], &stBaseFrmInfo);
+ if (HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
+ s32Ret,s32VpssGrp,as32VpssChn[0]);
+ }
+
+ EXT_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[1], &stExtFrmInfo);
+ if (HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
+ s32Ret,s32VpssGrp,as32VpssChn[1]);
+ }
+
+ }
+
+ return HI_NULL;
+}
+/******************************************************************************
+* function : Yolov3 vi to vo real time detection
+******************************************************************************/
+void SAMPLE_SVP_NNIE_Yolov3_Vivo(void)
+{
+ // HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/dog_bike_car_416x416.bgr";
+ HI_CHAR *pcModelName = "./data/nnie_model/detection/inst_yolov3_cycle.wk";
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = {0};
+ SIZE_S stSize;
+ PIC_SIZE_E enSize = PIC_CIF;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_CHAR acThreadName[16] = {0};
+
+
+
+
+ /*Sys init*/
+ SAMPLE_COMM_SVP_CheckSysInit();
+
+ /******************************************
+ step 1: start vi vpss vo
+ ******************************************/
+ s_stYolov3Switch.bVenc = HI_FALSE;
+ s_stYolov3Switch.bVo = HI_TRUE;
+ s32Ret = SAMPLE_COMM_IVE_StartViVpssVencVo_Yolov3(&s_stViConfig,&s_stYolov3Switch,&enSize);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, YOLOV3_FAIL_1,
+ "Error(%#x),SAMPLE_COMM_IVE_StartViVpssVencVo failed!\n", s32Ret);
+
+ s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSize, &stSize);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, YOLOV3_FAIL_1,
+ "Error(%#x),SAMPLE_COMM_SYS_GetPicSize failed!\n", s32Ret);
+
+ stSize.u32Width = 640;
+ stSize.u32Height = 384;
+
+ /******************************************
+ step 2: init NNIE param
+ ******************************************/
+ stNnieCfg.pszPic= NULL;
+ stNnieCfg.u32MaxInputNum = 1;
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0;//set NNIE core
+
+ /*Yolov3 Load model*/
+ SAMPLE_SVP_TRACE_INFO("Yolov3 Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName,&s_stYolov3Model);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret,YOLOV3_FAIL_0,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /*Yolov3 parameter initialization*/
+ /*Yolov3 software parameters are set in SAMPLE_SVP_NNIE_Yolov3_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Yolov3_SoftwareInit function are correct*/
+ SAMPLE_SVP_TRACE_INFO("Yolov3 parameter initialization!\n");
+ s_stYolov3NnieParam.pstModel = &s_stYolov3Model.stModel;
+ s32Ret = SAMPLE_SVP_NNIE_Yolov3_ParamInit(&stNnieCfg,&s_stYolov3NnieParam,&s_stYolov3SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret,YOLOV3_FAIL_0,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov3_ParamInit failed!\n");
+
+ /*Fill src data*/
+ SAMPLE_SVP_TRACE_INFO("Yolov3 start!\n");
+
+
+ s_bNnieStopSignal = HI_FALSE;
+ /******************************************
+ step 3: Create work thread
+ ******************************************/
+ snprintf(acThreadName, 16, "NNIE_ViToVo");
+ prctl(PR_SET_NAME, (unsigned long)acThreadName, 0,0,0);
+ pthread_create(&s_hNnieThread, 0, SAMPLE_SVP_NNIE_Yolov3_ViToVo_thread, NULL);
+ SAMPLE_PAUSE();
+
+ s_bNnieStopSignal = HI_TRUE;
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+
+
+
+YOLOV3_FAIL_1:
+ SAMPLE_SVP_NNIE_Yolov3_Deinit(&s_stYolov3NnieParam,&s_stYolov3SoftwareParam,&s_stYolov3Model);
+
+YOLOV3_FAIL_0:
+ SAMPLE_COMM_IVE_StopViVpssVencVo_Yolov3(&s_stViConfig,&s_stYolov3Switch);
+
+}
+
+void SAMPLE_SVP_NNIE_Yolov3_Vivo_HandleSig(void)
+{
+ s_bNnieStopSignal = HI_TRUE;
+ if (0 != s_hNnieThread)
+ {
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+ }
+
+ SAMPLE_SVP_NNIE_Yolov3_Deinit(&s_stYolov3NnieParam,&s_stYolov3SoftwareParam,&s_stYolov3Model);
+ memset(&s_stYolov3NnieParam,0,sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ memset(&s_stYolov3SoftwareParam,0,sizeof(SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S));
+ memset(&s_stYolov3Model,0,sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+
+ SAMPLE_COMM_IVE_StopViVpssVencVo_Yolov3(&s_stViConfig,&s_stYolov3Switch);
+
+}
+
+
+#define Net_FRM_WIDTH 640
+#define Net_FRM_HEIGHT 384
+/*===========================================================================*/
+/******************************************************************************
+* function : roi to rect Yolov2
+******************************************************************************/
+HI_S32 SAMPLE_SVP_NNIE_RoiToRect_Yolov2(SVP_BLOB_S *pstDstScore,
+ SVP_BLOB_S *pstDstRoi, SVP_BLOB_S *pstClassRoiNum, HI_FLOAT *paf32ScoreThr,
+ HI_BOOL bRmBg,SAMPLE_SVP_NNIE_RECT_ARRAY_S *pstRect,
+ HI_U32 u32SrcWidth, HI_U32 u32SrcHeight,HI_U32 u32DstWidth,HI_U32 u32DstHeight)
+{
+ HI_U32 i = 0, j = 0;
+ HI_U32 u32RoiNumBias = 0;
+ HI_U32 u32ScoreBias = 0;
+ HI_U32 u32BboxBias = 0;
+ HI_FLOAT f32Score = 0.0f;
+ HI_S32* ps32Score = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstDstScore->u64VirAddr);
+ HI_S32* ps32Roi = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstDstRoi->u64VirAddr);
+ HI_S32* ps32ClassRoiNum = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32,pstClassRoiNum->u64VirAddr);
+ HI_U32 u32ClassNum = pstClassRoiNum->unShape.stWhc.u32Width;
+ HI_U32 u32RoiNumTmp = 0;
+
+ SAMPLE_SVP_CHECK_EXPR_RET(u32ClassNum > 4 ,HI_ERR_SVP_NNIE_ILLEGAL_PARAM,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),u32ClassNum(%u) must be less than or equal %u to!\n",HI_ERR_SVP_NNIE_ILLEGAL_PARAM,u32ClassNum, 4);
+
+
+ pstRect->u32TotalNum = 0;
+ pstRect->u32ClsNum = u32ClassNum;
+ if (bRmBg)
+ {
+ pstRect->au32RoiNum[0] = 0;
+ u32RoiNumBias += ps32ClassRoiNum[0];
+ for (i = 1; i < u32ClassNum; i++)
+ {
+ u32ScoreBias = u32RoiNumBias;
+ u32BboxBias = u32RoiNumBias * SAMPLE_SVP_NNIE_COORDI_NUM;
+ u32RoiNumTmp = 0;
+ /*if the confidence score greater than result thresh, the result will be drawed*/
+ if(((HI_FLOAT)ps32Score[u32ScoreBias] / SAMPLE_SVP_NNIE_QUANT_BASE >=
+ paf32ScoreThr[i]) && (ps32ClassRoiNum[i] != 0))
+ {
+ for (j = 0; j < (HI_U32)ps32ClassRoiNum[i]; j++)
+ {
+ /*Score is descend order*/
+ f32Score = (HI_FLOAT)ps32Score[u32ScoreBias + j] / SAMPLE_SVP_NNIE_QUANT_BASE;
+ if ((f32Score < paf32ScoreThr[i]) || (u32RoiNumTmp >= SAMPLE_SVP_NNIE_MAX_ROI_NUM_OF_CLASS))
+ {
+ break;
+ }
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM] / (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1) ;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 1] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 2]/ (HI_FLOAT)u32SrcWidth * (HI_FLOAT)u32DstWidth) & (~1);
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32Y = pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32Y;
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32X = pstRect->astRect[i][u32RoiNumTmp].astPoint[1].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y = (HI_U32)((HI_FLOAT)ps32Roi[u32BboxBias + j*SAMPLE_SVP_NNIE_COORDI_NUM + 3] / (HI_FLOAT)u32SrcHeight * (HI_FLOAT)u32DstHeight) & (~1);
+
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32X = pstRect->astRect[i][u32RoiNumTmp].astPoint[0].s32X;
+ pstRect->astRect[i][u32RoiNumTmp].astPoint[3].s32Y = pstRect->astRect[i][u32RoiNumTmp].astPoint[2].s32Y;
+
+ u32RoiNumTmp++;
+ }
+
+ }
+
+ pstRect->au32RoiNum[i] = u32RoiNumTmp;
+ pstRect->u32TotalNum += u32RoiNumTmp;
+ u32RoiNumBias += ps32ClassRoiNum[i];
+ }
+
+ }
+ return HI_SUCCESS;
+}
+
+#define FOCUS_LEN 25
+#define FOCUS_THRESH 12
+#define MISS_THRESH 3
+#define TRACK_TRESH 3
+#define MATCH_THRESH 0.4
+#define BUF_LEN 80
+
+typedef struct TRACK_ID {
+ // RectBox box_prev;
+ //Yolo2FetchRes得到的resBuf相当于current时刻的box,PERSON_ID中的box_curr相当于上一帧的box,所以不需要box_prev这个变量了
+ RectBox box_curr;
+ // HI_U32 cls_arr[FOCUS_LEN];
+ int cls;
+ HI_U32 box_ID;
+ HI_U32 miss_hits;
+ HI_BOOL matched_flag;
+ HI_U32 tracked_count;
+ HI_BOOL tracked_flag;
+ float focused_time[FOCUS_LEN]; //循环利用
+ float focused_time_total;
+ float live_time;
+ HI_BOOL accumulate_first_flag;
+} PERSON_ID;
+
+//这么写会重复累加,导致统计的注意力时长大于实际的
+// HI_VOID Accumulate_Focused_Time(float focused_time[], int len)
+// {
+// int i;
+// int focused_count=0;
+// float sum=0;
+// //static HI_U32 focused_time_total=0;
+// for(i=0;i0){
+// sum+=focused_time[i];
+// focused_count++;
+// }
+// }
+// if(focused_count>=FOCUS_THRESH)
+// focused_time_total+=sum;
+// }
+
+//应该对每一个ID维护一个accumulate_first_flag的标志,否则会造成统计的注意力时长偏小
+// HI_VOID Accumulate_Focused_Time(float focused_time[], int len, int frame_curr)
+// {
+// int i;
+// int focused_count=0;
+// if(accumulate_first_flag==HI_FALSE){
+// float sum=0;
+// for(i=0;i0){
+// sum+=focused_time[i];
+// focused_count++;
+// }
+// }
+// if(focused_count>=FOCUS_THRESH)
+// focused_time_total+=sum;
+// accumulate_first_flag=HI_TRUE;
+// }
+// else{
+// for(i=0;i0)
+// focused_count++;
+// if(focused_count>=FOCUS_THRESH)
+// focused_time_total+=focused_time[frame_curr];
+// }
+// }
+
+// HI_VOID Accumulate_Focused_Time(PERSON_ID *ID, int len, int frame_curr, float live_time_tmp)
+HI_VOID Accumulate_Focused_Time(PERSON_ID *ID, int len, int frame_curr)
+{
+ int i;
+ int focused_count=0;
+ if(ID->accumulate_first_flag==HI_FALSE){
+ float sum=0;
+ for(i=0;ifocused_time[i]>0){
+ sum+=ID->focused_time[i];
+ focused_count++;
+ }
+ }
+ if(focused_count>=FOCUS_THRESH){
+ focused_time_total+=sum;
+ ID->focused_time_total+=sum;
+ ID->accumulate_first_flag=HI_TRUE;
+ }
+ }
+ else{
+ for(i=0;ifocused_time[i]>0)
+ focused_count++;
+ if(focused_count>=FOCUS_THRESH){
+ focused_time_total+=ID->focused_time[frame_curr];
+ ID->focused_time_total+=ID->focused_time[frame_curr];
+ }
+ }
+ // ID->live_time += live_time_tmp;
+}
+
+HI_DOUBLE Track_Yolov2_Iou(RectBox *box1, RectBox *box2)
+{
+ HI_FLOAT f32InterWidth = 0.0;
+ HI_FLOAT f32InterHeight = 0.0;
+ HI_DOUBLE f64InterArea = 0.0;
+ HI_DOUBLE f64Box1Area = 0.0;
+ HI_DOUBLE f64Box2Area = 0.0;
+ HI_DOUBLE f64UnionArea = 0.0;
+
+ f32InterWidth = (HI_FLOAT)(SAMPLE_SVP_NNIE_MIN(box1->xmax,box2->xmax)-SAMPLE_SVP_NNIE_MAX(box1->xmin,box2->xmin));
+ f32InterHeight = (HI_FLOAT)(SAMPLE_SVP_NNIE_MIN(box1->ymax,box2->ymax)-SAMPLE_SVP_NNIE_MAX(box1->ymin,box2->ymin));
+ if (f32InterWidth <= 0 || f32InterHeight <= 0)
+ return 0;
+
+ f64InterArea = f32InterWidth * f32InterHeight;
+ f64Box1Area = (HI_DOUBLE)((box1->xmax - box1->xmin) * (box1->ymax - box1->ymin));
+ f64Box2Area = (HI_DOUBLE)((box2->xmax - box2->xmin) * (box2->ymax - box2->ymin));
+ f64UnionArea = f64Box1Area + f64Box2Area - f64InterArea;
+
+ return f64InterArea / f64UnionArea;
+}
+
+/*
+参数初始化放在SAMPLE_SVP_NNIE_Yolov2_ViToVo_thread()函数的前面
+注意:刚开始跟踪时box_prev为空
+对每一帧进行跟踪时,都将matched_flag置为False
+
+匹配成功:
+1、box_prev与box_curr两两之间计算IOU,匹配最大的那个,视为同一个目标ID,置其matched_flag为True
+匹配失败:
+2、漏检,不更新box_curr,miss_hits+=1,连续超过3帧漏检(miss_hits>3)则丢弃该目标ID,否则将miss_hits清零
+3、新增目标ID
+*/
+
+//resBuf把box信息传给ID_arr
+int Trivial_Track_Yolov2(DetectObjInfo resBuf[], int resLen, float usedTime, PERSON_ID ID_arr[], int prevBoxNum, HI_U32 frame, HI_FLOAT *AD_attractiveness_tmp)
+{
+ int i,j;
+ int frame_tmp=frame%FOCUS_LEN;
+ int box_curr_num=0;
+ // RectBox *box_tmp;
+ HI_DOUBLE max_IOU;
+ HI_DOUBLE IOU_tmp;
+ HI_BOOL matched_flag[DETECT_OBJ_MAX]={0};
+ int max_idx;
+ // HI_BOOL all_matched_flag;
+ //static HI_U32 ID_num_total=0; //被跟踪的总人数
+
+ //算法刚开始运行的第一帧或前面一帧没有目标(要么一直没有目标,要么目标因为恰好消失或漏检次数超过阈值而丢弃)的情况,不需要考虑box_prev,不需要进行IOU匹配
+ //前一帧prevBoxNum==0的情况说明当前帧的框都是新增的!所以根本没必要累积注意力时长
+ if (prevBoxNum==0){
+ for(i=0;ixmin = resBuf[i].box.xmin;
+ // box_tmp->ymin = resBuf[i].box.ymin;
+ // box_tmp->xmax = resBuf[i].box.xmax;
+ // box_tmp->ymax = resBuf[i].box.ymax;
+ ID_arr[i].box_curr=resBuf[i].box;
+ // ID_arr[i].box_ID = ID_num_total;
+ // ID_num_total++;
+ ID_arr[i].cls=resBuf[i].cls;
+ ID_arr[i].miss_hits=0;
+ // if(ID_arr[i].tracked_flag==HI_FALSE)
+ ID_arr[i].tracked_count=1;
+ ID_arr[i].tracked_flag=HI_FALSE;
+ ID_arr[i].focused_time_total=0;
+ ID_arr[i].live_time=usedTime;
+ ID_arr[i].accumulate_first_flag=HI_FALSE;
+ if(resBuf[i].cls==2){
+ ID_arr[i].focused_time[frame_tmp] = usedTime;
+ }
+ // else if (resBuf[i].cls==1){
+ else{
+ ID_arr[i].focused_time[frame_tmp] = 0;
+ }
+ // printf("boxcurr(%d,%d,%d,%d),ID:%d,cls%d,hitmiss%d",ID_arr[i].box_curr.xmin,ID_arr[i].box_curr.ymin,ID_arr[i].box_curr.xmax,
+ // ID_arr[i].box_curr.ymax,ID_arr[i].box_ID,ID_arr[i].cls,ID_arr[i].miss_hits);
+ // if(frame>1 && ID_arr[i].tracked_flag==HI_TRUE) //第一帧不需要累积注意力时长
+ // Accumulate_Focused_Time(ID_arr[i].focused_time,FOCUS_LEN,frame_tmp);
+ }
+ prevBoxNum = resLen;
+ }
+ else if (prevBoxNum>0)
+ {
+ //matched_flag初始化为False
+ for(i=0;iprevBoxNum: 丢失的目标数<新增的目标数(新进入画面或者连续超过3帧漏检)
+ //resLen==prevBoxNum: 刚好匹配;丢失的目标数==新增的目标数
+ //resLen新增的目标数
+ for(i=0;imax_IOU){
+ max_IOU=IOU_tmp;
+ max_idx=j;
+ }
+ }
+ }
+ //匹配成功
+ if(max_IOU>MATCH_THRESH){
+ matched_flag[max_idx]=HI_TRUE;
+ // ID_arr[i].box_prev=ID_arr[i].box_curr;
+ ID_arr[i].box_curr=resBuf[max_idx].box;
+ ID_arr[i].miss_hits=0;
+ ID_arr[i].matched_flag=HI_TRUE;
+ ID_arr[i].cls=resBuf[max_idx].cls;
+ if(resBuf[max_idx].cls==2)
+ ID_arr[i].focused_time[frame_tmp] = usedTime;
+ else if(resBuf[max_idx].cls==1)
+ ID_arr[i].focused_time[frame_tmp] = 0;
+ ID_arr[i].live_time += usedTime;
+ if(ID_arr[i].cls == 1 || ID_arr[i].cls ==2){
+ if(ID_arr[i].tracked_flag==HI_FALSE){
+ if(ID_arr[i].tracked_count<=TRACK_TRESH){
+ ID_arr[i].tracked_count++;
+ if(ID_arr[i].tracked_count>TRACK_TRESH){
+ ID_arr[i].tracked_flag=HI_TRUE;
+ ID_arr[i].box_ID = ID_num_total;
+ ID_num_total++;
+ }
+ }
+ }
+ }
+ }
+ }
+ //分三种情况来考虑,好像没必要
+ // if(prevBoxNum>resLen){
+ // for(i=0;iMISS_THRESH){
+ if(ID_arr[i].miss_hits>MISS_THRESH){
+ if(ID_arr[i].tracked_flag==HI_TRUE)
+ *AD_attractiveness_tmp=*AD_attractiveness_tmp + ID_arr[i].focused_time_total/ID_arr[i].live_time;
+ for(j=i;j New Unconfirmed Tracks
+ for(i=0;iastSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64VirAddr = pstExtFrmInfo->stVFrame.u64VirAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u64PhyAddr = pstExtFrmInfo->stVFrame.u64PhyAddr[0];
+ pstParam->astSegData[stInputDataIdx.u32SegIdx].astSrc[stInputDataIdx.u32NodeIdx].u32Stride = pstExtFrmInfo->stVFrame.u32Stride[0];
+
+
+ s32Ret = SAMPLE_SVP_NNIE_Forward(&s_stYolov2NnieParam,&stInputDataIdx,&stProcSegIdx,HI_TRUE);
+
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_SVP_NNIE_Yolov2_Proc failed!\n");
+ /*draw result, this sample has 3 classes:
+ class 0:background class 1:focused class 2:unfocused
+*/
+
+
+ /*Software process*/
+ /*if user has changed net struct, please make sure SAMPLE_SVP_NNIE_Yolov2_GetResult
+ function input datas are correct*/
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_GetResult(&s_stYolov2NnieParam,&s_stYolov2SoftwareParam);
+ //这一步把归一化的xywh转成s_stYolov2SoftwareParam.stDstRoi的xyxy了
+
+ // SAMPLE_SVP_TRACE_INFO("Yolov2 result:\n");
+ // (void)SAMPLE_SVP_NNIE_Detection_PrintResult(&s_stYolov2SoftwareParam.stDstScore,
+ // &s_stYolov2SoftwareParam.stDstRoi, &s_stYolov2SoftwareParam.stClassRoiNum,f32PrintResultThresh);
+
+ s32Ret = SAMPLE_SVP_NNIE_RoiToRect_Yolov2(&(pstSwParam->stDstScore),
+ &(pstSwParam->stDstRoi), &(pstSwParam->stClassRoiNum), pstSwParam->af32ScoreThr,HI_TRUE,&(pstSwParam->stRect),
+ pstExtFrmInfo->stVFrame.u32Width, pstExtFrmInfo->stVFrame.u32Height,u32BaseWidth,u32BaseHeight);
+ SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error(%#x),SAMPLE_SVP_NNIE_RoiToRect failed!\n",s32Ret);
+
+ //主要作用是把检测框的信息转为DetectObjInfo的格式,并且对低于置信度阈值的框进行了进一步过滤
+ Yolo2FetchRes(&s_stYolov2SoftwareParam.stDstScore,
+ &s_stYolov2SoftwareParam.stDstRoi, &s_stYolov2SoftwareParam.stClassRoiNum, resBuf, resSize, resLen);
+
+ return s32Ret;
+
+}
+/******************************************************************************
+* function : Yolov2 vi to vo thread entry
+******************************************************************************/
+static HI_VOID* SAMPLE_SVP_NNIE_Yolov2_ViToVo_thread(HI_VOID* pArgs)
+{
+ HI_S32 s32Ret;
+ SAMPLE_SVP_NNIE_PARAM_S *pstParam;
+ SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S *pstSwParam;
+ VIDEO_FRAME_INFO_S stBaseFrmInfo;
+ VIDEO_FRAME_INFO_S stExtFrmInfo;
+ HI_S32 s32MilliSec = 20000;
+ VO_LAYER voLayer = 0;
+ VO_CHN voChn = 0;
+ HI_S32 s32VpssGrp = 0;
+ HI_S32 as32VpssChn[] = {VPSS_CHN0, VPSS_CHN1};
+
+ pstParam = &s_stYolov2NnieParam;
+ pstSwParam = &s_stYolov2SoftwareParam;
+
+ struct timespec start_time,end_time;
+ float use_time =0;
+
+ OsdSet *osds;
+ osds = OsdsCreate(HI_OSD_BINDMOD_VPSS, s32VpssGrp, as32VpssChn[0]);
+ s32Ret = OsdLibInit();
+ g_osdsPerson = osds;
+ HI_ASSERT(g_osdsPerson);
+ g_osd0Person = OsdsCreateRgn(g_osdsPerson);
+ HI_ASSERT(g_osd0Person >= 0);
+ memset_s(g_osd_Person_ID, sizeof(HI_S32)*DETECT_OBJ_MAX, -1, sizeof(HI_S32)*DETECT_OBJ_MAX); //或用0xFF
+
+ for(int i=0; i=0);
+ }
+
+ PERSON_ID personID[DETECT_OBJ_MAX] = {0};
+ SORT_ID sortID[DETECT_OBJ_MAX] = {0};
+ int prev_box_num=0;
+ // int max_ID_num=-1;
+ int prev_rgn_num=0;
+ //static HI_U32 focused_time_total=0;
+ //static HI_U32 ID_num_total=0; //被跟踪的总人数
+ HI_U32 frame=0; //从0计起
+ //广告吸引度
+ HI_FLOAT AD_attractiveness_total=0; //AD_attractiveness_dead_ID + 当前帧ID累计得到的吸引度
+ HI_FLOAT AD_attractiveness_dead_ID=0;//已经丢失的ID的AD_attractiveness_total
+ HI_FLOAT AD_attractiveness_mean=0; //对ID总数做平均,AD_attractiveness_total/ID_num_total
+ //AD_attractiveness_mean即对每个ID做平均的广告吸引度,其值域应为[0,1]
+
+ static HI_CHAR prevOsd[BUF_LEN];
+ HI_OSD_ATTR_S rgn;
+ HI_OSD_ATTR_S rgn_ID[DETECT_OBJ_MAX]={0};
+ int x_ID, y_ID;
+ HI_S32 offset = 0;
+ HI_CHAR osdBuf[BUF_LEN] = "";
+ HI_S32 offset_box=0;
+ HI_CHAR osdBuf_box[BUF_LEN] = "";
+
+ /*udp*/
+ // struct sockaddr_in s;
+ // int sock;
+ // char buffsend[512];
+ // char buffrecive[512];
+ // //协议:IPv4、IPv6
+ // //PF_INET PF_INET6
+ // //SOCK_DGRAM 无连接的
+ // //SOCK_STREAM TCP 面向连接的
+ // if((sock = socket(AF_INET,SOCK_DGRAM,0))==-1){
+ // perror("error");
+ // }
+
+ // memset(&s,0,sizeof(s));
+ // s.sin_family = AF_INET;
+ // s.sin_port = htons(8888);
+ // //pc端口
+ // //s.sin_addr.s_addr = inet_addr("192.168.200.1");
+ // //手机端口
+ // s.sin_addr.s_addr = inet_addr("192.168.12.2");
+ // memset(buffsend,0,sizeof(buffsend));
+ // /*udp*/
+
+ while (HI_FALSE == s_bNnieStopSignal)
+ {
+ offset=0;
+ // offset_box=0;
+ memset_s(osdBuf,BUF_LEN,0,BUF_LEN);
+ memset_s(osdBuf_box,BUF_LEN,0,BUF_LEN);
+
+ // for(int i=0; i<5; i++){
+ // g_osd_Person_ID[i] = OsdsCreateRgn(g_osdsPerson);
+ // HI_ASSERT(g_osd_Person_ID[i]>=0);
+ // }
+
+ clock_gettime(CLOCK_REALTIME, &start_time);
+
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[1], &stExtFrmInfo, s32MilliSec);
+ if(HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
+ s32Ret,s32VpssGrp, as32VpssChn[1]);
+ continue;
+ }
+
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[0], &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, EXT_RELEASE,
+ "Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
+ s32Ret,s32VpssGrp, as32VpssChn[0]);
+
+ VIDEO_FRAME_INFO_S resizeFrm;
+ s32Ret = MppFrmResize(&stExtFrmInfo, &resizeFrm, Net_FRM_WIDTH, Net_FRM_HEIGHT);
+ int objNum;
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_Proc_ViToVo(pstParam,pstSwParam, &resizeFrm,
+ stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height,objs,DETECT_OBJ_MAX, &objNum);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "Error(%#x),SAMPLE_SVP_NNIE_YOLOV2_Proc failed!\n", s32Ret);
+
+ HI_U32 FocuseNum = 0;
+ HI_U32 UnfocuseNum = 0;
+
+ clock_gettime(CLOCK_REALTIME, &end_time);
+ //单位是毫秒,hyc把这部分移到SendFrame前面了,因为Track要统计时间,统计的ID要显示在画面中
+ use_time = (float)(end_time.tv_sec - start_time.tv_sec)*1000 + (end_time.tv_nsec - start_time.tv_nsec) / 1000000.0;
+ //SAMPLE_SVP_TRACE_INFO("The use time is %f ms\n", use_time);
+
+ // prev_box_num = Trivial_Track_Yolov2(objs, objNum, use_time, personID, prev_box_num, frame, &AD_attractiveness_dead_ID);
+ prev_box_num = Sort_Track_Yolov2(objs, objNum, use_time, sortID, DETECT_OBJ_MAX, prev_box_num, frame, &AD_attractiveness_dead_ID);
+ frame++;
+
+ //实验发现会出现cls=0的情况,必须手动把它排除掉
+ //Draw rects; display ID number; print info for debugging
+ AD_attractiveness_total=AD_attractiveness_dead_ID;
+ printf("dead: %f\n", AD_attractiveness_total);
+ for (int i = 0; i < prev_box_num; i++) {
+ // RectBox box = personID[i].box_curr;
+ RectBox box = sortID[i].box;
+ RectBoxTran(&box, Net_FRM_WIDTH, Net_FRM_HEIGHT,stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height);
+ //SAMPLE_PRT("yolo2_out_track: box{%d, %d, %d, %d} \n class: %d\n miss_hits:%d,\n box_ID:%d,\n matched_flag:%d,\n tracked_count:%d,focuesed_time[%f,%f,%f,%f,%f,%f]",
+ //box.xmin, box.ymin, box.xmax, box.ymax, personID[i].cls, personID[i].miss_hits, personID[i].box_ID, personID[i].matched_flag,
+ // personID[i].tracked_count,personID[i].focused_time[0],personID[i].focused_time[1],personID[i].focused_time[2],personID[i].focused_time[3],personID[i].focused_time[4],personID[i].focused_time[5]);
+ //因为验证而打印的部分后续可以删了:包括SAMPLE_PRT、printf、HI_ASSERT
+ // boxs[i] = box;
+ remainingBoxs[0] = box;
+ // BoxsIDprint[i] = box;
+ memset_s(osdBuf_box,BUF_LEN,0,BUF_LEN);
+ offset_box=0;
+ if(sortID[i].cls == 1){
+ UnfocuseNum++;
+ MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_GREEN, DRAW_RETC_THICK);
+ offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ "%u ", sortID[i].ID);
+ // offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ // "Unfocused");
+ HI_ASSERT(offset_box < sizeof(osdBuf_box));
+ x_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((box.xmin)/2)*2,0),stBaseFrmInfo.stVFrame.u32Width- 1 - 120);
+ y_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((box.ymin)/2)*2-40,0),stBaseFrmInfo.stVFrame.u32Height - 1 - 40);
+ TxtRgnInit(&rgn_ID[i], osdBuf_box, x_ID, y_ID, ARGB1555_BLUE);
+ OsdsSetRgn(g_osdsPerson, g_osd_Person_ID[i], &rgn_ID[i]);
+ }
+ else if(sortID[i].cls == 2){
+ FocuseNum++;
+ MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_GREEN, DRAW_RETC_THICK);
+ offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ "%u ", sortID[i].ID);
+ // offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ // "Focused");
+ HI_ASSERT(offset_box < sizeof(osdBuf_box));
+ x_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((box.xmin)/2)*2,0),stBaseFrmInfo.stVFrame.u32Width - 1 - 120);
+ y_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((box.ymin)/2)*2-40,0),stBaseFrmInfo.stVFrame.u32Height - 1 - 40);
+ TxtRgnInit(&rgn_ID[i], osdBuf_box, x_ID, y_ID, ARGB1555_BLUE);
+ OsdsSetRgn(g_osdsPerson, g_osd_Person_ID[i], &rgn_ID[i]);
+ }
+ AD_attractiveness_total += sortID[i].focused_time_total/sortID[i].live_time;
+ printf("live id: %d, class: %d, total_focused_time: %f, live_time: %f\n", sortID[i].ID, sortID[i].cls,
+ sortID[i].focused_time_total, sortID[i].live_time);
+ }
+ for(int i=prev_box_num;i>>g_osd_person_ID[%d]:%d\n",i,g_osd_Person_ID[i]);
+ }
+ prev_rgn_num=prev_box_num;
+
+ MppFrmDestroy(&resizeFrm);
+
+ /*OSD*/
+
+ offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1, "FocuseNum: %u", FocuseNum);
+ HI_ASSERT(offset < sizeof(osdBuf));
+
+ offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1, "; UnfocuseNum: %u", UnfocuseNum);
+ HI_ASSERT(offset < sizeof(osdBuf));
+
+ offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1, "; IDTotalNum: %u", ID_num_total);
+ HI_ASSERT(offset < sizeof(osdBuf));
+
+ if (strcmp(osdBuf, prevOsd) != 0) {
+ HiStrxfrm(prevOsd, osdBuf, sizeof(prevOsd)); //就是把osdBuf字符串拷贝给prevOsd
+ // HI_OSD_ATTR_S rgn;
+ TxtRgnInit(&rgn, osdBuf, TXT_BEGX, TXT_BEGY, ARGB1555_RED); // font width and heigt use default 40
+ OsdsSetRgn(g_osdsPerson, g_osd0Person, &rgn);
+ }
+ ID_num_total = SORT_ID_num_total();
+ if(ID_num_total>0)
+ AD_attractiveness_mean= AD_attractiveness_total/ID_num_total;
+ else
+ AD_attractiveness_mean=0;
+ // //UdpSend
+ // sprintf(buffsend,"FoucseNum: %u,\nUnfocuseNum: %u,\nIDTotalNum: %u\nfocused_time_total: %f\nAD_attractiveness_mean: %f",
+ // FocuseNum,UnfocuseNum,ID_num_total,focused_time_total, AD_attractiveness_mean);
+ // sendto(sock,buffsend,strlen(buffsend),0,(struct sockaddr *)&s,sizeof(s));
+ // //UdpRecive
+
+ s32Ret = HI_MPI_VO_SendFrame(voLayer, voChn, &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "HI_MPI_VO_SendFrame failed, Error(%#x)!\n", s32Ret);
+
+ //printf("SendstBaseFrmInfo:width:%d, height:%d, entype:%d\n",stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height,stBaseFrmInfo.stVFrame.enPixelFormat);
+ BASE_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[0], &stBaseFrmInfo);
+ if (HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
+ s32Ret,s32VpssGrp,as32VpssChn[0]);
+ }
+
+ EXT_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[1], &stExtFrmInfo);
+ if (HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
+ s32Ret,s32VpssGrp,as32VpssChn[1]);
+ }
+
+ }
+
+ return HI_NULL;
+}
+
+
+static HI_VOID* SAMPLE_SVP_NNIE_Yolov2_ViToVo_thread_backup(HI_VOID* pArgs)
+{
+ HI_S32 s32Ret;
+ SAMPLE_SVP_NNIE_PARAM_S *pstParam;
+ SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S *pstSwParam;
+ VIDEO_FRAME_INFO_S stBaseFrmInfo;
+ VIDEO_FRAME_INFO_S stExtFrmInfo;
+ HI_S32 s32MilliSec = 20000;
+ VO_LAYER voLayer = 0;
+ VO_CHN voChn = 0;
+ HI_S32 s32VpssGrp = 0;
+ HI_S32 as32VpssChn[] = {VPSS_CHN0, VPSS_CHN1};
+
+ pstParam = &s_stYolov2NnieParam;
+ pstSwParam = &s_stYolov2SoftwareParam;
+
+ struct timespec start_time,end_time;
+ float use_time =0;
+
+ OsdSet *osds;
+ osds = OsdsCreate(HI_OSD_BINDMOD_VPSS, s32VpssGrp, as32VpssChn[0]);
+ s32Ret = OsdLibInit();
+ g_osdsPerson = osds;
+ HI_ASSERT(g_osdsPerson);
+ g_osd0Person = OsdsCreateRgn(g_osdsPerson);
+ HI_ASSERT(g_osd0Person >= 0);
+ memset_s(g_osd_Person_ID, sizeof(HI_S32)*DETECT_OBJ_MAX, -1, sizeof(HI_S32)*DETECT_OBJ_MAX); //或用0xFF
+
+ for(int i=0; i<15; i++){
+ g_osd_Person_ID[i] = OsdsCreateRgn(g_osdsPerson);
+ HI_ASSERT(g_osd_Person_ID[i]>=0);
+ }
+
+ PERSON_ID personID[DETECT_OBJ_MAX] = {0};
+ int prev_box_num=0;
+ // int max_ID_num=-1;
+ int prev_rgn_num=0;
+ //static HI_U32 focused_time_total=0;
+ //static HI_U32 ID_num_total=0; //被跟踪的总人数
+ HI_U32 frame=1; //从1计起
+ //广告吸引度
+ HI_FLOAT AD_attractiveness_total=0; //AD_attractiveness_dead_ID + 当前帧ID累计得到的吸引度
+ HI_FLOAT AD_attractiveness_dead_ID=0;//已经丢失的ID的AD_attractiveness_total
+ HI_FLOAT AD_attractiveness_mean=0; //对ID总数做平均,AD_attractiveness_total/ID_num_total
+ //AD_attractiveness_mean即对每个ID做平均的广告吸引度,其值域应为[0,1]
+
+ static HI_CHAR prevOsd[BUF_LEN];
+ HI_OSD_ATTR_S rgn;
+ HI_OSD_ATTR_S rgn_ID[DETECT_OBJ_MAX]={0};
+ int x_ID, y_ID;
+ HI_S32 offset = 0;
+ HI_CHAR osdBuf[BUF_LEN] = "";
+ HI_S32 offset_box=0;
+ HI_CHAR osdBuf_box[BUF_LEN] = "";
+
+ /*udp*/
+ struct sockaddr_in s;
+ int sock;
+ char buffsend[512];
+ char buffrecive[512];
+ //协议:IPv4、IPv6
+ //PF_INET PF_INET6
+ //SOCK_DGRAM 无连接的
+ //SOCK_STREAM TCP 面向连接的
+ if((sock = socket(AF_INET,SOCK_DGRAM,0))==-1){
+ perror("error");
+ }
+
+ memset(&s,0,sizeof(s));
+ s.sin_family = AF_INET;
+ s.sin_port = htons(8888);
+ //pc端口
+ //s.sin_addr.s_addr = inet_addr("192.168.200.1");
+ //手机端口
+ s.sin_addr.s_addr = inet_addr("192.168.12.2");
+ memset(buffsend,0,sizeof(buffsend));
+ /*udp*/
+
+ while (HI_FALSE == s_bNnieStopSignal)
+ {
+ offset=0;
+ offset_box=0;
+ memset_s(osdBuf,BUF_LEN,0,BUF_LEN);
+ memset_s(osdBuf_box,BUF_LEN,0,BUF_LEN);
+
+ // for(int i=0; i<5; i++){
+ // g_osd_Person_ID[i] = OsdsCreateRgn(g_osdsPerson);
+ // HI_ASSERT(g_osd_Person_ID[i]>=0);
+ // }
+
+ clock_gettime(CLOCK_REALTIME, &start_time);
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[1], &stExtFrmInfo, s32MilliSec);
+ if(HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
+ s32Ret,s32VpssGrp, as32VpssChn[1]);
+ continue;
+ }
+
+ s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[0], &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, EXT_RELEASE,
+ "Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
+ s32Ret,s32VpssGrp, as32VpssChn[0]);
+
+ VIDEO_FRAME_INFO_S resizeFrm;
+ s32Ret = MppFrmResize(&stExtFrmInfo, &resizeFrm, Net_FRM_WIDTH, Net_FRM_HEIGHT);
+ int objNum;
+ s32Ret = SAMPLE_SVP_NNIE_Yolov2_Proc_ViToVo(pstParam,pstSwParam, &resizeFrm,
+ stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height,objs,DETECT_OBJ_MAX, &objNum);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "Error(%#x),SAMPLE_SVP_NNIE_YOLOV2_Proc failed!\n", s32Ret);
+
+
+ HI_U32 FocuseNum = 0;
+ HI_U32 UnfocuseNum = 0;
+
+ //printf("!!!!!!!!!!!!!!!!!!!!!!!! objNum: %d, focused_time: %.3f !!!!!!!!!!!!!!!!!!!!!!!!!!",objNum,focused_time_total);
+ // for (int i = 0; i < objNum; i++) {
+ // RectBox *box = &objs[i].box;
+ // RectBoxTran(box, Net_FRM_WIDTH, Net_FRM_HEIGHT,stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height);
+ // SAMPLE_PRT("yolo2_out: {%d, %d, %d, %d} \n score: %f \n class: %d\n", box->xmin, box->ymin, box->xmax, box->ymax, objs[i].score, objs[i].cls);
+ // //因为验证而打印的部分后续可以删了:包括SAMPLE_PRT、printf、HI_ASSERT
+ // // boxs[i] = *box;
+ // // if(objs[i].cls == 1){
+ // // UnfocuseNum++;
+ // // }
+ // // if(objs[i].cls == 2){
+ // // FocuseNum++;
+ // // }
+ // }
+ //SAMPLE_SVP_TRACE_INFO("The Width is %d\n", resizeFrm.stVFrame.u32Width);
+ //SAMPLE_SVP_TRACE_INFO("The Height is %d\n", resizeFrm.stVFrame.u32Height);
+
+ //s32Ret = HI_MPI_VO_SendFrame(voLayer, voChn, &resizeFrm, 0);
+ //SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, BASE_RELEASE,
+ //"HI_MPI_VO_SendFrame fail, Error(%#x)\n", s32Ret);
+
+
+ //后面画框用到的box信息要使用跟踪的PERSON_ID.box_curr,这样能够弥补漏检的情况
+ // MppFrmDestroy(&resizeFrm);
+ // //Draw rect
+ // int num = 0;
+ // for (int j = 0; j < objNum; j++) {
+ // remainingBoxs[num++] = boxs[j];
+ // if(objs[j].cls == 1){
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, objNum, RGB888_GREEN, DRAW_RETC_THICK);
+ // }
+ // else{
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, objNum, RGB888_RED, DRAW_RETC_THICK);
+ // }
+ // }
+ //之前不是讨论过MppFrmDrawRects是一次性画多个框的吗
+ //改成下面这样?
+ // for (int j = 0; j < objNum; j++) {
+ // remainingBoxs[0] = boxs[j];
+ // if(objs[j].cls == 1){
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_GREEN, DRAW_RETC_THICK);
+ // }
+ // else{
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_RED, DRAW_RETC_THICK);
+ // }
+ // }
+
+ clock_gettime(CLOCK_REALTIME, &end_time);
+ //单位是毫秒,hyc把这部分移到SendFrame前面了,因为Track要统计时间,统计的ID要显示在画面中
+ use_time = (float)(end_time.tv_sec - start_time.tv_sec)*1000 + (end_time.tv_nsec - start_time.tv_nsec) / 1000000.0;
+ //SAMPLE_SVP_TRACE_INFO("The use time is %f ms\n", use_time);
+
+ prev_box_num = Trivial_Track_Yolov2(objs, objNum, use_time, personID, prev_box_num, frame, &AD_attractiveness_dead_ID);
+ frame++;
+
+ // if(prev_box_num>max_ID_num)
+ // max_ID_num=prev_box_num;
+
+ //实验发现会出现cls=0的情况,必须手动把它排除掉
+ //Draw rects; display ID number; print info for debugging
+ AD_attractiveness_total=AD_attractiveness_dead_ID;
+ printf("dead%f\n",AD_attractiveness_total);
+ for (int i = 0; i < prev_box_num; i++) {
+ RectBox box = personID[i].box_curr;
+ RectBoxTran(&box, Net_FRM_WIDTH, Net_FRM_HEIGHT,stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height);
+ //SAMPLE_PRT("yolo2_out_track: box{%d, %d, %d, %d} \n class: %d\n miss_hits:%d,\n box_ID:%d,\n matched_flag:%d,\n tracked_count:%d,focuesed_time[%f,%f,%f,%f,%f,%f]",
+ //box.xmin, box.ymin, box.xmax, box.ymax, personID[i].cls, personID[i].miss_hits, personID[i].box_ID, personID[i].matched_flag, personID[i].tracked_count,personID[i].focused_time[0],personID[i].focused_time[1],personID[i].focused_time[2],personID[i].focused_time[3],personID[i].focused_time[4],personID[i].focused_time[5]);
+ //因为验证而打印的部分后续可以删了:包括SAMPLE_PRT、printf、HI_ASSERT
+ // boxs[i] = box;
+ remainingBoxs[0] = box;
+ BoxsIDprint[i] = box;
+ if(personID[i].tracked_flag==HI_TRUE){
+ memset_s(osdBuf_box,BUF_LEN,0,BUF_LEN);
+ offset_box=0;
+ if(personID[i].cls == 1){
+ UnfocuseNum++;
+ MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_GREEN, DRAW_RETC_THICK);
+ offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ "%u ", personID[i].box_ID);
+ offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ "Unfocused");
+ HI_ASSERT(offset_box < sizeof(osdBuf_box));
+ x_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].xmin)/2)*2,0),stBaseFrmInfo.stVFrame.u32Width-1);
+ y_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].ymin-40)/2)*2,0),stBaseFrmInfo.stVFrame.u32Height-1);
+ //字体大小的设置:sample\taurus\ai_sample\mpp_help\src\osd_img.c,OSD_FONT_WIDTH_DEF与OSD_FONT_HEIGHT_DEF
+ TxtRgnInit(&rgn_ID[i], osdBuf_box, x_ID, y_ID, ARGB1555_BLUE); // font width and heigt use default 40
+ OsdsSetRgn(g_osdsPerson, g_osd_Person_ID[i], &rgn_ID[i]);
+ }
+ else if(personID[i].cls == 2){
+ FocuseNum++;
+ MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_RED, DRAW_RETC_THICK);
+ offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ "%u ", personID[i].box_ID);
+ offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ "Focused");
+ HI_ASSERT(offset_box < sizeof(osdBuf_box));
+ x_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].xmin)/2)*2,0),stBaseFrmInfo.stVFrame.u32Width-1);
+ y_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].ymin-40)/2)*2,0),stBaseFrmInfo.stVFrame.u32Height-1);
+ //字体大小的设置:sample\taurus\ai_sample\mpp_help\src\osd_img.c,OSD_FONT_WIDTH_DEF与OSD_FONT_HEIGHT_DEF
+ TxtRgnInit(&rgn_ID[i], osdBuf_box, x_ID, y_ID, ARGB1555_BLUE); // font width and heigt use default 40
+ OsdsSetRgn(g_osdsPerson, g_osd_Person_ID[i], &rgn_ID[i]);
+ }
+ AD_attractiveness_total+= personID[i].focused_time_total/personID[i].live_time;
+ printf("curlive id:%d,class:%d,totalfocustime:%f,livetime:%f\n",personID[i].box_ID,personID[i].cls,personID[i].focused_time_total,personID[i].live_time);
+ //每个框的左上角加ID文字
+ // memset_s(osdBuf_box,BUF_LEN,0,BUF_LEN);
+ // offset_box=0;
+ // offset_box += snprintf_s(osdBuf_box + offset_box, sizeof(osdBuf_box) - offset_box, sizeof(osdBuf_box) - offset_box - 1,
+ // "%u", personID[i].box_ID);
+ // HI_ASSERT(offset_box < sizeof(osdBuf_box));
+ // x_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].xmin)/2)*2,0),stBaseFrmInfo.stVFrame.u32Width);
+ // y_ID=SAMPLE_SVP_NNIE_MIN(SAMPLE_SVP_NNIE_MAX(((BoxsIDprint[i].ymin-40)/2)*2,0),stBaseFrmInfo.stVFrame.u32Height);
+ // //字体大小的设置:sample\taurus\ai_sample\mpp_help\src\osd_img.c,OSD_FONT_WIDTH_DEF与OSD_FONT_HEIGHT_DEF
+ // TxtRgnInit(&rgn_ID[i], osdBuf_box, x_ID, y_ID, ARGB1555_BLUE); // font width and heigt use default 40
+ // OsdsSetRgn(g_osdsPerson, g_osd_Person_ID[i], &rgn_ID[i]);
+ }
+ //printf("g_osd_person_ID[%d]:%d\n",i,g_osd_Person_ID[i]);
+ //OsdsDestroyRgn(g_osdsPerson,g_osd_Person_ID[i]);
+ }
+ for(int i=prev_box_num;i>>g_osd_person_ID[%d]:%d\n",i,g_osd_Person_ID[i]);
+ }
+ prev_rgn_num=prev_box_num;
+ // for(int i=prev_box_num;i>>g_osd_person_ID[%d]:%d\n",i,g_osd_Person_ID[i]);
+ // }
+ // for(int i=0;i<5;i++)
+ // {
+ // printf("g_osd_person_ID[%d]:%d\n",i,g_osd_Person_ID[i]);
+ // OsdsDestroyRgn(g_osdsPerson,g_osd_Person_ID[i]);
+ // }
+
+
+
+ //Draw rect
+ // for (int j = 0; j < prev_box_num; j++) {
+ // remainingBoxs[0] = boxs[j];
+ // if(personID[j].tracked_flag==HI_TRUE){
+ // if(objs[j].cls == 1){
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_GREEN, DRAW_RETC_THICK);
+ // }
+ // else if(objs[j].cls == 2){
+ // MppFrmDrawRects(&stBaseFrmInfo, remainingBoxs, 1, RGB888_RED, DRAW_RETC_THICK);
+ // }
+ // }
+ // }
+ MppFrmDestroy(&resizeFrm);
+
+ /*OSD*/
+
+ offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1, "FocuseNum: %u", FocuseNum);
+ HI_ASSERT(offset < sizeof(osdBuf));
+ // offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1,
+ // "%u",FocuseNum);
+ // HI_ASSERT(offset < sizeof(osdBuf));
+
+ offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1, "; UnfocuseNum: %u", UnfocuseNum);
+ HI_ASSERT(offset < sizeof(osdBuf));
+ // offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1,
+ // "%u",UnfocuseNum);
+ // HI_ASSERT(offset < sizeof(osdBuf));
+
+ offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1, "; IDTotalNum: %u", ID_num_total);
+ HI_ASSERT(offset < sizeof(osdBuf));
+ // offset += snprintf_s(osdBuf + offset, sizeof(osdBuf) - offset, sizeof(osdBuf) - offset - 1,
+ // "%u",ID_num_total);
+ // HI_ASSERT(offset < sizeof(osdBuf));
+
+ if (strcmp(osdBuf, prevOsd) != 0) {
+ HiStrxfrm(prevOsd, osdBuf, sizeof(prevOsd)); //就是把osdBuf字符串拷贝给prevOsd
+ // HI_OSD_ATTR_S rgn;
+ TxtRgnInit(&rgn, osdBuf, TXT_BEGX, TXT_BEGY, ARGB1555_RED); // font width and heigt use default 40
+ OsdsSetRgn(g_osdsPerson, g_osd0Person, &rgn);
+ }
+ if(ID_num_total>0)
+ AD_attractiveness_mean= AD_attractiveness_total/ID_num_total;
+ else
+ AD_attractiveness_mean=0;
+ //UdpSend
+ sprintf(buffsend,"FoucseNum: %u,\nUnfocuseNum: %u,\nIDTotalNum: %u\nfocused_time_total: %f\nAD_attractiveness_mean: %f",
+ FocuseNum,UnfocuseNum,ID_num_total,focused_time_total, AD_attractiveness_mean);
+ sendto(sock,buffsend,strlen(buffsend),0,(struct sockaddr *)&s,sizeof(s));
+ //UdpRecive
+
+ s32Ret = HI_MPI_VO_SendFrame(voLayer, voChn, &stBaseFrmInfo, s32MilliSec);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
+ "HI_MPI_VO_SendFrame failed, Error(%#x)!\n", s32Ret);
+
+ //printf("SendstBaseFrmInfo:width:%d, height:%d, entype:%d\n",stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height,stBaseFrmInfo.stVFrame.enPixelFormat);
+ BASE_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[0], &stBaseFrmInfo);
+ if (HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
+ s32Ret,s32VpssGrp,as32VpssChn[0]);
+ }
+
+ EXT_RELEASE:
+ s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[1], &stExtFrmInfo);
+ if (HI_SUCCESS != s32Ret)
+ {
+ SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
+ s32Ret,s32VpssGrp,as32VpssChn[1]);
+ }
+
+ }
+
+ return HI_NULL;
+}
+/******************************************************************************
+* function : Yolov2 vi to vo real time detection
+******************************************************************************/
+void SAMPLE_SVP_NNIE_Yolov2_Vivo(void)
+{
+ // HI_CHAR *pcSrcFile = "./data/nnie_image/rgb_planar/dog_bike_car_416x416.bgr";
+ HI_CHAR *pcModelName = "./data/nnie_model/detection/resnet18_best.wk";
+ SAMPLE_SVP_NNIE_CFG_S stNnieCfg = {0};
+ SIZE_S stSize;
+ PIC_SIZE_E enSize = PIC_CIF;
+ HI_S32 s32Ret = HI_SUCCESS;
+ HI_CHAR acThreadName[16] = {0};
+
+
+
+
+ /*Sys init*/
+ SAMPLE_COMM_SVP_CheckSysInit();
+
+ /******************************************
+ step 1: start vi vpss vo
+ ******************************************/
+ s_stYolov2Switch.bVenc = HI_FALSE;
+ s_stYolov2Switch.bVo = HI_TRUE;
+ s32Ret = SAMPLE_COMM_IVE_StartViVpssVencVo_Yolov2(&s_stViConfig,&s_stYolov2Switch,&enSize);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, YOLOV2_FAIL_1,
+ "Error(%#x),SAMPLE_COMM_IVE_StartViVpssVencVo failed!\n", s32Ret);
+
+ s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSize, &stSize);
+ SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, YOLOV2_FAIL_1,
+ "Error(%#x),SAMPLE_COMM_SYS_GetPicSize failed!\n", s32Ret);
+
+ stSize.u32Width = 640;
+ stSize.u32Height = 384;
+
+ /******************************************
+ step 2: init NNIE param
+ ******************************************/
+ stNnieCfg.pszPic= NULL;
+ stNnieCfg.u32MaxInputNum = 1;
+ stNnieCfg.u32MaxRoiNum = 0;
+ stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0;//set NNIE core
+
+ /*YOLOV2 */
+ SAMPLE_SVP_NNIE_CFG_S *self;
+ HI_U32 u32PicNum = 1;
+ //HI_S32 s32Ret;
+
+ self = (SAMPLE_SVP_NNIE_CFG_S*)malloc(sizeof(*self));
+ HI_ASSERT(self);
+ memset_s(self, sizeof(*self), 0x00, sizeof(*self));
+
+ /*
+ * 设置配置参数
+ * Set configuration parameter
+ */
+ self->pszPic = NULL;
+ self->u32MaxInputNum = u32PicNum; // max input image num in each batch
+ self->u32MaxRoiNum = 0;
+ self->aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
+
+ /*Yolov2 Load model*/
+ SAMPLE_SVP_TRACE_INFO("Yolov2 Load model!\n");
+ s32Ret = SAMPLE_COMM_SVP_NNIE_LoadModel(pcModelName,&s_stYolov2Model);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret,YOLOV2_FAIL_0,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SAMPLE_COMM_SVP_NNIE_LoadModel failed!\n");
+
+ /*Yolov2 parameter initialization*/
+ /*Yolov2 software parameters are set in SAMPLE_SVP_NNIE_Yolov2_SoftwareInit,
+ if user has changed net struct, please make sure the parameter settings in
+ SAMPLE_SVP_NNIE_Yolov2_SoftwareInit function are correct*/
+ SAMPLE_SVP_TRACE_INFO("Yolov2 parameter initialization!\n");
+ s_stYolov2NnieParam.pstModel = &s_stYolov2Model.stModel;
+ // s32Ret = SAMPLE_SVP_NNIE_Yolov2_ParamInit(&stNnieCfg,&s_stYolov2NnieParam,&s_stYolov2SoftwareParam);
+ // SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret,YOLOV2_FAIL_0,SAMPLE_SVP_ERR_LEVEL_ERROR,
+ // "Error,SAMPLE_SVP_NNIE_Yolov2_ParamInit failed!\n");
+ s32Ret = SampleSvpNnieYolov2ParamInit(self, &s_stYolov2NnieParam, &s_stYolov2SoftwareParam);
+ SAMPLE_SVP_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, YOLOV2_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
+ "Error,SampleSvpNnieYolov2ParamInit failed!\n");
+
+ /*Fill src data*/
+ SAMPLE_SVP_TRACE_INFO("Yolov2 start!\n");
+
+
+ s_bNnieStopSignal = HI_FALSE;
+ /******************************************
+ step 3: Create work thread
+ ******************************************/
+ snprintf(acThreadName, 16, "NNIE_ViToVo");
+ prctl(PR_SET_NAME, (unsigned long)acThreadName, 0,0,0);
+ pthread_create(&s_hNnieThread, 0, SAMPLE_SVP_NNIE_Yolov2_ViToVo_thread, NULL);
+ SAMPLE_PAUSE();
+
+ s_bNnieStopSignal = HI_TRUE;
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+ OsdsClear(g_osdsPerson);
+
+
+YOLOV2_FAIL_1:
+ SAMPLE_SVP_NNIE_Yolov2_Deinit(&s_stYolov2NnieParam,&s_stYolov2SoftwareParam,&s_stYolov2Model);
+
+YOLOV2_FAIL_0:
+ SAMPLE_COMM_IVE_StopViVpssVencVo_Yolov2(&s_stViConfig,&s_stYolov2Switch);
+
+}
+
+void SAMPLE_SVP_NNIE_Yolov2_Vivo_HandleSig(void)
+{
+ s_bNnieStopSignal = HI_TRUE;
+ if (0 != s_hNnieThread)
+ {
+ pthread_join(s_hNnieThread, HI_NULL);
+ s_hNnieThread = 0;
+ }
+
+ SAMPLE_SVP_NNIE_Yolov2_Deinit(&s_stYolov2NnieParam,&s_stYolov2SoftwareParam,&s_stYolov2Model);
+ memset(&s_stYolov2NnieParam,0,sizeof(SAMPLE_SVP_NNIE_PARAM_S));
+ memset(&s_stYolov2SoftwareParam,0,sizeof(SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S));
+ memset(&s_stYolov2Model,0,sizeof(SAMPLE_SVP_NNIE_MODEL_S));
+
+ SAMPLE_COMM_IVE_StopViVpssVencVo_Yolov2(&s_stViConfig,&s_stYolov2Switch);
+
+}
\ No newline at end of file
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample_nnie_main.c b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample_nnie_main.c
new file mode 100644
index 0000000000000000000000000000000000000000..ed82ca95b82a1345adbc7e353f834ab563c559df
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample_nnie_main.c
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "sdk.h"
+#include "securec.h"
+#include "sample_nnie_main.h"
+
+static char **s_ppChCmdArgv = NULL;
+
+/* function : to process abnormal case */
+#if (!defined(__HuaweiLite__)) || defined(__OHOS__)
+static void SAMPLE_SVP_HandleSig(int s32Signo)
+{
+ if (s32Signo == SIGINT || s32Signo == SIGTERM) {
+ switch (*s_ppChCmdArgv[1]) {
+ case '0':
+ SAMPLE_SVP_NNIE_Rfcn_HandleSig();
+ break;
+ case '1':
+ SAMPLE_SVP_NNIE_Segnet_HandleSig();
+ break;
+ case '2':
+ SAMPLE_SVP_NNIE_FasterRcnn_HandleSig();
+ break;
+ case '3':
+ SAMPLE_SVP_NNIE_FasterRcnn_HandleSig();
+ break;
+ case '4':
+ SAMPLE_SVP_NNIE_Cnn_HandleSig();
+ break;
+ case '5':
+ SAMPLE_SVP_NNIE_Ssd_HandleSig();
+ break;
+ case '6':
+ SAMPLE_SVP_NNIE_Yolov2_Vivo_HandleSig();
+ //SAMPLE_SVP_NNIE_Yolov1_HandleSig();
+ break;
+ case '7':
+ SAMPLE_SVP_NNIE_Yolov2_HandleSig();
+ break;
+ case '8':
+ SAMPLE_SVP_NNIE_Yolov3_HandleSig();
+ break;
+ case '9':
+ SAMPLE_SVP_NNIE_Yolov3_Vivo_HandleSig();
+ //SAMPLE_SVP_NNIE_Lstm_HandleSig();
+ break;
+ case 'a':
+ SAMPLE_SVP_NNIE_Pvanet_HandleSig();
+ break;
+ case 'b':
+ SAMPLE_SVP_NNIE_Rfcn_HandleSig_File();
+ break;
+ default:
+ break;
+ }
+ }
+}
+#endif
+
+/* function : show usage */
+static void SAMPLE_SVP_Usage(const char *pchPrgName)
+{
+ printf("Usage : %s \n", pchPrgName);
+ printf("index:\n");
+ printf("\t 0) RFCN(VI->VPSS->NNIE->VGS->VO).\n");
+ printf("\t 1) Segnet(Read File).\n");
+ printf("\t 2) FasterRcnnAlexnet(Read File).\n");
+ printf("\t 3) FasterRcnnDoubleRoiPooling(Read File).\n");
+ printf("\t 4) Cnn(Read File).\n");
+ printf("\t 5) SSD(Read File).\n");
+ //printf("\t 6) Yolov1(Read File).\n");
+ printf("\t 6) Yolov2(VI->VPSS->NNIE->VGS->VO).\n");
+ printf("\t 7) Yolov2(Read File).\n");
+ printf("\t 8) Yolov3(Read File).\n");
+ //printf("\t 9) LSTM(Read File).\n");
+ printf("\t 9) Yolov3(VI->VPSS->NNIE->VGS->VO).\n");
+ printf("\t a) Pvanet(Read File).\n");
+ printf("\t b) Rfcn(Read File).\n");
+}
+
+/* function : nnie sample */
+#if defined(__HuaweiLite__) && (!defined(__OHOS__))
+int app_main(int argc, char *argv[])
+#else
+int main(int argc, char *argv[])
+#endif
+{
+ int s32Ret = HI_SUCCESS;
+ sdk_init();
+ s_ppChCmdArgv = argv;
+#if (!defined(__HuaweiLite__)) || defined(__OHOS__)
+ struct sigaction sa;
+ (hi_void)memset_s(&sa, sizeof(struct sigaction), 0, sizeof(struct sigaction));
+ sa.sa_handler = SAMPLE_SVP_HandleSig;
+ sa.sa_flags = 0;
+ sigaction(SIGINT, &sa, NULL);
+ sigaction(SIGTERM, &sa, NULL);
+#endif
+ if (argc < 2 || argc > 2) { /* only support 2 parameters */
+ SAMPLE_SVP_Usage(argv[0]);
+ s32Ret = HI_FAILURE;
+ goto end;
+ }
+
+ if (strncmp(argv[1], "-h", 2) == 0) { /* 2: maximum number of characters to compare */
+ SAMPLE_SVP_Usage(argv[0]);
+ s32Ret = HI_SUCCESS;
+ goto end;
+ }
+ switch (*argv[1]) {
+ case '0':
+ SAMPLE_SVP_NNIE_Rfcn();
+ break;
+ case '1':
+ SAMPLE_SVP_NNIE_Segnet();
+ break;
+ case '2':
+ SAMPLE_SVP_NNIE_FasterRcnn();
+ break;
+ case '3':
+ SAMPLE_SVP_NNIE_FasterRcnn_DoubleRoiPooling();
+ break;
+ case '4':
+ SAMPLE_SVP_NNIE_Cnn();
+ break;
+ case '5':
+ SAMPLE_SVP_NNIE_Ssd();
+ break;
+ case '6':
+ SAMPLE_SVP_NNIE_Yolov2_Vivo();
+ //SAMPLE_SVP_NNIE_Yolov1();
+ break;
+ case '7':
+ SAMPLE_SVP_NNIE_Yolov2();
+ break;
+ case '8':
+ SAMPLE_SVP_NNIE_Yolov3();
+ break;
+ case '9':
+ SAMPLE_SVP_NNIE_Yolov3_Vivo();
+ //SAMPLE_SVP_NNIE_Lstm();
+ break;
+ case 'a':
+ SAMPLE_SVP_NNIE_Pvanet();
+ break;
+ case 'b':
+ SAMPLE_SVP_NNIE_Rfcn_File();
+ break;
+ default:
+ SAMPLE_SVP_Usage(argv[0]);
+ break;
+ }
+
+end:
+ sdk_exit();
+ return s32Ret;
+}
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample_nnie_software/Hungarian.cpp b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample_nnie_software/Hungarian.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c10843935979418913eb2ea235f343601a226583
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample_nnie_software/Hungarian.cpp
@@ -0,0 +1,421 @@
+/*
+匈牙利最小权匹配算法(Kuhn–Munkres最小权匹配算法)的步骤:
+DistMatrix的行表示上一帧经过predict()的track数量,列表示当前帧的detection数量
+starred表示匹配成功,primed是未匹配但是“待匹配”的状态,primed元素和starred元素交替构成增广路径,
+covered就相当于连线?
+1. 若行数小于等于列数,将权重矩阵/距离矩阵(Distance Matrix)/关联矩阵的每一行减去该行的最小值
+2a. 若一列中包含starred元素,则将用coveredColumns该列置为covered状态(初始化时是将一列中的第一个零元素置为starred,并把该列置为covered)
+2b. 处于covered状态的列数等于minDim,进入最后的线性分配阶段buildassignmentvector(),否则进入步骤3.
+3. 寻找uncovered列中位于uncovered行中的零元素,将其标记为primed,在该行寻找第一个starred元素,
+ 若能找到,将其列索引计为starCol,将starCol对应列置为uncovered,该行置为covered;若不能找到,转至步骤4.;
+ 若uncovered行、uncovered列中都没有零元素时,转至步骤5
+4. 将步骤3中新标记为primed的元素置为starred,在该列中寻找第一个除该元素以外的starred元素,将其置为unstarred,
+ 然后在转为unstarred所在行找到第一个primed元素,将其置为starred,然后继续找它所在列除它以外的第一个starred元素,循环往复……
+ 一直到无法继续扩展增广路径(找到了一条完整的增广路径),然后跳转到步骤2a.
+以下是一个图例,注意P和*都表示最开始的状态,它们连接起来的路径叫作增广路径,取反后得到一个更大的匹配图
+*表示starred,P表示primed
+@@@@@@@@@
+@@@@P@@*@(*是在step4的第一次while循环里找到的,P是在第二次while循环里找到的)
+@@@@@@@@@
+@@@@@@@@@
+@@*@@@@P@(在step4的第一次while循环里被置为primed)
+@@@@@@@@@
+@@P@@@@@@(在step3里被置为primed)
+5. 在uncovered的行和列中寻找最小值h,covered行加上h,uncovered列减去h,相当于covered行、列的交叉节点+h,其他行列均为uncovered的元素-h,
+ 处于covered行、uncovered列或者covered列、uncovered行的元素保持不变
+
+
+https://blog.csdn.net/weijimin1/article/details/89927725
+步骤一:将关联矩阵每一行减去本行的最小值,进入步骤二。
+
+步骤二:将新的矩阵每一列减去本列的最小值,进入步骤三。
+
+步骤三:用最少的行线和列线将新矩阵中的零全部穿起来,检查目前是否为最优分配。如果行线和列线没有将矩阵所有元素都穿起来,进入第四步,否则则进入步骤五
+
+步骤四:将行线和列线没有穿起来的元素中找到最小元素,将剩余元素减去最小元素,对应行线和列线的交叉点的元素加上最小元素,
+
+步骤五:找出每一行对应的0元素和列对应的0元素,根据0元素找到最优分配。
+*/
+
+#include "Hungarian.h"
+#include //DBL_EPSILON, DBL_MAX
+#include //malloc, calloc, free
+
+HungarianAlgorithm::HungarianAlgorithm(){}
+HungarianAlgorithm::~HungarianAlgorithm(){}
+
+
+//********************************************************//
+// A single function wrapper for solving assignment problem.
+//********************************************************//
+double HungarianAlgorithm::Solve(std::vector>& DistMatrix, std::vector& Assignment)
+{
+ unsigned int nRows = DistMatrix.size();
+ unsigned int nCols = DistMatrix[0].size();
+
+ double *distMatrixIn = new double[nRows * nCols];
+ int *assignment = new int[nRows];
+ double cost = 0.0;
+
+ // Fill in the distMatrixIn. Mind the index is "i + nRows * j".
+ // Here the cost matrix of size MxN is defined as a double precision array of N*M elements.
+ // In the solving functions matrices are seen to be saved MATLAB-internally in row-order.
+ // (i.e. the matrix [1 2; 3 4] will be stored as a vector [1 3 2 4], NOT [1 2 3 4]).
+ for (unsigned int i = 0; i < nRows; i++)
+ for (unsigned int j = 0; j < nCols; j++)
+ distMatrixIn[i + nRows * j] = DistMatrix[i][j];
+
+ // call solving function
+ assignmentoptimal(assignment, &cost, distMatrixIn, nRows, nCols);
+
+ Assignment.clear();
+ for (unsigned int r = 0; r < nRows; r++)
+ Assignment.push_back(assignment[r]);
+
+ delete[] distMatrixIn;
+ delete[] assignment;
+ return cost;
+}
+
+
+//********************************************************//
+// Solve optimal solution for assignment problem using Munkres algorithm, also known as Hungarian Algorithm.
+//********************************************************//
+void HungarianAlgorithm::assignmentoptimal(int *assignment, double *cost, double *distMatrixIn, int nOfRows, int nOfColumns)
+{
+ double *distMatrix, *distMatrixTemp, *distMatrixEnd, *columnEnd, value, minValue;
+ bool *coveredColumns, *coveredRows, *starMatrix, *newStarMatrix, *primeMatrix;
+ int nOfElements, minDim, row, col;
+
+ /* initialization */
+ *cost = 0;
+ for (row = 0; row nOfColumns) */
+ {
+ minDim = nOfColumns;
+
+ for (col = 0; col= 0)
+ *cost += distMatrix[row + nOfRows*col];
+ }
+}
+
+/********************************************************/
+void HungarianAlgorithm::step2a(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim)
+{
+ bool *starMatrixTemp, *columnEnd;
+ int col;
+
+ /* cover every column containing a starred zero */
+ for (col = 0; col
+
+class HungarianAlgorithm
+{
+public:
+ HungarianAlgorithm();
+ ~HungarianAlgorithm();
+ double Solve(std::vector>& DistMatrix, std::vector& Assignment);
+
+private:
+ void assignmentoptimal(int *assignment, double *cost, double *distMatrix, int nOfRows, int nOfColumns);
+ void buildassignmentvector(int *assignment, bool *starMatrix, int nOfRows, int nOfColumns);
+ void computeassignmentcost(int *assignment, double *cost, double *distMatrix, int nOfRows);
+ void step2a(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
+ void step2b(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
+ void step3(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
+ void step4(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim, int row, int col);
+ void step5(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
+};
+
+#ifdef __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
diff --git a/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample_nnie_software/KalmanTracker.cpp b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample_nnie_software/KalmanTracker.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1ddaa15cdf7dc107b8dafc685ad308a665843391
--- /dev/null
+++ b/AIOT/10274_Intelligent AD Analysis System/code/nnie/sample_nnie_software/KalmanTracker.cpp
@@ -0,0 +1,193 @@
+#include "KalmanTracker.h"
+#include
+
+int KalmanTracker::kf_cnt = 0;
+float KalmanTracker::_focused_time_total=0.0;
+
+KalmanTracker::KalmanTracker(cv::Rect_ initState, int cls)
+{
+ m_time_since_update = 0;
+ m_hit_streak = 0;
+ m_hit_streak_init = 0;
+ m_age = 0;
+ m_id = -1; //-1代表该tracker还未初始化,还不能赋予它id值
+ m_cls = cls;
+ m_accumulate_first_flag =false;
+ m_focused_time_total = 0;
+ m_live_time = 0;
+ memset(m_focused_time, 0, sizeof(m_focused_time));
+ init_kf(initState);
+}
+
+void KalmanTracker::init_kf(cv::Rect_ stateRect)
+{
+ int stateDim=7;
+ int measureDim=4;
+ int controlDim=0;
+ //默认int type=CV_32F(值为5)
+ kf = cv::KalmanFilter(stateDim, measureDim, controlDim);
+
+ measurement = cv::Mat::zeros(measureDim, 1, CV_32F);
+
+ kf.transitionMatrix = (cv::Mat_(stateDim, stateDim) <<
+ 1, 0, 0, 0, 1, 0, 0,
+ 0, 1, 0, 0, 0, 1, 0,
+ 0, 0, 1, 0, 0, 0, 1,
+ 0, 0, 0, 1, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0, 1);
+ kf.measurementMatrix = (cv::Mat_(measureDim, stateDim) <<
+ 1, 0, 0, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0, 0, 0,
+ 0, 0, 1, 0, 0, 0, 0,
+ 0, 0, 0, 1, 0, 0, 0);
+ kf.processNoiseCov = (cv::Mat_(stateDim, stateDim) <<
+ 1, 0, 0, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0, 0, 0,
+ 0, 0, 1, 0, 0, 0, 0,
+ 0, 0, 0, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0.01, 0, 0,
+ 0, 0, 0, 0, 0, 0.01, 0,
+ 0, 0, 0, 0, 0, 0, 0.0001);
+ kf.measurementNoiseCov = (cv::Mat_(measureDim, measureDim) <<
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 10, 0,
+ 0, 0, 0, 10);
+ kf.errorCovPost = (cv::Mat_(stateDim, stateDim) <<
+ 10, 0, 0, 0, 0, 0, 0,
+ 0, 10, 0, 0, 0, 0, 0,
+ 0, 0, 10, 0, 0, 0, 0,
+ 0, 0, 0, 10, 0, 0, 0,
+ 0, 0, 0, 0, 10000, 0, 0,
+ 0, 0, 0, 0, 0, 10000, 0,
+ 0, 0, 0, 0, 0, 0, 10000);
+ kf.statePost.at(0,0) = stateRect.x + stateRect.width/2;
+ kf.statePost.at(1,0) = stateRect.y + stateRect.height/2;
+ kf.statePost.at(2,0) = stateRect.area();
+ kf.statePost.at(3,0) = stateRect.width/stateRect.height;
+}
+
+cv::Rect_ KalmanTracker::predict()
+{
+ if((kf.statePost.at(2,0) + kf.statePost.at(6,0)) <= 0)
+ kf.statePost.at(6,0) = 0.0;
+
+ cv::Mat p = kf.predict();
+ m_age += 1;
+
+ // 初始化阶段,在达到MIN_HITS之前若出现过一次匹配失败就将hit_streak置零,
+ // 相当于重新开始初始化的过程,但用到的bbox信息是之前的还没被删掉的track bbox
+ if(m_id==-1){
+ if(m_time_since_update>0){
+ m_hit_streak=0;
+ m_hit_streak_init=0;
+ }
+ }
+ else if(m_time_since_update>MAX_AGE_SORT-1)
+ m_hit_streak=0;
+
+ // 这种策略要求更低一些,不要求连续成功匹配MIN_HITS次才能将bbox成功初始化
+ // 与Trivial_Track_Yolov2()的策略类似
+ // if(m_time_since_update>MAX_AGE_SORT-1){
+ // m_hit_streak = 0;
+ // if(m_id==-1)
+ // m_hit_streak_init = 0;
+ // }
+
+ m_time_since_update += 1;
+
+ return xysr2cvRect(p.at(0,0) ,p.at(1, 0), p.at(2, 0), p.at(3, 0));
+}
+
+void KalmanTracker::update(cv::Rect_ measureRect)
+{
+ m_time_since_update = 0;
+ m_hit_streak += 1;
+ if(m_id == -1){
+ m_hit_streak_init+=1;
+ if(m_hit_streak_init>=MIN_HITS_SORT){
+ m_id = get_tracker_num();
+ add_tracker_num();
+ }
+ }
+ measurement.at(0, 0) = measureRect.x + measureRect.width/2;
+ measurement.at(1, 0) = measureRect.y + measureRect.height/2;
+ measurement.at(2, 0) = measureRect.area();
+ measurement.at(3, 0) = measureRect.width/measureRect.height;
+
+ kf.correct(measurement);
+}
+
+cv::Rect_ KalmanTracker::get_state()
+{
+ return xysr2cvRect(kf.statePost.at(0,0), kf.statePost.at(1,0),
+ kf.statePost.at(2,0), kf.statePost.at(3,0));
+}
+
+int KalmanTracker::get_tracker_num()
+{
+ return kf_cnt;
+}
+
+void KalmanTracker::add_tracker_num()
+{
+ kf_cnt++;
+}
+
+float KalmanTracker::get_global_focused_time_total()
+{
+ return _focused_time_total;
+}
+
+void KalmanTracker::accumulate_global_focused_time_total(float focused_time)
+{
+ _focused_time_total+=focused_time;
+}
+
+cv::Rect_ KalmanTracker::xysr2cvRect(float xc,float yc, float s, float r)
+{
+ float w = std::sqrt(s * r);
+ float h = s/w;
+ float xmin = xc - w/2;
+ float ymin = yc - h/2;
+ // float xmax = xc + w/2;
+ // float ymax = yc + h/2;
+ // return cv::Rect_(xmin, ymin, xmax, ymax);
+ if (xmin < 0 && xc > 0)
+ xmin = 0;
+ if (ymin < 0 && yc > 0)
+ ymin = 0;
+ return cv::Rect_(xmin, ymin, w, h);
+}
+
+void KalmanTracker::SORT_Accumulate_Focused_Time(int frame_circular)
+{
+ int i;
+ int focused_count=0;
+ if(m_accumulate_first_flag == false){
+ float sum = 0;
+ for(i=0; i