Blame view

src/vpt_det_demo/main.cppbk 2.63 KB
2434ed4a   Zou XiKun   trt 20210304
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
115
116
117
118
119
120
  #include "vpt.h"
  #include <highgui.h>
  #include <opencv2/opencv.hpp>
  #include <fstream>
  #include <iostream>
  #include "sy_common.h"
  #include "utools.h"
  
  #ifdef _WIN32
  #include<windows.h>
  #else
  #include <sys/time.h>
  #endif
  
  
  int main()
  {
  
  CvFont font;
  	cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0, 0, 1, 3);
  	int fontFace = CV_FONT_HERSHEY_COMPLEX;
  	double fontScale = 1;
  	int thickness = 2;
  	static std::string type[9] = { "person", "bike", "motor", "tricycle", "car", "bigbus", "lorry", "tractor", "midibus" };
   
  void* handle;
  
  	vpt_param param;
  	param.mode = DEVICE_GPU;
  	param.gpuid = 0;
  
  
  printf("begin vpt_init\n");
  vpt_init(&handle, param);
  printf("finish  vpt_init\n");
  
  const int batchsize = 10;
  
  
  /*³õʼ»¯½á¹û½á¹¹Ìå*/
  	vpt_result *result = new vpt_result[batchsize];
  	for (int b = 0; b < batchsize; b++)
  	{
  		result[b].obj_count_ = 0;
  		result[b].obj_results_ = new vpt_obj_result[MAX_DET_COUNT];
  	}
  
  	//CTOOLS_Img *images = new CTOOLS_Img[batchsize];
  	//cv::Mat img;
  	sy_img images[batchsize];
  	cv::Mat img[batchsize];
  
  	char strpath[1024];
  	memset(strpath, 0, sizeof(strpath));
  	for (int b = 0; b < batchsize; b++)
  	{
  #ifdef _MSC_VER
  		sprintf(strpath, "../../../data/%d.jpg", b);// b);
  #else
  		sprintf(strpath, "vpt_pic/%d.jpg", b);
  
  #endif
  
  		//cv::Mat img/*[b]*/;
  		//memset(&img, 0, sizeof(img));
  		img[b] = cv::imread(strpath);
  		images[b].SetData(img[b].cols, img[b].rows, img[b].channels(), img[b].data);
  
  	}
  
  
  //vpt_batch(handle, images, batchsize, &result);
  
  
  
  		vpt_batch(handle, images, batchsize, &result);
  
  
  		for (int b = 0; b < batchsize; b++)
  		{
  			for (int c = 0; c < result[b].obj_count_; c++)
  			{
  				char str_i[100];
  				sprintf(str_i, "%s:%.2f", type[result[b].obj_results_[c].obj_index].c_str(), result[b].obj_results_[c].obj_score);
  
  				rectangle(img[b],
  					cvPoint(result[b].obj_results_[c].obj_rect.left_ - 5, result[b].obj_results_[c].obj_rect.top_ - 15),
  					cvPoint(result[b].obj_results_[c].obj_rect.left_ + result[b].obj_results_[c].obj_rect.width_ + 5, 
  						result[b].obj_results_[c].obj_rect.top_ + result[b].obj_results_[c].obj_rect.height_ + 10),
  					cv::Scalar(127, 64, 120), 3, 1);
  				cv::putText(img[b], str_i,
  					cv::Point(result[b].obj_results_[c].obj_rect.left_, result[b].obj_results_[c].obj_rect.top_),
  					fontFace, fontScale,
  					cv::Scalar(58,158,199), thickness, 8);
  
  			}
  
  			#ifdef _MSC_VER
  			//cv::imshow("RES", image);
  			//cv::waitKey(0);
  
  			cv::Mat showImg;
  			cv::resize(batch_mat[b], showImg, cv::Size(640, 480));
  			cv::imshow("image", showImg);
  			cv::waitKey(0);
  #else
  			sprintf(strpath, "vpt_result/%d.jpg", b);
  			cv::imwrite(strpath,  img[b]);
  #endif
  		}
  	}
  */
  
  	vpt_release(&handle);
   
  return 0;
  
   
  	
  }