/
face_recognizer.hpp
296 lines (262 loc) · 11.9 KB
/
face_recognizer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#pragma once
#include "dl_variable.hpp"
#include "face_recognition_tool.hpp"
#include <vector>
using namespace dl;
/**
* @brief
*
* @tparam feature_t
*/
template<typename feature_t>
class FaceRecognizer
{
public:
/**
* @brief Construct a new Face Recognizer object
*
*/
FaceRecognizer();
/**
* @brief Destroy the Face Recognizer object
*
*/
virtual ~FaceRecognizer();
void *model;
/**
* @brief Set the face recognition threshold [-1, 1], default thresh: 0.55
* Note: If the similarity of two faces is greater than the threshold, they will be judged as the same person
*
* @param thresh
*/
void set_thresh(float thresh);
/**
* @brief Get the current threshold of recognizer.
*
* @return float current threshold.
*/
float get_thresh();
/**
* @brief Get the input shape of the recognizer.
*
* @return std::vector<int> the input shape of the recognizer.
*/
std::vector<int> get_input_shape();
/**
* @brief do forward
*
* @param model_input the input data of the face recognition model.
* Note: the input data should have been preprocessed.
* @return Tensor<feature_t>& the output of the face recognition model.
*/
Tensor<feature_t> &forward(Tensor<feature_t> &model_input);
/**
* @brief recognize face
*
* @param image_input the pointer of the input image with format bgr565.
* @param shape the shape of the input image
* @param landmarks face landmarks coordinates
* @return face_info_t the recognition result.
*/
face_info_t recognize(uint16_t *image_input, std::vector<int> shape, std::vector<int> &landmarks);
/**
* @brief recognize face
*
* @param image_input the pointer of the input image with format bgr565.
* @param shape the shape of the input image
* @param aligned_face the Tensor to store the intermeidate aligned face.
* @param landmarks face landmarks coordinates
* @return face_info_t the recognition result.
*/
face_info_t recognize(uint16_t *image_input, std::vector<int> shape, Tensor<uint8_t> &aligned_face, std::vector<int> &landmarks);
/**
* @brief recognize face
*
* @param image_input the Tensor of input image with format bgr888.
* @param landmarks face landmarks coordinates
* @return face_info_t the recognition result.
*/
face_info_t recognize(Tensor<uint8_t> &image_input, std::vector<int> &landmarks);
/**
* @brief recognize face
*
* @param image_input the Tensor of input image with format bgr888.
* @param aligned_face the Tensor to store the intermeidate aligned face.
* @param landmarks face landmarks coordinates
* @return face_info_t the recognition result.
*/
face_info_t recognize(Tensor<uint8_t> &image_input, Tensor<uint8_t> &aligned_face, std::vector<int> &landmarks);
/**
* @brief recognize face
*
* @param aligned_face the Tensor of the input aligned face with format bgr888.
* @return face_info_t the recognition result.
*/
face_info_t recognize(Tensor<uint8_t> &aligned_face);
/**
* @brief recognize the face embedding.
*
* @param emb the normalized face embbeding.
* @return face_info_t the recognition result.
*/
face_info_t recognize(Tensor<float> &emb);
/**
* @brief Get the index of the enrolled ids
*
* @return std::vector<int> a vector of face ids index
*/
std::vector<face_info_t> get_enrolled_ids();
/**
* @brief Get the face embedding
*
* @param id the face id index
* @return Tensor<float> the face embedding of the face id index.
* if there is no matched id return the embedding of last input image.
*/
Tensor<float> &get_face_emb(int id=-1);
/**
* @brief Get the number of enrolled id
*
* @return int the number of enrolled id
*/
int get_enrolled_id_num();
/**
* @brief enroll face id
*
* @param image_input the pointer of the input image with format bgr565.
* @param shape the shape of the input image
* @param landmarks face landmarks coordinates
* @param name name of the face id.
* @return int the face id index of the enrolled embedding.
*/
int enroll_id(uint16_t *image_input, std::vector<int> shape, std::vector<int> &landmarks, std::string name="", bool update_flash = false);
/**
* @brief enroll face id
*
* @param image_input the pointer of the input image with format bgr565.
* @param shape the shape of the input image
* @param aligned_face the Tensor to store the intermeidate aligned face.
* @param landmarks face landmarks coordinates
* @param name name of the face id.
* @param update_flash true: the enrolled ids will be stored to flash
* false: the enrolled ids will not be stored to flash
* @return int the face id index of the enrolled embedding.
*/
int enroll_id(uint16_t *image_input, std::vector<int> shape, Tensor<uint8_t> &aligned_face, std::vector<int> &landmarks, std::string name="", bool update_flash = false);
/**
* @brief enroll face id
*
* @param image_input the Tensor of input image with format bgr888.
* @param landmarks face landmarks coordinates
* @param name name of the face id.
* @param update_flash true: the enrolled ids will be stored to flash
* false: the enrolled ids will not be stored to flash
* @return int the face id index of the enrolled embedding.
*/
int enroll_id(Tensor<uint8_t> &image_input, std::vector<int> &landmarks, std::string name="", bool update_flash = false);
/**
* @brief enroll face id
*
* @param image_input the Tensor of input image with format bgr888.
* @param aligned_face the Tensor to store the intermeidate aligned face.
* @param landmarks face landmarks coordinates
* @param name name of the face id.
* @param update_flash true: the enrolled ids will be stored to flash
* false: the enrolled ids will not be stored to flash
* @return int the face id index of the enrolled embedding.
*/
int enroll_id(Tensor<uint8_t> &image_input, Tensor<uint8_t> &aligned_face, std::vector<int> &landmarks, std::string name="", bool update_flash = false);
/**
* @brief enroll face id
*
* @param aligned_face the Tensor of the input aligned face with format bgr888.
* @param name name of the face id.
* @param update_flash true: the enrolled ids will be stored to flash
* false: the enrolled ids will not be stored to flash
* @return int the face id index of the enrolled embedding.
*/
int enroll_id(Tensor<uint8_t> &aligned_face, std::string name="", bool update_flash = false);
/**
* @brief enroll the normalzied face embedding.
*
* @param emb the normalized face embbeding.
* @param name name of the face id.
* @param update_flash true: the enrolled ids will be stored to flash
* false: the enrolled ids will not be stored to flash
* @return int the face id index of the enrolled embedding.
*/
int enroll_id(Tensor<float> &emb, std::string name="", bool update_flash = false);
/**
* @brief delete the last enrolled face id.
* @param update_flash true: the ids will be updated to flash
* false: the ids will not be stored to flash
*
* @return int the number of remained face ids.
* if the face ids list is empty, return -1
*/
int delete_id(bool update_flash = false);
/**
* @brief delete the face id with id index.
*
* @param id face id index.
* @param update_flash true: the ids will be updated to flash
* false: the ids will not be stored to flash
* @return int the number of remained face ids.
* if there is no matched id return -1
*/
int delete_id(int id, bool update_flash = false);
/**
* @brief Set the enrolled ids
*
* @param ids the ids to be set
* @param update_flash true: the ids will be updated to flash
* false: the ids will not be stored to flash
* @return int the number of enrolled ids.
*/
int set_ids(std::vector<FaceID<float> *> &ids, bool update_flash = false);
/**
* @brief Set the enrolled ids from flash
*
* @return int the number of enrolled ids.
*/
int set_ids_from_flash();
/**
* @brief write the enrolled ids to flash
*
* @return int the number of enrolled ids.
*/
int write_ids_to_flash();
/**
* @brief Get the enrolled ids with name object
*
* @param name
* @return std::vector<face_info_t>
*/
std::vector<face_info_t> get_enrolled_ids_with_name(std::string name);
/**
* @brief Check whether the Flash partition is available
*
* @return int -2: the partition has not been set
* -1: the data in the flash does not match the current model.
* model_check_code: the Flash partition is available.
* number of ids in flash: The IDs in Flash and RAM does not sync.
*/
int check_partition();
/**
* @brief delete all the enrolled face ids.
* @param update_flash true: the ids will be updated to flash
* false: the ids will not be stored to flash
*
*/
void clear_id(bool update_flash = false);
/**
* @brief Set the partition for saving face ids to flash or reading face ids from flash.
*
* @param type esp_partition_type
* @param subtype esp_partition_subtype
* @param label the partition label
* @return int 0: set the partition failed
* 1: set the partition successfully
*/
int set_partition(esp_partition_type_t type, esp_partition_subtype_t subtype, const char *label);
};