#include "HumanParsing.h" #include //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 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; }