#include "HumanCarAnalysis.h" #include "human_car_parsing.h" static std::vector STANDARD_COLOR_TABLE = {"棕", "橙", "灰", "白", "粉", "紫", "红", "绿", "蓝", "银", "青", "黄", "黑", "多色", "其他"}; std::string human_car_color[] = {"黑" , "白" , "红", "黄", "蓝", "绿", "灰", "多色", "其他"}; HumanCarAnalysis::HumanCarAnalysis(/* args */) { } HumanCarAnalysis::~HumanCarAnalysis() { release(); } int HumanCarAnalysis::init(int devId, std::string sdk_root){ ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED); ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED); std::string model_path = sdk_root + "/models/hcp/hcp211008_310p.om"; hcp_param param; param.modelNames = (char*)model_path.data(); param.devId = devId; LOG_INFO("hcp_init start"); int ret = hcp_init(&m_handle, param); if (ret != 0) { return -1; } LOG_INFO("hcp_init success"); return SY_SUCCESS; } 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; } std::vector HumanCarAnalysis::detect(vector vec_img){ std::vector vec_result; const int batchsize = vec_img.size(); hcp_analysis_result * results = new hcp_analysis_result[batchsize]; int ret = SY_FAILED; do { ret = aclrtSetCurrentContext(ctx); if (SY_SUCCESS != ret) { printf("aclrtSetCurrentContext failed!"); break; } ret = hcp_batch(m_handle, vec_img.data(), batchsize, results); if (SY_SUCCESS != ret) { printf("hcp_batch failed!"); break; } for(int batchIdx = 0;batchIdx