4a273a4a
Hu Chunming
添加hcp和hp
|
1
|
#include "HumanCarAnalysis.h"
|
f258e1c8
Hu Chunming
添加非机动车驾乘信息
|
2
3
4
5
|
#include "human_car_parsing.h"
static std::vector<std::string> STANDARD_COLOR_TABLE = {"棕", "橙", "灰", "白", "粉", "紫", "红", "绿", "蓝", "银", "青", "黄", "黑", "多色", "其他"};
std::string human_car_color[] = {"黑" , "白" , "红", "黄", "蓝", "绿", "灰", "多色", "其他"};
|
4a273a4a
Hu Chunming
添加hcp和hp
|
6
7
8
9
10
11
12
13
14
15
|
HumanCarAnalysis::HumanCarAnalysis(/* args */)
{
}
HumanCarAnalysis::~HumanCarAnalysis()
{
release();
}
|
581a68a4
Hu Chunming
修正parse_road无返回值导...
|
16
|
int HumanCarAnalysis::init(int devId, std::string sdk_root){
|
4a273a4a
Hu Chunming
添加hcp和hp
|
17
18
19
|
ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED);
ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);
|
581a68a4
Hu Chunming
修正parse_road无返回值导...
|
20
21
|
std::string model_path = sdk_root + "/models/hcp/hcp211008_310p.om";
|
4a273a4a
Hu Chunming
添加hcp和hp
|
22
|
hcp_param param;
|
581a68a4
Hu Chunming
修正parse_road无返回值导...
|
23
|
param.modelNames = (char*)model_path.data();
|
4a273a4a
Hu Chunming
添加hcp和hp
|
24
25
|
param.devId = devId;
|
e3062370
Hu Chunming
优化日志
|
26
|
LOG_INFO("hcp_init start");
|
4a273a4a
Hu Chunming
添加hcp和hp
|
27
28
29
30
31
|
int ret = hcp_init(&m_handle, param);
if (ret != 0) {
return -1;
}
|
e3062370
Hu Chunming
优化日志
|
32
|
LOG_INFO("hcp_init success");
|
4a273a4a
Hu Chunming
添加hcp和hp
|
33
34
35
36
|
return SY_SUCCESS;
}
|
f258e1c8
Hu Chunming
添加非机动车驾乘信息
|
37
38
39
40
41
42
43
44
45
46
47
48
|
int get_standard_color(int index) {
int index_standard = -1;
string str_color = human_car_color[index];
for (size_t i = 0; i < STANDARD_COLOR_TABLE.size(); i++) {
if(STANDARD_COLOR_TABLE[i] == str_color) {
index_standard = i;
break;
}
}
return index_standard;
}
|
81e8a405
Hu Chunming
初步完成SDK
|
49
|
std::vector<HumanCarResult> HumanCarAnalysis::detect(vector<sy_img> vec_img){
|
4a273a4a
Hu Chunming
添加hcp和hp
|
50
|
|
81e8a405
Hu Chunming
初步完成SDK
|
51
|
std::vector<HumanCarResult> vec_result;
|
4a273a4a
Hu Chunming
添加hcp和hp
|
52
53
54
55
56
57
58
59
|
const int batchsize = vec_img.size();
hcp_analysis_result * results = new hcp_analysis_result[batchsize];
int ret = SY_FAILED;
do
{
|
81e8a405
Hu Chunming
初步完成SDK
|
60
61
62
63
64
65
|
ret = aclrtSetCurrentContext(ctx);
if (SY_SUCCESS != ret) {
printf("aclrtSetCurrentContext failed!");
break;
}
|
4a273a4a
Hu Chunming
添加hcp和hp
|
66
67
|
ret = hcp_batch(m_handle, vec_img.data(), batchsize, results);
if (SY_SUCCESS != ret) {
|
f171c20a
Hu Chunming
添加moter_rainshed ...
|
68
|
printf("hcp_batch failed!");
|
4a273a4a
Hu Chunming
添加hcp和hp
|
69
70
71
72
|
break;
}
for(int batchIdx = 0;batchIdx<batchsize;batchIdx++){
|
a1a053f2
Hu Chunming
修正人骑车逻辑错误
|
73
74
75
76
77
78
79
80
81
82
83
|
HumanCarResult one_result;
one_result.head = results[batchIdx].res_objs[0].res_index;
one_result.head_prob = results[batchIdx].res_objs[0].res_prob;
one_result.eye = results[batchIdx].res_objs[1].res_index;
one_result.eye_prob = results[batchIdx].res_objs[1].res_prob;
one_result.mouth = results[batchIdx].res_objs[2].res_index;
one_result.mouth_prob = results[batchIdx].res_objs[2].res_prob;
one_result.weibo = results[batchIdx].res_objs[3].res_index;
one_result.weibo_prob = results[batchIdx].res_objs[3].res_prob;
one_result.up_wear = results[batchIdx].res_objs[4].res_index;
one_result.up_wear_prob = results[batchIdx].res_objs[4].res_prob;
|
f258e1c8
Hu Chunming
添加非机动车驾乘信息
|
84
|
one_result.up_color = get_standard_color(results[batchIdx].res_objs[5].res_index);
|
a1a053f2
Hu Chunming
修正人骑车逻辑错误
|
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
one_result.up_color_prob = results[batchIdx].res_objs[5].res_prob;
one_result.up_tex = results[batchIdx].res_objs[6].res_index;
one_result.up_tex_prob = results[batchIdx].res_objs[6].res_prob;
one_result.bag = results[batchIdx].res_objs[7].res_index;
one_result.bag_prob = results[batchIdx].res_objs[7].res_prob;
one_result.sex = results[batchIdx].res_objs[8].res_index;
one_result.sex_prob = results[batchIdx].res_objs[8].res_prob;
one_result.age = results[batchIdx].res_objs[9].res_index;
one_result.age_prob = results[batchIdx].res_objs[9].res_prob;
one_result.carColor = results[batchIdx].res_objs[10].res_index;
one_result.carColor_prob = results[batchIdx].res_objs[10].res_prob;
one_result.orient = results[batchIdx].res_objs[11].res_index;
one_result.orient_prob = results[batchIdx].res_objs[11].res_prob;
one_result.dasan = results[batchIdx].res_objs[12].res_index;
one_result.dasan_prob = results[batchIdx].res_objs[12].res_prob;
one_result.take = results[batchIdx].res_objs[13].res_index;
one_result.take_prob = results[batchIdx].res_objs[13].res_prob;
vec_result.push_back(one_result);
|
4a273a4a
Hu Chunming
添加hcp和hp
|
104
105
106
107
108
109
110
|
}
} while (0);
if (results) {
delete [] results;
}
|
81e8a405
Hu Chunming
初步完成SDK
|
111
|
return vec_result;
|
4a273a4a
Hu Chunming
添加hcp和hp
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
}
int HumanCarAnalysis::release() {
ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);
if (m_handle) {
hcp_release(&m_handle);
}
if(ctx){
aclrtDestroyContext(ctx);
ctx = nullptr;
}
return SY_SUCCESS;
}
|