-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathface_detect_mscale.c
executable file
·121 lines (111 loc) · 3.07 KB
/
face_detect_mscale.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "sdk_common.h"
#include "sz_face_module.h"
#include "sz_image_module.h"
#include "sz_license_module.h"
#include "sz_net_module.h"
static void usage(char** argv) {
printf(
"usage: %s [a:b] \n"
" -a face.jpg\n"
" -b facemodel\n",
argv[0]);
printf(
"for example:\n"
"%s -a face.jpg -b facemodel\n",
argv[0]);
}
int main(int argc, char** argv) {
char jpgFile[MAX_FILE_LEN + 1] = {0};
char modelFile[MAX_FILE_LEN + 1] = {0};
if (argc < 5) {
usage(argv);
return -1;
}
//解析参数
int bInvaildParam = 0;
int c;
while ((c = getopt(argc, argv, "a:b:")) != EOF) {
switch (c) {
case 'a':
strncpy(jpgFile, optarg, MAX_FILE_LEN);
break;
case 'b':
strncpy(modelFile, optarg, MAX_FILE_LEN);
break;
default:
bInvaildParam = 1;
break;
}
}
if (bInvaildParam || strlen(jpgFile) == 0 || strlen(modelFile) == 0 ||
(strstr(jpgFile, ".jpg") == NULL && strstr(jpgFile, ".jpeg") == NULL &&
strstr(jpgFile, ".png") == NULL)) {
usage(argv);
return -1;
}
SZ_RETCODE ret;
SZ_LICENSE_CTX* licenseCtx = NULL;
SZ_FACE_CTX* faceCtx = NULL;
ret = init_handles(modelFile, &faceCtx, &licenseCtx);
if (ret != SZ_RETCODE_OK) {
goto JUMP;
}
//创建一个图像句柄
SZ_IMAGE_CTX* imgCtx = NULL;
SZ_BOOL bOk = SZ_FALSE;
SZ_FLOAT compareScore = 0.0;
SZ_FACE_FEATURE* pFeature = NULL;
SZ_FACE_QUALITY quality;
SZ_INT32 featureLen = 0;
int faceCnt = 0;
SZ_FACE_DETECTION pFaceInfos[128];
// ********************
// 读入一张jpg人脸照片
// ********************
int width = 0, height = 0;
unsigned char* pBgrData = readImage(jpgFile, &width, &height);
if (pBgrData == NULL) {
printf("[ERR] Read jpgFile %s failed!\n", jpgFile);
goto JUMP;
}
// ********************
// create image handle
// ********************
imgCtx = SZ_IMAGE_CTX_create(width, height, SZ_IMAGETYPE_BGR);
if (imgCtx == NULL) {
printf("[ERR] Creat imageCtx failed!\n");
goto JUMP;
}
ret = SZ_IMAGE_setData(imgCtx, pBgrData, width, height);
if (ret != SZ_RETCODE_OK) {
printf("[ERR] setData failed!\n");
goto JUMP;
}
// ********************
// face detect in 1080P and save results to File
// ********************
struct timespec start, next, end;
long spend;
clock_gettime(0, &start);
ret = SZ_FACE_detectAndGetInfo_1080P(faceCtx, imgCtx, pFaceInfos, &faceCnt);
clock_gettime(0, &end);
spend = (end.tv_sec - start.tv_sec) * 1000 +
(end.tv_nsec - start.tv_nsec) / 1000000;
printf("\n[face detection]===== TIME SPEND: %ld ms =====\n", spend);
if (ret != SZ_RETCODE_OK || faceCnt <= 0) {
printf("[ERR] SZ_FACE_detect failed !\n");
} else {
saveDetection2File(jpgFile, pBgrData, width, height, 1080, faceCnt,
pFaceInfos);
}
JUMP:
SZ_LICENSE_CTX_release(licenseCtx);
SZ_IMAGE_CTX_release(imgCtx);
SZ_FACE_CTX_release(faceCtx);
return ret;
}