MSRegionSurveilanceHst.cpp 1.96 KB
#include "MSRegionSurveilanceHst.h"
#include "head_shoulder_det.h"
#include "sy_errorinfo.h"
#include <cuda.h>
#include <cuda_runtime.h>


int IRegionSurveillanceHst::init(const rs_param & param)
{
	hs_det_param hsparam;
	hsparam.gpuid = 0;
	hsparam.mode = DEVICE_GPU;
	hsparam.thresld = 0.5;
	hsparam.engine = ENGINE_MCAFFE2;
	hsparam.max_batch = 10;
	hsparam.trt_serialize_file = "HSD";
	if (hs_det_init(&hst_handle, &hsparam))
	{
		printf("hs_det_init failed!\n");
		return VPT_DET_INIT_ERROR;
	}
	printf("finish init hst\n");
	AddTaskTracker(0, 1, 1);
	return 0;
}

int IRegionSurveillanceHst::detect(const sy_img &img_data, VPT_Result & vptResult)
{
	vector<int> deleteObjectID;
	hs_det_result * hsresult = new hs_det_result{};
	hsresult->objcount = 0;
	sy_img batch_img_gpu;
	unsigned char * data = NULL;
	cudaMalloc(&data, img_data.w_ *img_data.h_*img_data.c_ * sizeof(unsigned char));
	cudaMemcpy(data, img_data.data_, img_data.w_ *img_data.h_ * img_data.c_ * sizeof(unsigned char), cudaMemcpyHostToDevice);
	batch_img_gpu.set_data(img_data.w_, img_data.h_, img_data.c_, data);
	auto ret = hs_det_process_batch(hst_handle, &batch_img_gpu, 1, hsresult);
	cudaFree(data);
	std::vector<std::vector<float>> detectResult;
	for (int c = 0; c < hsresult->objcount&& c < MAX_OBJ_COUNT; c++)
	{
		vector <float> obj;

		obj.push_back(hsresult->objinfo[c].left);
		obj.push_back(hsresult->objinfo[c].top);
		obj.push_back(hsresult->objinfo[c].right);
		obj.push_back(hsresult->objinfo[c].bottom);
		obj.push_back(hsresult->objinfo[c].confidence);
		obj.push_back(0);
		detectResult.push_back(obj);
	}

	int objCount = taskTrackers.tracker.update(/*tools->param.w*/img_data.w_* taskTrackers.ratioWidth, /*tools->param.h*/img_data.h_* taskTrackers.ratioHeight, true, detectResult, vptResult.obj, deleteObjectID);
	vptResult.objCount = objCount;
	delete hsresult;
	return ret;
}

void IRegionSurveillanceHst::release()
{
	//1.VPT RELEASE
	if (hst_handle)
	{
		hs_det_release(&hst_handle);
		hst_handle = NULL;
	}
}