diff --git a/src/ai_platform/header.h b/src/ai_platform/header.h index 4d9dcf1..3c55003 100755 --- a/src/ai_platform/header.h +++ b/src/ai_platform/header.h @@ -136,6 +136,8 @@ enum ai_log_level { }; +typedef void(*ResultData_CALLBACK)(ObjectData obj); + //VPT初始化参数 typedef struct tsl_aiplatform_param { int gpuid; //指定显卡id @@ -145,6 +147,8 @@ typedef struct tsl_aiplatform_param { char *log_path; //日志文件路径 int log_days; //日志保存周期 double log_mem; //每个日志最大大小 + + ResultData_CALLBACK result_cbk; } tsl_aiplatform_param; #endif // __AI_PLATFORM_HEADER__ \ No newline at end of file diff --git a/src/ai_platform/mvpt.cpp b/src/ai_platform/mvpt.cpp index 8777108..9fabb8a 100755 --- a/src/ai_platform/mvpt.cpp +++ b/src/ai_platform/mvpt.cpp @@ -92,6 +92,8 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ m_devId = vptParam.gpuid; + m_result_cbk = vptParam.result_cbk; + string models_dir = vptParam.models_dir; VPTProcess_PARAM vparam; @@ -536,7 +538,7 @@ void CMultiSourceProcess::vehicle_locus_finished(const OBJ_KEY obj_key) { TaskInfo* info = m_task_manager.GetTaskInfo(obj_key.video_id); - string result_folder = info->result_folder + "/snapshot";//todo + string result_folder = info->result_folder + "/snapshot"; string result_folder_little = info->result_folder_little + "/snapshot_lite"; if (!result_folder.empty()) { @@ -578,7 +580,7 @@ void CMultiSourceProcess::vehicle_locus_finished(const OBJ_KEY obj_key) { bool bSaved = save_obj_pic(res_obj); if (bSaved) { - // todo 回调函数抛出结果给上层 + m_result_cbk(res_obj); } m_snapshot_reprocessing->release_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, true); diff --git a/src/ai_platform/mvpt.h b/src/ai_platform/mvpt.h index 9a506be..0aa50e9 100755 --- a/src/ai_platform/mvpt.h +++ b/src/ai_platform/mvpt.h @@ -92,6 +92,8 @@ private: JpegUtil jpegUtil; + ResultData_CALLBACK m_result_cbk; + void *skt_handle = nullptr;//授权 atlas_licence_check_param check_param;//授权 int check_label{-1};//授权 -1=未授权 0=授权 1=授权check日已经check成功(每月一次check) diff --git a/src/ai_platform/mvpt_process_assist.h b/src/ai_platform/mvpt_process_assist.h index 8561498..d7dae25 100755 --- a/src/ai_platform/mvpt_process_assist.h +++ b/src/ai_platform/mvpt_process_assist.h @@ -30,7 +30,6 @@ bool LegalArea(int maxArea, int lastArea, int left, int top, int right, int bott bool LegalMinArea(int width, int height, sy_rect min_box); void ExpandMargin(int direction_x, int direction_y, int boundary_w, int boundary_h, int &boundary_left, int &boundary_right, int &boundary_top, int &boundary_bottom); -void CreateResultFolder(char* resultFolder, const char* jointFolder); bool snapshot_legal_inarea(int width, int height); bool snapshot_legal_inarea(sy_rect algor_area, int left, int top, int right, int bottom); diff --git a/src/ai_platform/vpt_proj.cpp1 b/src/ai_platform/vpt_proj.cpp1 deleted file mode 100755 index 7cbd277..0000000 --- a/src/ai_platform/vpt_proj.cpp1 +++ /dev/null @@ -1,166 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "vpt.h" - -#include "acl/acl.h" -#include "acl/ops/acl_dvpp.h" - -#include "../decoder/interface/DecoderManager.h" -#include "../decoder/interface/utiltools.hpp" - -using namespace std; - -#define ACL_CALL(ret, expect, errCode)\ - do {\ - if (ret != expect) {\ - if (errCode == 0)\ - return ret;\ - else\ - return errCode;\ - }\ - } while(0) - - -string test_uri = "/home/huchunming/data/caishenkezhan.mp4"; - -queue memQueue; -mutex mem_mutex; - -static void postDecoded(const void * userPtr, DeviceMemory* devFrame){ - AbstractDecoder* decoder = (AbstractDecoder*)userPtr; - if (decoder!= nullptr) - { - } - - std::lock_guard l(mem_mutex); - memQueue.push(devFrame); - - // if(devFrame){ - // delete devFrame; - // devFrame = nullptr; - // } -} - -static void decode_finished_cbk(const void* userPtr){ - cout << "当前时间戳: " << UtilTools::get_cur_time_ms() << endl; -} - -static void createDvppDecoder(int index, char* devId){ - DecoderManager* pDecManager = DecoderManager::getInstance(); - MgrDecConfig config; - config.name = "dec" + to_string(index); - config.cfg.uri = test_uri; - config.cfg.post_decoded_cbk = postDecoded; - config.cfg.decode_finished_cbk = decode_finished_cbk; - config.cfg.force_tcp = true; - config.dec_type = DECODER_TYPE_DVPP; - - config.cfg.gpuid = devId; - - AbstractDecoder* decoder = pDecManager->createDecoder(config); - if (!decoder) - { - cout << "创建解码器失败" << endl; - return ; - } - pDecManager->setPostDecArg(config.name, decoder); - pDecManager->setFinishedDecArg(config.name, decoder); - pDecManager->startDecodeByName(config.name); -} - - -int main(){ - cout << vpt_get_version() << endl; - - vpt_param param; - - // param.modelNames = "vtp0716x.om"; - param.modelNames = "../models/vpt0715_310p.om"; - param.threshold = 0.4; - param.devId = 0; - param.isTrk = false; - - ACL_CALL(aclInit(nullptr), ACL_ERROR_NONE, 1); - ACL_CALL(aclrtSetDevice(param.devId), ACL_ERROR_NONE, 1); - aclrtContext ctx; - ACL_CALL(aclrtCreateContext(&ctx, param.devId), ACL_ERROR_NONE, 1); - - void* handle = nullptr; - int ret = vpt_init(&handle, param); - if(ret != 0){ - printf("init error \n"); - return -1; - } - - createDvppDecoder(0,"0"); - - DecoderManager* pDecManager = DecoderManager::getInstance(); - const int batchsize = 1; - int index = 0; - while (pDecManager->isRunning("dec0")) - { - if(index > 30){ - break; - } - if(memQueue.size() <= 0){ - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - continue; - } - - vector vec_mem; - - vector imgs; - - std::lock_guard l(mem_mutex); - for (int b = 0; b < batchsize; b++) { - DeviceMemory* mem = memQueue.front(); - sy_img img; - img.w_ = mem->getWidth(); - img.h_ = mem->getHeight(); - img.data_ = mem->getMem(); - imgs.push_back(img); - vec_mem.push_back(mem); - memQueue.pop(); - } - - if(vec_mem.size() <= 0){ - std::this_thread::sleep_for(std::chrono::milliseconds(3)); - continue; - } - - ACL_CALL(aclrtSetCurrentContext(ctx), ACL_ERROR_NONE, 1); - vpt_result* results; - int ret = vpt_batch(handle, imgs.data(), imgs.size(), &results); - - for(int batchIdx = 0; batchIdx < batchsize; batchIdx ++){ - printf("debug det num:%d\n",results[batchIdx].obj_count_); - } - - for(int i=0;i < vec_mem.size(); i++){ - DeviceMemory* mem = vec_mem[i]; - delete mem; - mem = nullptr; - } - vec_mem.clear(); - - index ++; - } - - pDecManager->closeDecoderByName("dec0"); - - pDecManager->closeAllDecoder(); - - ret = aclrtDestroyContext(ctx); - if(ret != ACL_ERROR_NONE){ - printf("aclrtDestroyContext failed ! \n"); - } - - - - aclFinalize(); -} \ No newline at end of file diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index b481781..598bf2d 100755 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -5,6 +5,7 @@ #include #include #include +#include using namespace std; @@ -154,19 +155,10 @@ string createTask(void *handle, int gi, bool bFlag = true){ return task_id_str; } - -// void test_snapshot(void *handle){ -// task_param tparam; -// tparam.ipc_url = "rtsp://admin:ad123456@192.168.60.165:554/cam/realmonitor?channel=1&subtype=0"; -// std::string task_id_str = "test_task_id_default" ; -// tparam.task_id = task_id_str.c_str(); - - -// const int result_code = screenshot_task(handle, tparam); -// if (result_code != 0) -// printf("[Error]: "); -// printf("--- task_id: %s result code: %d\n", tparam.task_id, result_code); -// } +void show_result(ObjectData obj) +{ + cout << obj.index << endl; +} void test_gpu(int gpuID){ tsl_aiplatform_param vptParam; @@ -179,6 +171,8 @@ void test_gpu(int gpuID){ vptParam.log_mem = 64 * 1024 * 1024; // 64MB. vptParam.log_path = "logs/main.log"; + vptParam.result_cbk = show_result; + void *handle; int flag = tsl_aiplatform_init(&handle, vptParam); if (0 != flag) {