HumanParsing.cpp 2.69 KB
#include "HumanParsing.h"

#include <opencv2/opencv.hpp>

#include "depend_inc.h"


//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 };


HumanParsing::HumanParsing(/* args */)
{
}

HumanParsing::~HumanParsing()
{
    LOG_INFO("~HumanParsing");
}

int HumanParsing::init(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) {
        LOG_ERROR("hp_init failed!");
		return FAILED;
	}
 
    LOG_INFO("hp_init success! gpu_id: {}", gpuid);
	return SUCCESS;
}

int HumanParsing::process(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) {
            LOG_ERROR("data null!");
            return FAILED;
        }
	}

	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;
				
			}
		}
	}

	return SUCCESS;
}

int HumanParsing::release()
{
	if(handle) {
        hp_release(&handle);
        handle = nullptr;
    }
	
    LOG_INFO("hp_release");
	return SUCCESS;
}