HumanParsing.cpp
5.06 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
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
#include "HumanParsing.h"
#include <opencv2/opencv.hpp>
//static string head[] = { "长发", "短发", "其他" };
//static string head_color[] = { "黑", "白", "其他" };
//static string eye[] = { "未戴眼镜", "戴眼镜" };
//static string mouth[] = { "未戴口罩", "戴口罩" };
//static string up[] ={ "T恤/背心", "衬衫", "毛衣"," 外套" , "连衣裙", "其他" };
//static std::string up_color[] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "其他" };
//static string clothing_text[] = { "纯色", "碎花", "条纹/格子", "其他" };
//static string down[6] = { "长裤", "短裤", "长裙", "短裙", "连衣裙", "其他" };
//static std::string down_color[] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "其他" };
//static string bao[5] = { "无包", "有包" };
//static std::string sex[] = { "男", "女", "不明" };
//static std::string age[] = { "小孩", "成人", "不明" };
//static std::string viewpoint[] = { "正面","背面", "侧面" };
//static string dasan[2] = { "未打伞", "打伞" };
//static string child[2] = { "未抱小孩", "抱小孩" };
//static string personstate[5] = { "行走/站立", "奔跑", "蹲/坐", "推车", "其他" };
const int FIR_INDEX_SIZE = 16;
const int SEC_INDEX_SIZE[FIR_INDEX_SIZE] = { 3, 3, 2, 2, 6, 9, 4, 6, 9, 2, 3, 3, 3, 2, 2, 5 };
int HumanParsing_Init(void *&handle, int gpuid, char* auth_license)
{
hp_param param;
param.mode = DEVICE_GPU;
param.gpuid = gpuid;
param.engine = ENGINE_TENSORRT;
param.max_batch = 20;
param.serialize_file = "./serialize_file/HP";
param.auth_license = auth_license;
if (hp_init(&handle, param) != 0)
{
cout << "Init HP Failed!" << endl;
return FAILED;
}
return SUCCESS;
}
#include <fstream>
int HumanParsing_Process(void * handle, sy_img * batch_img, int batch_size, hp_analysis_res*& result)
{
for (int i = 0; i < batch_size; i++)
{
if (batch_img[i].data_ == NULL)
cout << i << " data null" << endl;
}
//cout << "begin HumanParsingProcessBatch" << endl;
hp_batch(handle, batch_img, batch_size, result);
for (int b = 0; b < batch_size; b++)
{
hp_analysis_res &cur_result = result[b];
for (int i = 0; i < FIR_INDEX_SIZE; i++)
{
if (cur_result.res_objs[i].res_index >= SEC_INDEX_SIZE[i])
{
cur_result.res_objs[i].res_index = 0;
}
}
}
//cout << "end HumanParsingProcessBatch" << endl;
//for (int b = 0; b < batch_size; b++)
//{
// ctools_result &cur_result = result[b];
// int big_class_count = cur_result.obj_count_;
// ctools_obj_result &index_score = cur_result.obj_results_[big_class_count];
// if (index_score.data_count_ != FIR_INDEX_SIZE * 2)
// {
// printf("wrong result.\n");
// break;
// }
// //for (int i = 0; i < FIR_INDEX_SIZE; i++)
// //{
// // //int resIndex = result[j][i].index;
// // int resIndex = index_score.data_[i * 2];
// // switch (i)
// // {
// // case 0:
// // cout << head[resIndex] << " ";
// // break;
// // case 1:
// // cout << head_color[resIndex] << " ";
// // break;
// // case 2:
// // cout << eye[resIndex] << " ";
// // break;
// // case 3:
// // cout << mouth[resIndex] << " ";
// // break;
// // case 4:
// // cout << up[resIndex] << " ";
// // break;
// // case 5:
// // cout << up_color[resIndex] << " ";
// // break;
// // case 6:
// // cout << clothing_text[resIndex] << " ";
// // break;
// // case 7:
// // cout << down[resIndex] << " ";
// // break;
// // case 8:
// // cout << down_color[resIndex] << " ";
// // break;
// // case 9:
// // cout << bao[resIndex] << " ";
// // break;
// // case 10:
// // cout << sex[resIndex] << " ";
// // break;
// // case 11:
// // cout << age[resIndex] << " ";
// // break;
// // case 12:
// // cout << viewpoint[resIndex] << " ";
// // break;
// // case 13:
// // cout << dasan[resIndex] << " ";
// // break;
// // case 14:
// // cout << child[resIndex] << " ";
// // break;
// // case 15:
// // cout << personstate[resIndex] << " ";
// // break;
// // default:
// // break;
// // }
// //}
// //cout << endl << endl;
//}
return SUCCESS;
}
int HumanParsing_Release(void *& handle)
{
if(handle)
hp_release(&handle);
return SUCCESS;
}