VidClothes.cpp 1.81 KB
#include "VidClothes.h"

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

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

int VidClothes::init(int devId, std::string sdk_root){
    ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED);

    std::string model_path = sdk_root + "/models/vid_clothes/vidClothes0325_310P.om";

    vidclothes_param param;
    param.modelNames = (char*)model_path.data();
    param.thresld = 0.0;
    param.devId = devId;

    LOG_INFO("vidclothes_init start");
    int ret = vidclothes_init(&m_handle, param);
    if (ret != 0) {
        return -1;
	}

    LOG_INFO("vidclothes_init success");

    return SY_SUCCESS;
}

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

    vector<int> vec_color;

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

    int ret = SY_FAILED;

    do
    {
        ret = aclrtSetCurrentContext(ctx);
        if (SY_SUCCESS != ret) {
            printf("aclrtSetCurrentContext failed!");
            break;
        }

        ret = vidclothes_batch(m_handle, vec_img.data(), batchsize, results);
        if (SY_SUCCESS != ret) {
            printf("vidclothesClassification process failed!");
            break;
        }
        
        for(int batchIdx = 0;batchIdx<batchsize;batchIdx++) {    
            // printf("index:%d,confidence:%f\n",results[batchIdx].index,results[batchIdx].score);
            vec_color.push_back(results[batchIdx].index);
        }
    } while (0);

    if (results) {
        delete [] results;
    }

    return vec_color;
}

int VidClothes::release() {

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

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

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

    return SY_SUCCESS;
}