forked from opendr-eu/opendr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface_recognition.h
110 lines (92 loc) · 3.54 KB
/
face_recognition.h
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
/*
* Copyright 2020-2024 OpenDR European Project
*
* 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 C_API_FACE_RECOGNITION_H
#define C_API_FACE_RECOGNITION_H
#include "opendr_utils.h"
#include "target.h"
#ifdef __cplusplus
extern "C" {
#endif
struct FaceRecognitionModel {
// ONNX session objects
void *onnxSession;
void *env;
void *sessionOptions;
// Sizes for resizing and cropping an input image
int modelSize;
int resizeSize;
// Statistics for normalization
float meanValue;
float stdValue;
// Recognition threshold
float threshold;
// Feature dimension
int outputSize;
// Database data
void *database;
int *databaseIds;
char **personNames;
// Number of persons in the database
int nPersons;
// Number of features vectors in the database
int nFeatures;
};
typedef struct FaceRecognitionModel FaceRecognitionModelT;
/**
* Loads a face recognition model saved in OpenDR format.
* @param modelPath path to the OpenDR face recognition model (as exported using OpenDR library)
* @param model the loaded model
*/
void loadFaceRecognitionModel(const char *modelPath, FaceRecognitionModelT *model);
/**
* This function perform inference using a face recognition model and an input image.
* @param model face recognition model to be used for inference
* @param image OpenDR image
* @return OpenDR classification target containing the id of the recognized person
*/
OpenDRCategoryTargetT inferFaceRecognition(FaceRecognitionModelT *model, OpenDRImageT *image);
/**
* Builds a face recognition database (containing images for persons to be recognized). This function expects the
* databaseFolder to have the same format as the main Python toolkit.
* @param databaseFolder folder containing the database
* @param outputPath output path to store the binary database. This file should be loaded along with the face
* recognition model before performing inference.
* @param model the face recognition model to be used for extracting the database features
*/
void buildDatabaseFaceRecognition(const char *databaseFolder, const char *outputPath, FaceRecognitionModelT *model);
/**
* Loads an already built database into the face recognition model. After this step, the model can be used for
* performing inference.
* @param databasePath path to the database file
* @param model the face recognition model to be used for inference
*/
void loadDatabaseFaceRecognition(const char *databasePath, FaceRecognitionModelT *model);
/**
* Returns the name of a recognition person by decoding the category id into a string.
* @param model the face recognition model to be used for inference
* @param category the predicted category
* @param personName buffer to store the person name
*/
void decodeCategoryFaceRecognition(FaceRecognitionModelT *model, OpenDRCategoryTargetT category, char *personName);
/**
* Releases the memory allocated for a face recognition model.
* @param model model to be de-allocated
*/
void freeFaceRecognitionModel(FaceRecognitionModelT *model);
#ifdef __cplusplus
}
#endif
#endif // C_API_FACE_RECOGNITION_H