STM32N6 NPU Deployment — Politecnico di Milano  1.0
Documentation for Neural Network Deployment on STM32N6 NPU - Politecnico di Milano 2024-2025
display_mpe.c
Go to the documentation of this file.
1 
19 #include "display_mpe.h"
20 #include "app_config.h"
21 #include "main.h"
22 #include "display_keypoints_17.h"
23 #include "utils.h"
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <stdint.h>
27 
28 #define NUMBER_COLORS 10
29 const uint32_t colors[NUMBER_COLORS] = {
30  UTIL_LCD_COLOR_GREEN,
31  UTIL_LCD_COLOR_RED,
32  UTIL_LCD_COLOR_CYAN,
33  UTIL_LCD_COLOR_MAGENTA,
34  UTIL_LCD_COLOR_YELLOW,
35  UTIL_LCD_COLOR_GRAY,
36  UTIL_LCD_COLOR_BLACK,
37  UTIL_LCD_COLOR_BROWN,
38  UTIL_LCD_COLOR_BLUE,
39  UTIL_LCD_COLOR_ORANGE
40 };
41 
42 static int (*clamp_point)(int *x, int *y);
43 static void (*convert_length)(float32_t wi, float32_t hi, int *wo, int *ho);
44 static void (*convert_point)(float32_t xi, float32_t yi, int *xo, int *yo);
45 static void (*Display_binding_line)(int x0, int y0, int x1, int y1, uint32_t color);
46 
47 static void Display_keypoint(mpe_pp_keyPoints_t *key, uint32_t color)
48 {
49  int is_clamp;
50  int xc, yc;
51  int x, y;
52 
53  if (key->conf < AI_POSE_PP_CONF_THRESHOLD)
54  return ;
55 
56  convert_point(key->x, key->y, &x, &y);
57  xc = x - CIRCLE_RADIUS / 2;
58  yc = y - CIRCLE_RADIUS / 2;
59  is_clamp = clamp_point(&xc, &yc);
60  xc = x + CIRCLE_RADIUS / 2;
61  yc = y + CIRCLE_RADIUS / 2;
62  is_clamp |= clamp_point(&xc, &yc);
63 
64  if (is_clamp)
65  return ;
66 
67  UTIL_LCD_FillCircle(x, y, CIRCLE_RADIUS, color);
68 }
69 
70 static void Display_binding(mpe_pp_keyPoints_t *from, mpe_pp_keyPoints_t *to, uint32_t color)
71 {
72  int is_clamp;
73  int x0, y0;
74  int x1, y1;
75  int i;
76 
77  assert(BINDING_WIDTH % 2 == 1);
78 
79  if (from->conf < AI_POSE_PP_CONF_THRESHOLD)
80  return ;
81  if (to->conf < AI_POSE_PP_CONF_THRESHOLD)
82  return ;
83 
84  convert_point(from->x, from->y, &x0, &y0);
85  is_clamp = clamp_point(&x0, &y0);
86  if (is_clamp)
87  return ;
88 
89  convert_point(to->x, to->y, &x1, &y1);
90  is_clamp = clamp_point(&x1, &y1);
91  if (is_clamp)
92  return ;
93 
94  UTIL_LCD_DrawLine(x0, y0, x1, y1, color);
95  for (i = 1; i <= (BINDING_WIDTH - 1) / 2; i++) {
96  if (abs(y1 - y0) > abs(x1 - x0)) {
97  Display_binding_line(x0 + i, y0, x1 + i , y1, color);
98  Display_binding_line(x0 - i, y0, x1 - i , y1, color);
99  } else {
100  Display_binding_line(x0, y0 + i, x1 , y1 + i, color);
101  Display_binding_line(x0, y0 - i, x1 , y1 - i, color);
102  }
103  }
104 }
105 
106 void Display_mpe_InitFunctions(int clamp_point_init(int *x, int *y),
107  void convert_length_init(float32_t wi, float32_t hi, int *wo, int *ho),
108  void convert_point_init(float32_t xi, float32_t yi, int *xo, int *yo),
109  void Display_binding_line_init(int x0, int y0, int x1, int y1, uint32_t color))
110 {
111  clamp_point = clamp_point_init;
112  convert_length = convert_length_init;
113  convert_point = convert_point_init;
114  Display_binding_line = Display_binding_line_init;
115 }
116 
117 void Display_mpe_Detection(mpe_pp_outBuffer_t *detect)
118 {
119  int xc, yc;
120  int x0, y0;
121  int x1, y1;
122  int w, h;
123  int i;
124 
125  convert_point(detect->x_center, detect->y_center, &xc, &yc);
126  convert_length(detect->width, detect->height, &w, &h);
127  x0 = xc - (w + 1) / 2;
128  y0 = yc - (h + 1) / 2;
129  x1 = xc + (w + 1) / 2;
130  y1 = yc + (h + 1) / 2;
131  clamp_point(&x0, &y0);
132  clamp_point(&x1, &y1);
133 
134  UTIL_LCD_DrawRect(x0, y0, x1 - x0, y1 - y0, colors[detect->class_index % NUMBER_COLORS]);
135 
136  for (i = 0; i < ARRAY_NB(bindings); i++)
137  Display_binding(&detect->pKeyPoints[bindings[i][0]], &detect->pKeyPoints[bindings[i][1]], bindings[i][2]);
138  for (i = 0; i < AI_POSE_PP_POSE_KEYPOINTS_NB; i++)
139  Display_keypoint(&detect->pKeyPoints[i], kp_color[i]);
140 }
Central configuration header for the STM32N6570-DK pose estimation firmware application.
static const int kp_color[13]
static const int bindings[][3]
static void Display_binding(mpe_pp_keyPoints_t *from, mpe_pp_keyPoints_t *to, uint32_t color)
Definition: display_mpe.c:70
static int(* clamp_point)(int *x, int *y)
Definition: display_mpe.c:42
static void(* convert_length)(float32_t wi, float32_t hi, int *wo, int *ho)
Definition: display_mpe.c:43
static void(* Display_binding_line)(int x0, int y0, int x1, int y1, uint32_t color)
Definition: display_mpe.c:45
#define NUMBER_COLORS
Definition: display_mpe.c:28
void Display_mpe_Detection(mpe_pp_outBuffer_t *detect)
Definition: display_mpe.c:117
void Display_mpe_InitFunctions(int clamp_point_init(int *x, int *y), void convert_length_init(float32_t wi, float32_t hi, int *wo, int *ho), void convert_point_init(float32_t xi, float32_t yi, int *xo, int *yo), void Display_binding_line_init(int x0, int y0, int x1, int y1, uint32_t color))
Definition: display_mpe.c:106
const uint32_t colors[NUMBER_COLORS]
Definition: display_mpe.c:29
static void(* convert_point)(float32_t xi, float32_t yi, int *xo, int *yo)
Definition: display_mpe.c:44
static void Display_keypoint(mpe_pp_keyPoints_t *key, uint32_t color)
Definition: display_mpe.c:47
#define AI_POSE_PP_CONF_THRESHOLD
Minimum confidence threshold for accepting a detected keypoint.
Definition: app_config.h:245
#define AI_POSE_PP_POSE_KEYPOINTS_NB
Number of body keypoints output by the model.
Definition: app_config.h:261
#define BINDING_WIDTH
Definition: main.h:32
#define CIRCLE_RADIUS
Definition: main.h:30
#define ARRAY_NB(a)
Definition: utils.h:30