-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBarcodePerformanceEvaluator.cpp
More file actions
205 lines (190 loc) · 5.95 KB
/
BarcodePerformanceEvaluator.cpp
File metadata and controls
205 lines (190 loc) · 5.95 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// BarcodePerformanceEvaluator.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <string>
#if defined(_WIN64) || defined(_WIN32)
#include <conio.h>
#else
#include <limits>
#endif
#include "DbrBarcodeFileReader.h"
void ShowConsole();
void ShowConsoleCmd();
/****
*The command grammar: (options) (paramters)
-i: set the input the barcode files directory. -i "D:\images"
-o: set the output result files directory. -o "D:\output"
-l: set the barcode reader library(dll) path
*/
char *stdin_get_str(char *str, int len)
{
fgets(str, len, stdin);
if(str[strlen(str)-1] == '\n')
str[strlen(str)-1] = '\0';
return str;
}
int main(int argc, char* argv[])
{
char szErrorMsg[256];
// 1.Initialize license.
// The string 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9' here is a free public trial license. Note that network connection is required for this license to work.
// You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?architecture=dcv&product=dbr&utm_source=samples&package=c_cpp
int errorCode = CLicenseManager::InitLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", szErrorMsg, 256);
if (errorCode != ErrorCode::EC_OK && errorCode != ErrorCode::EC_LICENSE_WARNING)
{
cout << "License initialization failed: ErrorCode: " << errorCode << ", ErrorString: " << szErrorMsg << endl;
}
CDbrBarcodeFileReader *barcodeFileReader = new CDbrBarcodeFileReader();
if (argc >= 3 && argc%2==1)
{
for (int i = 1; i < argc-1; i++)
{
string str = argv[i];
if (str == "-i")
{
string strBarcodeDir = argv[i + 1];
barcodeFileReader->LoadBarcodeFiles(strBarcodeDir.c_str());
}
if (str == "-o")
{
string strOutputBarcodeDir = argv[i + 1];
barcodeFileReader->SetOutputFileDir(strOutputBarcodeDir.c_str());
}
if (str == "-l")
{
string strOutputBarcodeDir = argv[i + 1];
}
if (str == "-t")
{
string strOutputType = argv[i + 1];
if (strcasecmp(strOutputType.c_str(), "console") ==0)
{
barcodeFileReader->SetOutputType(CBarcodeFileReader::OUTPUT_CONSOLE);
}
else
{
barcodeFileReader->SetOutputType(CBarcodeFileReader::OUTPUT_FILE);
}
}
}
barcodeFileReader->Run();
std::cout << "Complete!" << std::endl;
if (barcodeFileReader != NULL)
{
delete barcodeFileReader;
}
return 0;
}
ShowConsole();
char szBuffer[256] = { 0 };
string strGettingMessage = "";
char ichar=' ', iType=' ';
size_t iLen;
while (ichar!='q')
{
#if defined(_WIN64) || defined(_WIN32)
ichar = _getche();
#else
ichar = getchar();
#endif
if(ichar=='\0')
#if defined(_WIN64) || defined(_WIN32)
ichar = _getche();
#else
ichar = getchar();
#endif
switch (ichar)
{
case 'i':
case 'I':
std::cout << "\n Please input the barcode files directory:";
memset(szBuffer, 0, sizeof(szBuffer));
#if defined(_WIN64) || defined(_WIN32)
strGettingMessage = gets_s(szBuffer, 256);
#else
std::cin.clear();
std::cin.ignore( numeric_limits<streamsize>::max(), '\n' );
std::cin.get(szBuffer, 256);
strGettingMessage = szBuffer;
#endif
iLen = strGettingMessage.length();
if (strGettingMessage[0] == '\"' && strGettingMessage[iLen - 1] == '\"')
strGettingMessage = strGettingMessage.substr(1, iLen - 2);
barcodeFileReader->LoadBarcodeFiles(strGettingMessage.c_str());
break;
case 'o':
case 'O':
{
barcodeFileReader->SetOutputType(CBarcodeFileReader::OUTPUT_FILE);
std::cout << "\n Please input the output directory for decoding result:";
memset(szBuffer, 0, sizeof(szBuffer));
#if defined(_WIN64) || defined(_WIN32)
strGettingMessage = gets_s(szBuffer, 256);
#else
std::cin.clear();
std::cin.ignore( numeric_limits<streamsize>::max(), '\n' );
std::cin.get(szBuffer, 256);
strGettingMessage = szBuffer;
#endif
iLen = strGettingMessage.length();
if (strGettingMessage[0] == '\"' && strGettingMessage[iLen - 1] == '\"')
strGettingMessage = strGettingMessage.substr(1, iLen - 2);
barcodeFileReader->SetOutputFileDir(strGettingMessage.c_str());
}
break;
case 'r':
case 'R':
{
std::cout << "\n";
barcodeFileReader->Run();
std::cout << "Complete!" << std::endl;
#if defined(_WIN64) || defined(_WIN32)
_getche();
#else
getchar();
#endif
memset(szBuffer, 0, sizeof(szBuffer));
}
break;
case 'q':
case 'Q':
ichar = 'q';
break;
case ' ':
break;
default:
{
std::cout << "\n The input commands invalid!" << std::endl;
}
}
#if defined(_WIN64) || defined(_WIN32)
#else
std::cin.clear();
std::cin.ignore( numeric_limits<streamsize>::max(), '\n' );
#endif
ShowConsoleCmd();
}
if (barcodeFileReader != NULL)
{
delete barcodeFileReader;
}
return 0;
}
void ShowConsole()
{
std::cout << "***************************************************************************" << std::endl;
std::cout << "***** Dynamsoft Barcode Performance Evaluator ********" << std::endl;
std::cout << "***************************************************************************" << std::endl;
std::cout << "***** I-Input barcode files directory (Default is './') ********" << std::endl;
std::cout << "***** O-Output directory for decoding result (Default is './') ********" << std::endl;
std::cout << "***** R-Run the barcode Reader ********" << std::endl;
std::cout << "***** Q-Quit! ********" << std::endl;
std::cout << "***************************************************************************" << std::endl;
}
void ShowConsoleCmd()
{
std::cout << "* I-Input barcode files directory (Default is './') " << std::endl;
std::cout << "* O-Output directory for decoding result (Default is './') " << std::endl;
std::cout << "* R-Run the barcode reader " << std::endl;
std::cout << "* Q-Quit! " << std::endl;
}