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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
#include "vehicle_features.h"
#include <iostream>
#include "sy_errorinfo.h"
using namespace std;
void RectboundCheck(int Width, int Height, int &left, int &top, int &width, int &height);
int vhd_features_init(void *&handle, char*dbpath, int gpuid)
{
vhd_param params;
params.gpuid = gpuid;
params.mode = DEVICE_GPU;
params.process_min_length = 512;
params.threshold = 0.5;
params.engine = ENGINE_TENSORRT;
params.max_batchsize = 20;
params.serialize_file = "./serialize_file/VHD";
// params.db_path = dbpath;
if (vhd_init(&handle, ¶ms) !=0)
{
cout << "Init vhd Failed!" << endl;
return FAILED;
}
return SUCCESS;
}
int vf_features_init(void *&handle, char*dbpath, int gpuid)
{
vf_param params;
params.gpuid = gpuid;
params.mode = DEVICE_GPU;
params.serialize_file = NULL;
params.engine = ENGINE_TENSORRT;
params.max_batch = 20;
params.serialize_file = "./serialize_file/VF";
// params.db_path = dbpath;
if (vf_init(&handle, params) !=0)
{
cout << "Init VF Failed!" << endl;
return FAILED;
}
return SUCCESS;
}
int vhd_features_process(void * handle, sy_img * batch_img, int batch_size, vhd_result*& result)
{
for (int i = 0; i < batch_size; i++)
{
if (batch_img[i].data_ == NULL)
cout << i << " data null" << endl;
}
vhd_process_batch(handle, batch_img, batch_size, result);
for (int b = 0; b < batch_size; b++)
{
for (int c = 0; c < result[b].obj_count_; c++)
{
RectboundCheck(batch_img[b].w_, batch_img[b].h_, result[b].obj_results_[c].obj_rect.left_,
result[b].obj_results_[c].obj_rect.top_, result[b].obj_results_[c].obj_rect.width_, result[b].obj_results_[c].obj_rect.height_);
}
}
return SUCCESS;
}
#include <cuda.h>
#include <cuda_runtime.h>
#include <opencv2/opencv.hpp>
int vf_features_process(void * handle, sy_img * batch_img, int batch_size, int8**& result)
{
for (int i = 0; i < batch_size; i++)
{
if (batch_img[i].data_ == NULL)
cout << i << " data null" << endl;
}
int **fea = new int*[batch_size];
for (int i = 0; i < batch_size; i++)
{
fea[i] = new int[FEATURESIZE];
}
vf_feature_batch(handle, batch_img, batch_size, fea);
for (int i = 0; i < batch_size; i++)
{
for (int f = 0; f < FEATURESIZE; f++)
{
result[i][f] = (unsigned char)fea[i][f];
}
}
if (fea)
{
for (int b = 0; b < batch_size; b++)
{
if(fea[b])
{
delete[] fea[b];
fea[b] = NULL;
}
}
delete[] fea;
fea = NULL;
}
return SUCCESS;
}
int vhd_feature_release(void *& handle)
{
if (handle)
vhd_release(&handle);
return SUCCESS;
}
int vf_feature_release(void *& handle)
{
if (handle)
vf_release(&handle);
return SUCCESS;
}
void RectboundCheck(int Width, int Height, int &left, int &top, int &width, int &height)
{
#ifdef _DEBUG
printf("img: Width = %d Height = %d\n",
Width, Height);
printf("Src: width = %d height = %d, x = %d, y =%d\n",
rect->width, rect->height, rect->left, rect->top);
#endif
if (left <= 0)
left = 0;
if (left >= (Width - 1))
left = Width - 2;
if (top < 0)
top = 0;
if (top >= (Height - 1))
top = Height - 2;
if ((left + width) >= Width)
width = Width - left - 1;
if (width <= 0)
width = 0;
if ((top + height) >= Height)
height = Height - 1 - top;
if (height <= 0)
height = 0;
#ifdef _DEBUG
printf("Dst: width = %d, height = %d, x = %d, y =%d\n",
rect->width, rect->height, rect->left, rect->top);
#endif
}
|