Blame view

src/MSRegionSurveilance/MSRegionSurveilanceHst.cpp 1.96 KB
8805b950   Liu Meng   物品遗留效果优化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  #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;
  	}
  }