STM32N6 NPU Deployment — Politecnico di Milano  1.0
Documentation for Neural Network Deployment on STM32N6 NPU - Politecnico di Milano 2024-2025
display_spe.c
Go to the documentation of this file.
1 
19 #include "display_spe.h"
20 #include "app_config.h"
21 #include "main.h"
22 #if POSTPROCESS_TYPE == POSTPROCESS_SPE_MOVENET_UF
23  #if AI_POSE_PP_POSE_KEYPOINTS_NB == 17
24  #include "display_keypoints_17.h"
25  #elif AI_POSE_PP_POSE_KEYPOINTS_NB == 13
26  #include "display_keypoints_13.h"
27  #else
28  #error "Unsupported number of keypoints"
29  #endif
30 #endif
31 #include "utils.h"
32 #include <assert.h>
33 #include <stdlib.h>
34 #include <stdint.h>
35 
36 static int (*clamp_point)(int *x, int *y);
37 static void (*convert_length)(float32_t wi, float32_t hi, int *wo, int *ho);
38 static void (*convert_point)(float32_t xi, float32_t yi, int *xo, int *yo);
39 static void (*Display_binding_line)(int x0, int y0, int x1, int y1, uint32_t color);
40 
41 static void Display_keypoint(spe_pp_outBuffer_t *key, uint32_t color)
42 {
43  int is_clamp;
44  int xc, yc;
45  int x, y;
46 
47  if (key->proba < AI_POSE_PP_CONF_THRESHOLD)
48  return ;
49 
50  convert_point(key->x_center, key->y_center, &x, &y);
51  xc = x - CIRCLE_RADIUS / 2;
52  yc = y - CIRCLE_RADIUS / 2;
53  is_clamp = clamp_point(&xc, &yc);
54  xc = x + CIRCLE_RADIUS / 2;
55  yc = y + CIRCLE_RADIUS / 2;
56  is_clamp |= clamp_point(&xc, &yc);
57 
58  if (is_clamp)
59  return ;
60 
61  UTIL_LCD_FillCircle(x, y, CIRCLE_RADIUS, color);
62 }
63 
64 static void Display_binding(spe_pp_outBuffer_t *from, spe_pp_outBuffer_t *to, uint32_t color)
65 {
66  int is_clamp;
67  int x0, y0;
68  int x1, y1;
69  int i;
70 
71  assert(BINDING_WIDTH % 2 == 1);
72 
73  if (from->proba < AI_POSE_PP_CONF_THRESHOLD)
74  return ;
75  if (to->proba < AI_POSE_PP_CONF_THRESHOLD)
76  return ;
77 
78  convert_point(from->x_center, from->y_center, &x0, &y0);
79  is_clamp = clamp_point(&x0, &y0);
80  if (is_clamp)
81  return ;
82 
83  convert_point(to->x_center, to->y_center, &x1, &y1);
84  is_clamp = clamp_point(&x1, &y1);
85  if (is_clamp)
86  return ;
87 
88  UTIL_LCD_DrawLine(x0, y0, x1, y1, color);
89  for (i = 1; i <= (BINDING_WIDTH - 1) / 2; i++) {
90  if (abs(y1 - y0) > abs(x1 - x0)) {
91  Display_binding_line(x0 + i, y0, x1 + i , y1, color);
92  Display_binding_line(x0 - i, y0, x1 - i , y1, color);
93  } else {
94  Display_binding_line(x0, y0 + i, x1 , y1 + i, color);
95  Display_binding_line(x0, y0 - i, x1 , y1 - i, color);
96  }
97  }
98 }
99 
100 void Display_spe_InitFunctions(int clamp_point_init(int *x, int *y),
101  void convert_length_init(float32_t wi, float32_t hi, int *wo, int *ho),
102  void convert_point_init(float32_t xi, float32_t yi, int *xo, int *yo),
103  void Display_binding_line_init(int x0, int y0, int x1, int y1, uint32_t color))
104 {
105  clamp_point = clamp_point_init;
106  convert_length = convert_length_init;
107  convert_point = convert_point_init;
108  Display_binding_line = Display_binding_line_init;
109 }
110 
111 void Display_spe_Detection(spe_pp_outBuffer_t *detect)
112 {
113  int i;
114 
115  for (i = 0; i < ARRAY_NB(bindings); i++)
116  Display_binding(&detect[bindings[i][0]], &detect[bindings[i][1]], bindings[i][2]);
117  for (i = 0; i < AI_POSE_PP_POSE_KEYPOINTS_NB; i++)
118  Display_keypoint(&detect[i], kp_color[i]);
119 }
Central configuration header for the STM32N6570-DK pose estimation firmware application.
static const int kp_color[13]
static const int bindings[][3]
static int(* clamp_point)(int *x, int *y)
Definition: display_spe.c:36
void Display_spe_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_spe.c:100
void Display_spe_Detection(spe_pp_outBuffer_t *detect)
Definition: display_spe.c:111
static void(* convert_length)(float32_t wi, float32_t hi, int *wo, int *ho)
Definition: display_spe.c:37
static void Display_binding(spe_pp_outBuffer_t *from, spe_pp_outBuffer_t *to, uint32_t color)
Definition: display_spe.c:64
static void(* Display_binding_line)(int x0, int y0, int x1, int y1, uint32_t color)
Definition: display_spe.c:39
static void Display_keypoint(spe_pp_outBuffer_t *key, uint32_t color)
Definition: display_spe.c:41
static void(* convert_point)(float32_t xi, float32_t yi, int *xo, int *yo)
Definition: display_spe.c:38
#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