-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathopenalprpy.cpp
146 lines (102 loc) · 3.6 KB
/
openalprpy.cpp
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <alpr.h>
extern "C" {
#if defined(WIN32)
// Microsoft
#define OPENALPR_EXPORT __declspec(dllexport)
#else
// do nothing
#define OPENALPR_EXPORT
#endif
using namespace alpr;
OPENALPR_EXPORT Alpr* initialize(char* ccountry, char* cconfigFile, char* cruntimeDir)
{
//printf("Initialize");
// Convert strings from char* to string
std::string country(ccountry);
std::string configFile(cconfigFile);
std::string runtimeDir(cruntimeDir);
//std::cout << country << std::endl << configFile << std::endl << runtimeDir << std::endl;
Alpr* nativeAlpr = new alpr::Alpr(country, configFile, runtimeDir);
return nativeAlpr;
}
OPENALPR_EXPORT void dispose(Alpr* nativeAlpr)
{
delete nativeAlpr;
}
OPENALPR_EXPORT bool isLoaded(Alpr* nativeAlpr)
{
//printf("IS LOADED");
return nativeAlpr->isLoaded();
}
OPENALPR_EXPORT char* recognizeFile(Alpr* nativeAlpr, char* cimageFile)
{
//printf("Recognize file");
// Convert strings from java to C++ and release resources
std::string imageFile(cimageFile);
AlprResults results = nativeAlpr->recognize(imageFile);
std::string json = Alpr::toJson(results);
int strsize = sizeof(char) * (strlen(json.c_str()) + 1);
char* membuffer = (char*)malloc(strsize);
strcpy(membuffer, json.c_str());
//printf("allocated address: %p\n", membuffer);
return membuffer;
}
OPENALPR_EXPORT void freeJsonMem(char* ptr)
{
//printf("freeing address: %p\n", ptr);
free( ptr );
}
OPENALPR_EXPORT char* recognizeArray(Alpr* nativeAlpr, unsigned char* buf, int len)
{
//printf("Recognize byte array");
//printf("buffer pointer: %p\n", buf);
//printf("buffer length: %d\n", len);
//std::cout << "Using instance: " << nativeAlpr << std::endl;
std::vector<char> cvec(buf, buf+len);
AlprResults results = nativeAlpr->recognize(cvec);
std::string json = Alpr::toJson(results);
int strsize = sizeof(char) * (strlen(json.c_str()) + 1);
char* membuffer = (char*)malloc(strsize);
strcpy(membuffer, json.c_str());
//printf("allocated address: %p\n", membuffer);
return membuffer;
}
OPENALPR_EXPORT void setCountry(Alpr* nativeAlpr, char* ccountry)
{
// Convert strings from java to C++ and release resources
std::string country(ccountry);
nativeAlpr->setCountry(country);
}
OPENALPR_EXPORT void setPrewarp(Alpr* nativeAlpr, char* cprewarp)
{
// Convert strings from java to C++ and release resources
std::string prewarp(cprewarp);
nativeAlpr->setPrewarp(prewarp);
}
OPENALPR_EXPORT void setDefaultRegion(Alpr* nativeAlpr, char* cdefault_region)
{
// Convert strings from java to C++ and release resources
std::string default_region(cdefault_region);
nativeAlpr->setDefaultRegion(default_region);
}
OPENALPR_EXPORT void setDetectRegion(Alpr* nativeAlpr, bool detect_region)
{
nativeAlpr->setDetectRegion(detect_region);
}
OPENALPR_EXPORT void setTopN(Alpr* nativeAlpr, int top_n)
{
nativeAlpr->setTopN(top_n);
}
OPENALPR_EXPORT char* getVersion(Alpr* nativeAlpr)
{
std::string version = nativeAlpr->getVersion();
int strsize = sizeof(char) * (strlen(version.c_str()) + 1);
char* membuffer = (char*)malloc(strsize);
strcpy(membuffer, version.c_str());
//printf("allocated address: %p\n", membuffer);
return membuffer;
}
}