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


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

HumanParsing::~HumanParsing()
{
    release();
}


int HumanParsing::init(int dev_id, string model_dir){

    string model_path = model_dir + "/models/hp2/hp220908_310p.om" ;

    LOG_INFO("hp 版本:{}  模型路径:{}", hp_get_version(), model_path);

    hp_param param;
    char modelNames[100];
    strcpy(modelNames, model_path.c_str());
    param.modelNames = modelNames;
    param.devId = dev_id;

    m_devId = param.devId;
    ACL_CALL(aclrtSetDevice(m_devId), ACL_SUCCESS, -1);
    ACL_CALL(aclrtCreateContext(&m_algorthim_ctx, m_devId), ACL_SUCCESS, -1);

    int ret = hp_init(&m_handle, param);
    if(ret != 0){
        LOG_ERROR("vpt init error.");
        return -1;
    }

    return 0;
}

vector<hp_analysis_res> HumanParsing::process(vector<DeviceMemory*> vec_gpuMem) {

    int batchsize = vec_gpuMem.size();

    vector<sy_img> batch_img;
    for (int i = 0; i < batchsize; i++) {
        DeviceMemory* mem = vec_gpuMem[i];

        sy_img img;
        img.w_ = mem->getWidth();     
        img.h_ = mem->getHeight();
        img.c_ = mem->getChannel();   
        img.data_ = mem->getMem();
        batch_img.push_back(img);
    }

    vector<hp_analysis_res> vec_result;
    vec_result.resize(batchsize);
    int ret = hp_batch(m_handle, batch_img.data(), batchsize, vec_result.data());
    if (SY_SUCCESS != ret) {
        printf("HumanCarParse process failed!");
        return vec_result;
    }

    return vec_result;
}

void HumanParsing::release(){
    if (m_handle){
        hp_release(&m_handle);
        m_handle = NULL;
    }
    if(m_algorthim_ctx){
        aclrtDestroyContext(m_algorthim_ctx);
    }
}