forked from Dynamsoft/barcode-reader-c-cpp-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneralSettings.cpp
105 lines (82 loc) · 3.74 KB
/
GeneralSettings.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
// GeneralSettings.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
// Include headers of DynamsoftBarcodeReader SDK
#include "../../../include/DynamsoftBarcodeReader.h"
#include "../../../include/DynamsoftCommon.h"
using namespace std;
using namespace dynamsoft::dbr;
// Link libraries of DynamsoftBarcodeReader SDK for Windows.
#if defined(_WIN64) || defined(_WIN32)
#ifdef _WIN64
#pragma comment(lib, "../../../lib/Windows/x64/DBRx64.lib")
#else
#pragma comment(lib, "../../../lib/Windows/x86/DBRx86.lib")
#endif
#endif
int main()
{
int errorCode = 0;
char szErrorMsg[256];
PublicRuntimeSettings settings;
TextResultArray* barcodeResults = NULL;
// 1.Initialize license.
// The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work.
// If you don't have a license yet, you can request a trial from https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=samples&package=c_cpp
errorCode = CBarcodeReader::InitLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", szErrorMsg, 256);
if (errorCode != DBR_OK)
{
cout << szErrorMsg << endl;
}
// 2. Create an instance of Barcode Reader
CBarcodeReader dbr;
// 3. Configure settings
// 3.1 Through PublicRuntimeSetting
// 3.1.1 Call GetRuntimeSettings to get current runtime settings.
dbr.GetRuntimeSettings(&settings);
// 3.1.2 Configure one or more specific settings
// In this sample, we configure three settings:
// try to finnd PDF 417 and DotCode
settings.barcodeFormatIds = BF_PDF417;
settings.barcodeFormatIds_2 = BF2_DOTCODE;
// try to find 2 barcodes
settings.expectedBarcodesCount = 2;
// try to find barcodes in the lower part of the image
settings.region.regionLeft = 0;
settings.region.regionRight = 100;
settings.region.regionTop = 50;
settings.region.regionBottom = 100;
settings.region.regionMeasuredByPercentage = 1;
// 3.1.3 Call UpdateRuntimeSettings to apply above settings
dbr.UpdateRuntimeSettings(&settings, szErrorMsg, 256);
// 3.2 Through JSON template
//dbr.InitRuntimeSettingsWithString("{\"ImageParameter\":{\"Name\":\"S1\",\"RegionDefinitionNameArray\":[\"R1\"]},\"RegionDefinition\":{\"Name\":\"R1\",\"BarcodeFormatIds\":[\"BF_PDF417\"],\"BarcodeFormatIds_2\":[\"BF2_POSTALCODE\"],\"ExpectedBarcodesCount\":2,\"Left\":0,\"Right\":100,\"Top\":50,\"Bottom\":100,\"MeasuredByPercentage\":1}}", CM_IGNORE, szErrorMsg, 256);
// 4. Read barcode from an image file
errorCode = dbr.DecodeFile("../../../images/AllSupportedBarcodeTypes.png", "");
if (errorCode != DBR_OK)
cout << CBarcodeReader::GetErrorString(errorCode) << endl;
// 5. Get all barcode results
dbr.GetAllTextResults(&barcodeResults);
if (barcodeResults != NULL && barcodeResults->resultsCount > 0)
{
// Process each result in a loop
for (int i = 0; i < barcodeResults->resultsCount; ++i)
{
cout << "Result " << (i + 1) << ":" << endl;
// 5.1. Get format of each barcode
cout << " Barcode Format: " << barcodeResults->results[i]->barcodeFormatString << endl;
// 5.2. Get text result of each barcode
cout << " Barcode Text: " << barcodeResults->results[i]->barcodeText << endl;
}
}
else
{
cout << "No barcode detected." << endl;
}
// 6. Free the memory allocated for text results
if (barcodeResults != NULL)
CBarcodeReader::FreeTextResults(&barcodeResults);
cout << "Press any key to quit..." << endl;
cin.ignore();
return 0;
}