HumanCarParsing.cpp 4.1 KB
#include "HumanCarParsing.h"
#include <cuda.h>
#include <cuda_runtime.h>
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"

#include "depend_inc.h"

//string up[12] = { "T恤", "马甲/吊带/背心", "衬衫", "西服", "毛衣", "皮衣/夹克", "羽绒服", "大衣/风衣", "外套", "连衣裙", "无上衣", "其他" };
//string up_color[12] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他" };
//string down[6] = { "长裤", "短裤", "长裙", "短裙", "连衣裙", "其他" };
//string down_color[12] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他" };
//string bao[5] = { "无包", "单肩包", "双肩包", "其他", "钱包" };
//string bag_color[12] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他" };
//string head[6] = { "长发", "短发", "光头", "帽子", "头盔", "其他" };
//string clothing_text[5] = { "纯色", "碎花", "条纹", "格子", "其他" };
//string sex[3] = { "男", "女", "不明" };
//string figure[3] = { "胖", "瘦", "中" };
//string nationality[5] = { "汉族", "维族", "黑人", "白人", "其他" };
//string age[6] = { "幼儿", "儿童", "青年", "中年", "老年", "不明" };
//string eye[4] = { "正常眼睛", "眼镜", "墨镜", "其他" };
//string mouth[3] = { "正常嘴", "戴口罩", "其他" };
//string weibo[3] = { "无围巾", "普通围巾", "包头围巾" };
//
//string carColor[13] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他", "银" };
//string orient[3] = { "正面", "背面", "侧面" };
//string drivenum[4] = { "0人", "1人", "2人", "更多人" };
//string dasan[2] = { "无", "有" };
//string take[2] = { "无", "物品" };

//static std::string hcp_head[] = { "长发", "短发", "头盔", "其他" };
//static std::string hcp_eye[] = { "未戴眼镜", "戴眼镜" };
//static std::string hcp_mouth[] = { "未戴口罩", "戴口罩" };
//static std::string hcp_weibo[] = { "未带围巾", "带围巾" };
//static std::string hcp_up[] = { "T恤/背心", "衬衫", "毛衣", "外套", "连衣裙", "其他" };
//static std::string hcp_up_color[] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "不明" };
//static std::string hcp_clothing_text[] = { "纯色", "碎花", "条纹格子", "其他" };
//static std::string hcp_bao[] = { "无包", "背包" };
//static std::string hcp_sex[] = { "男", "女", "不明" };
//static std::string hcp_age[] = { "小孩", "成人", "不明" };
//static std::string hcp_carColor[] = { "黑", "白", "红", "其他" };
//static std::string hcp_orient[] = { "正面", "背面", "侧面" };
//static std::string hcp_dasan[] = { "无", "有" };
//static std::string hcp_take[] = { "无", "有" };

const int FIR_INDEX_SIZE = 14;
const int SEC_INDEX_SIZE[FIR_INDEX_SIZE] = {4,2,2,2,6,9,4,2,3,3,4,3,2,2 };

HumanCarParsing::HumanCarParsing(){

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

int HumanCarParsing::init(int gpuid, char* auth_license)
{
    hcp_param param;
	param.mode = DEVICE_GPU;
	param.gpuid = gpuid;
	param.engine = ENGINE_TENSORRT;
	param.serialize_file = "./serialize_file/HCP";
	param.max_batch = 20;
	if (hcp_init(&handle, param) != 0)
	{
        LOG_ERROR("hcp_init Failed!");
		return FAILED;
	}
    
    LOG_INFO("hcp_init success! gpu_id: {}", gpuid);
	return SUCCESS;
}

int HumanCarParsing::process(sy_img * batch_img, int batch_size, hcp_analysis_result *result)
{
    // LOG_DEBUG("batch_size: {}", batch_size);
	hcp_batch(handle, batch_img, batch_size, result);

	for (int b = 0; b < batch_size; b++)
	{
		hcp_analysis_result &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 HumanCarParsing::release()
{
	if(handle) {
        hcp_release(&handle);
        handle = nullptr;
    }

    LOG_INFO("hcp_release");
	return SUCCESS;
}