-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGeneralSettings.cpp
More file actions
136 lines (119 loc) · 5.48 KB
/
GeneralSettings.cpp
File metadata and controls
136 lines (119 loc) · 5.48 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
#include <iostream>
#include <string>
#include "../../Include/DynamsoftCaptureVisionRouter.h"
using namespace std;
using namespace dynamsoft::license;
using namespace dynamsoft::cvr;
using namespace dynamsoft::dbr;
using namespace dynamsoft::basic_structures;
#if defined(_WIN64) || defined(_WIN32)
#ifdef _WIN64
#pragma comment(lib, "../../Dist/Lib/Windows/x64/DynamsoftLicensex64.lib")
#pragma comment(lib, "../../Dist/Lib/Windows/x64/DynamsoftCorex64.lib")
#pragma comment(lib, "../../Dist/Lib/Windows/x64/DynamsoftCaptureVisionRouterx64.lib")
#else
#pragma comment(lib, "../../Dist/Lib/Windows/x86/DynamsoftLicensex86.lib")
#pragma comment(lib, "../../Dist/Lib/Windows/x86/DynamsoftCorex86.lib")
#pragma comment(lib, "../../Dist/Lib/Windows/x86/DynamsoftCaptureVisionRouterx86.lib")
#endif
#endif
int main()
{
int errorCode = 1;
char errorMsg[512];
// 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?product=dbr&utm_source=samples&package=c_cpp
errorCode = CLicenseManager::InitLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", errorMsg, 512);
if (errorCode != ErrorCode::EC_OK && errorCode != ErrorCode::EC_LICENSE_WARNING)
{
cout << "License initialization failed: ErrorCode: " << errorCode << ", ErrorString: " << errorMsg << endl;
}
else
{
// 2. Create an instance of CaptureVisionRouter.
CCaptureVisionRouter *cvRouter = new CCaptureVisionRouter;
// 3. General settings (including barcode format, barcode count and scan region) through SimplifiedCaptureVisionSettings
// 3.1 Obtain current runtime settings of instance.
SimplifiedCaptureVisionSettings settings;
errorCode = cvRouter->GetSimplifiedSettings(CPresetTemplate::PT_READ_BARCODES, &settings);
if (errorCode != ErrorCode::EC_OK)
{
cout << "Get simplified settings failed, Error: " << errorCode << endl;
}
else
{
// 3.2 Set the expected barcode format you want to read.
settings.barcodeSettings.barcodeFormatIds = BarcodeFormat::BF_QR_CODE | BarcodeFormat::BF_CODE_128;
// 3.3 Set the expected barcode count you want to read.
settings.barcodeSettings.expectedBarcodesCount = 10;
// 3.4 Set the grayscale transformation modes.
settings.barcodeSettings.grayscaleTransformationModes[0] = GrayscaleTransformationMode::GTM_AUTO;
// 3.5 Set the ROI(region of interest) to speed up the barcode reading process.
// Note: DBR supports setting coordinates by pixels or percentages. The origin of the coordinate system is the upper left corner point.
settings.roiMeasuredInPercentage = 1;
settings.roi.points[0] = CPoint(0, 0);
settings.roi.points[1] = CPoint(100, 0);
settings.roi.points[2] = CPoint(100, 100);
settings.roi.points[3] = CPoint(0, 100);
// 3.6 Apply the new settings to the instance.
errorCode = cvRouter->UpdateSettings(CPresetTemplate::PT_READ_BARCODES, &settings, errorMsg, 512);
if (errorCode != ErrorCode::EC_OK)
cout << "Update settings failed: ErrorCode: " << errorCode << ", ErrorString : " << errorMsg << endl;
// 4. Replace by your own image path
string imageFile = "../../Images/GeneralBarcodes.png";
// 5. Decode barcodes from the image file.
CCapturedResultArray* resultArray = cvRouter->CaptureMultiPages(imageFile.c_str(), CPresetTemplate::PT_READ_BARCODES);
int count = resultArray->GetResultsCount();
for (int i = 0; i < count; ++i)
{
const CCapturedResult* result = resultArray->GetResult(i);
if (result->GetErrorCode() == ErrorCode::EC_UNSUPPORTED_JSON_KEY_WARNING)
{
cout << "Warning: " << result->GetErrorCode() << ", " << result->GetErrorString() << endl;
}
else if (result->GetErrorCode() != ErrorCode::EC_OK)
{
cout << "Error: " << result->GetErrorCode() << "," << result->GetErrorString() << endl;
}
int pageNumber = i + 1;
// It is usually necessary to determine 'ImageTagType' based on the original image tag.
// Since imageFile is used, it is directly converted to 'const dynamsoft::basic_structures::CFileImageTag *'.
const CFileImageTag *tag = dynamic_cast<const CFileImageTag *>(result->GetOriginalImageTag());
if(tag != nullptr)
{
pageNumber = tag->GetPageNumber() + 1;
}
// 6. Output the barcode text.
CDecodedBarcodesResult* barcodeResult = result->GetDecodedBarcodesResult();
if (barcodeResult == nullptr || barcodeResult->GetItemsCount() == 0)
{
cout << "No barcode found in page " << pageNumber << endl;
}
else
{
int barcodeResultItemCount = barcodeResult->GetItemsCount();
cout << "Page " << pageNumber << " decoded " << barcodeResultItemCount << " barcodes" << endl;
for (int j = 0; j < barcodeResultItemCount; j++)
{
const CBarcodeResultItem* barcodeResultItem = barcodeResult->GetItem(j);
cout << "Result " << pageNumber << "-" << j + 1 << endl;
cout << "Barcode Format: " << barcodeResultItem->GetFormatString() << endl;
cout << "Barcode Text: " << barcodeResultItem->GetText() << endl;
}
}
// 7. Release the barcode result.
if (barcodeResult)
barcodeResult->Release();
}
// 8. Release the capture result.
if (resultArray)
resultArray->Release();
// 9. Release the allocated memory.
delete cvRouter, cvRouter = NULL;
}
}
cout << "Press any key to quit..." << endl;
cin.ignore();
return 0;
}