-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathsample_create_session.c
More file actions
131 lines (114 loc) · 5.2 KB
/
sample_create_session.c
File metadata and controls
131 lines (114 loc) · 5.2 KB
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
/**
* Created by InspireFace
* @date 2025-06-22
* Sample code for creating InspireFace session with all features enabled
*/
#include <stdio.h>
#include <stdlib.h>
#include <inspireface.h>
int main(int argc, char* argv[]) {
HResult ret;
const char* packPath;
HOption option;
HFDetectMode detMode;
HInt32 maxDetectNum;
HInt32 detectPixelLevel;
HFSession session;
HFFaceDetectPixelList pixelLevels;
packPath = argv[1];
HFLogPrint(HF_LOG_INFO, "Pack file Path: %s", packPath);
/* Set log level to debug for detailed output */
HFSetLogLevel(HF_LOG_DEBUG);
/* The resource file must be loaded before it can be used */
ret = HFLaunchInspireFace(packPath);
if (ret != HSUCCEED) {
HFLogPrint(HF_LOG_ERROR, "Load Resource error: %d", ret);
return ret;
}
HFLogPrint(HF_LOG_INFO, "Resource loaded successfully");
/* Query supported pixel levels for face detection */
ret = HFQuerySupportedPixelLevelsForFaceDetection(&pixelLevels);
if (ret != HSUCCEED) {
HFLogPrint(HF_LOG_ERROR, "HFQuerySupportedPixelLevelsForFaceDetection error: %d", ret);
return ret;
}
HFLogPrint(HF_LOG_INFO, "Supported pixel levels for face detection: %d", pixelLevels.size);
for (int i = 0; i < pixelLevels.size; i++) {
HFLogPrint(HF_LOG_INFO, "Supported pixel level %d: %d", i + 1, pixelLevels.pixel_level[i]);
}
/* Enable ALL available functions in the pipeline */
option = HF_ENABLE_FACE_RECOGNITION | // Face recognition
HF_ENABLE_LIVENESS | // RGB liveness detection
HF_ENABLE_IR_LIVENESS | // IR liveness detection
HF_ENABLE_MASK_DETECT | // Mask detection
HF_ENABLE_FACE_ATTRIBUTE | // Face attribute prediction
HF_ENABLE_QUALITY | // Face quality assessment
HF_ENABLE_INTERACTION | // Interaction feature
HF_ENABLE_FACE_POSE | // Face pose estimation
HF_ENABLE_FACE_EMOTION; // Face emotion recognition
HFLogPrint(HF_LOG_INFO, "Enabled features:");
HFLogPrint(HF_LOG_INFO, "- Face Recognition: YES");
HFLogPrint(HF_LOG_INFO, "- RGB Liveness Detection: YES");
HFLogPrint(HF_LOG_INFO, "- IR Liveness Detection: YES");
HFLogPrint(HF_LOG_INFO, "- Mask Detection: YES");
HFLogPrint(HF_LOG_INFO, "- Face Attributes: YES");
HFLogPrint(HF_LOG_INFO, "- Face Quality: YES");
HFLogPrint(HF_LOG_INFO, "- Interaction: YES");
HFLogPrint(HF_LOG_INFO, "- Face Pose: YES");
HFLogPrint(HF_LOG_INFO, "- Face Emotion: YES");
/* Set detection mode - use light track for general purpose */
detMode = HF_DETECT_MODE_LIGHT_TRACK;
HFLogPrint(HF_LOG_INFO, "Detection mode: HF_DETECT_MODE_LIGHT_TRACK");
/* Maximum number of faces to detect */
maxDetectNum = 20;
HFLogPrint(HF_LOG_INFO, "Maximum faces to detect: %d", maxDetectNum);
/* Face detection image input level */
detectPixelLevel = 320;
HFLogPrint(HF_LOG_INFO, "Detection pixel level: %d", detectPixelLevel);
/* Create InspireFace session with all features enabled */
session = NULL;
ret = HFCreateInspireFaceSessionOptional(option, detMode, maxDetectNum, detectPixelLevel, -1, &session);
if (ret != HSUCCEED) {
HFLogPrint(HF_LOG_ERROR, "Create InspireFace session error: %d", ret);
return ret;
}
HFLogPrint(HF_LOG_INFO, "InspireFace session created successfully");
/* Configure session parameters */
ret = HFSessionSetTrackPreviewSize(session, detectPixelLevel);
if (ret != HSUCCEED) {
HFLogPrint(HF_LOG_ERROR, "Set track preview size error: %d", ret);
} else {
HFLogPrint(HF_LOG_INFO, "Track preview size set to: %d", detectPixelLevel);
}
ret = HFSessionSetFilterMinimumFacePixelSize(session, 4);
if (ret != HSUCCEED) {
HFLogPrint(HF_LOG_ERROR, "Set minimum face pixel size error: %d", ret);
} else {
HFLogPrint(HF_LOG_INFO, "Minimum face pixel size set to: 4");
}
/* Session is now ready for use */
HFLogPrint(HF_LOG_INFO, "========================================");
HFLogPrint(HF_LOG_INFO, "Session created successfully with ALL features enabled!");
HFLogPrint(HF_LOG_INFO, "You can now use this session for:");
HFLogPrint(HF_LOG_INFO, "- Face detection and tracking");
HFLogPrint(HF_LOG_INFO, "- Face recognition");
HFLogPrint(HF_LOG_INFO, "- Liveness detection (RGB & IR)");
HFLogPrint(HF_LOG_INFO, "- Mask detection");
HFLogPrint(HF_LOG_INFO, "- Face attribute analysis");
HFLogPrint(HF_LOG_INFO, "- Face quality assessment");
HFLogPrint(HF_LOG_INFO, "- Interaction detection");
HFLogPrint(HF_LOG_INFO, "- Face pose estimation");
HFLogPrint(HF_LOG_INFO, "- Emotion recognition");
HFLogPrint(HF_LOG_INFO, "========================================");
/* Clean up resources */
ret = HFReleaseInspireFaceSession(session);
if (ret != HSUCCEED) {
HFLogPrint(HF_LOG_ERROR, "Release session error: %d", ret);
return ret;
}
HFLogPrint(HF_LOG_INFO, "Session released successfully");
/* Show resource statistics */
HFLogPrint(HF_LOG_INFO, "");
HFDeBugShowResourceStatistics();
return 0;
}