VehiclePlate.cpp
3.85 KB
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
#include "VehiclePlate.h"
#include <cuda_runtime.h>
//static string type[69] = { "��", "��", "��", "��", "��", "��", "��", "��", "��", "��", "��", "��", "��", "��", "��", "³", "ԥ", "��", "��", "��", "��", "��", "��", "��", "��", "��", "��", "��", "��", "��", "��", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "��", "ѧ", "ʹ", "��" };
int VehiclePlateDetectRecog_Init(void *&handle, int gpuid, char* auth_license)
{
vpd_param param;
param.gpuid = gpuid;
param.thresld = 0.3;
param.max_batch = 20;
param.serialize_file = "./serialize_file/VPD";
param.auth_license = auth_license;
vpr_param rparam;
rparam.gpuid =gpuid;
param.max_batch = 20;
param.serialize_file = "./serialize_file/VPR";
int ret = vpdr_init(&handle, param, rparam);
if (ret != 0)
{
cout << "Init platedr Failed!" << endl;
return FAILED;
}
return SUCCESS;
}
#include <fstream>
int VehiclePlateDetectRecog_Process(void * handle, sy_img * batch_img, int batchsize, vplate_result *&result)
{
/*��ʼ������ṹ��*/
vplates_result * all_result = new vplates_result[batchsize] {};
for (int i = 0; i<batchsize; i++)
{
for (int j = 0; j < MAXPLATECOUNT; j++)
{
memset(&all_result[i].vehicle_plate_infos[j].rect, -1, sizeof(sy_rect));
}
}
std::vector<unsigned char *> gpu_data;
for (int i = 0; i < batchsize; i++)
{
if (batch_img[i].data_ == NULL)
{
cout << i << " data null" << endl;
}
unsigned char * data_ = (unsigned char *)malloc(batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char));
cudaMemcpy(data_, batch_img[i].data_, batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char), cudaMemcpyDeviceToHost);
gpu_data.push_back(batch_img[i].data_);
batch_img[i].data_ = data_;
/*cv::Mat car(batch_img[i].h_, batch_img[i].w_, CV_8UC3, data_);
cv::imshow("car", car);
cv::waitKey(0);*/
}
//cout << "error begin vpdr_batch" << endl;
int index_count = vpdr_batch(handle, batch_img, batchsize, all_result);
//cout << "end vpdr_batch" << endl;
for (int b = 0; b < batchsize; b++)
{
double max_score = 0.0;
int best_index = 0;
for (int j = 0; j < MAXPLATECOUNT; j++)
{
if (all_result[b].vehicle_plate_infos[j].rect.left_ == -1)
{
continue;
}
if (all_result[b].vehicle_plate_infos[j].detect_score > max_score)
{
max_score = all_result[b].vehicle_plate_infos[j].detect_score;
best_index = j;
}
}
/*{
result[b].detect_score = all_result[b][best_index].detect_score;
result[b].num_score = all_result[b][best_index].num_score;
result[b].rect.left_ = all_result[b][best_index].rect.left_;
result[b].rect.height_ = all_result[b][best_index].rect.height_;
result[b].rect.top_ = all_result[b][best_index].rect.top_;
result[b].rect.width_ = all_result[b][best_index].rect.width_;
result[b].type = all_result[b][best_index].type;
}
*/
/*printf("b=%d\n", b);
for (int m = 0; m < PLATENUM; m++)
{
printf("%s", all_result[b].vehicle_plate_infos[best_index].recg[m].character);
}
printf("\n");*/
memcpy(&result[b], &all_result[b].vehicle_plate_infos[best_index], sizeof(vplate_result));
}
//for (int i = 0; i<batchsize; i++)
//{
// if (all_result[i] != NULL)
// delete[] all_result[i];
//}
for (int i = 0; i < batchsize; i++)
{
free(batch_img[i].data_);
batch_img[i].data_ = gpu_data[i];
}
if (all_result != NULL)
delete [] all_result;
return SUCCESS;
}
int VehiclePlateDetectRecog_Release(void *& handle)
{
if (handle)
vpdr_release(&handle);
return SUCCESS;
}