Blame view

src/VPT/snapshot_analysis/VehicleRecognition.cpp 3.4 KB
e30d6793   Zou XiKun   v0.0.1
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  #include "vehicle_recognition.h"
  #include <iostream>
  #include "sy_errorinfo.h"
  #include "vehicle_features.h"
  using namespace std;
  int VehicleRecognition_Init(void *&handle, char*dbpath, int gpuid)
  {
  	vr_param params;
      params.gpuid = gpuid;
      params.mode = DEVICE_GPU;
  	params.db_path = dbpath;
  	params.engine = ENGINE_TENSORRT;
  	params.max_batch = 20;
  	params.serialize_file = "./serialize_file/VR";
  //#ifdef _MSC_VER
  //	params.dbPath = "../../../../vehicleRecognition_MCaffeTmpBody/db/CarBodyFeature.db";
  //#else
  //    params.dbPath = "/home/mliu/project/Project_MultiVPT/Video-Platform/video_structure_20190131/VehicleRecognition_body/db/CarBodyFeature.db";
  //#endif
      int ret = vr_init(&handle, params);
      if (ret != 0)
      {
          cout << "VR Init Failed!" << endl;
          system("pause");
          return FAILED;
      }
  	return SUCCESS;
  }
  
  #include <fstream>
  int Vehicle_Recognition_Process(void *vhd_handle, void * vr_handle, sy_img * batch_img, int batchsize, vr_result *&vrresult)
  {
  	vhd_result * vhd_res = new vhd_result[batchsize]{};
  	vhd_features_process(vhd_handle, batch_img, batchsize, vhd_res);
  	for (int vhd_idx = 0; vhd_idx < batchsize; vhd_idx++)
  	{
  		vhd_result & result =  vhd_res[vhd_idx];
  		for (int i = 0; i < result.obj_count_; ++i)         //车头
  		{
  
  		}
  	}
  
  	delete[] vhd_res;
  }
  
  int VehicleRecognition_Process(void * handle,  sy_img * batch_img, int batchsize, vr_result *&vrresult)
  {
      //VR_Result *vr_result = new VR_Result[batchsize];
  	/*vrresult = new vr_result[batchsize];
      for (int i = 0; i < batchsize; i++)
      {
  		vrresult[i].vehicle_brand = new char[260];
  		vrresult[i].vehicle_subbrand = new char[260];
  		vrresult[i].vehicle_issue_year = new char[260];
  		vrresult[i].vehicle_type = new char[260];
  		vrresult[i].freight_ton = new char[260];
      }*/
  	for (int i = 0; i < batchsize; i++)
  	{
  		if (batch_img[i].data_ == NULL)
  			cout << i << " data null" << endl;
  	}
  	
  	//cout << "begin vr_batch" << endl;
  	vr_batch(handle, batch_img, batchsize, vrresult);
  	//cout << "end vr_batch" << endl;
     /* for (int i = 0; i < batchsize; i++)
      {
  		cout << i << ".识别结果:" << endl;
  		cout << "  识别置信度: " << vr_result[i].name_score << endl;
  		cout << "  车辆品牌 - " << vr_result[i].vehicleBrand << endl;
  		cout << "  车辆子品牌 - " << vr_result[i].vehicleSubBrand << endl;
  		cout << "  车辆年款 - " << vr_result[i].vehicleIssueYear << endl;
  		cout << "  车辆类型 - " << vr_result[i].vehicleType << endl;
  		cout << "  货车吨级 - " << vr_result[i].freightTon << endl;
  		cout << endl;
  
          if (vr_result[i].vehicleBrand != NULL)
          {
              delete[] vr_result[i].vehicleBrand;
              vr_result[i].vehicleBrand = NULL;
          }
          if (vr_result[i].vehicleSubBrand != NULL)
          {
              delete[] vr_result[i].vehicleSubBrand;
              vr_result[i].vehicleSubBrand = NULL;
          }
          if (vr_result[i].vehicleIssueYear != NULL)
          {
              delete[] vr_result[i].vehicleIssueYear;
              vr_result[i].vehicleIssueYear = NULL;
          }
          if (vr_result[i].vehicleType != NULL)
          {
              delete[] vr_result[i].vehicleType;
              vr_result[i].vehicleType = NULL;
          }
          if (vr_result[i].freightTon != NULL)
          {
              delete[] vr_result[i].freightTon;
              vr_result[i].freightTon = NULL;
          }
      }*/
  
  	return SUCCESS;
  }
  
  int VehicleRecognition_Release(void *& handle)
  {
  	if (handle)
  	vr_release(&handle);
  	return SUCCESS;
  }