HumanCarAnalysis.cpp 1.69 KB
#include "HumanCarAnalysis.h"

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

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

int HumanCarAnalysis::init(int devId){
    ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED);
    ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);

    hcp_param param;
    param.modelNames = "./models/hcp/hcp211008_310p.om";
    param.devId = devId;

    cout << "hcp_init start " << endl;
    int ret = hcp_init(&m_handle, param);
    if (ret != 0) {
        return -1;
	}

    cout << "hcp_init success " << endl;

    return SY_SUCCESS;
}

int HumanCarAnalysis::detect(vector<sy_img> vec_img){

    ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);

    const int batchsize = vec_img.size();
    hcp_analysis_result * results = new hcp_analysis_result[batchsize];

    int ret = SY_FAILED;

    do
    {
        ret = hcp_batch(m_handle, vec_img.data(), batchsize, results);
        if (SY_SUCCESS != ret) {
            printf("vidclothesClassification process failed!");
            break;
        }
        
        for(int batchIdx = 0;batchIdx<batchsize;batchIdx++){ 
            for (int i = 0; i < HCP_ATTRI_INDEX_SIZE; i++) {   
                printf("hcp index:%d,confidence:%f\n",results[batchIdx].res_objs[i].res_index,results[batchIdx].res_objs[i].res_prob);
            }
        }
    } while (0);

    if (results) {
        delete [] results;
    }

    return ret;
}

int HumanCarAnalysis::release() {

    ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);	

    if (m_handle) {
        hcp_release(&m_handle);
    }

    if(ctx){
        aclrtDestroyContext(ctx);
        ctx = nullptr;
    }

    return SY_SUCCESS;
}