11
11
print ("License error: " + error [1 ])
12
12
13
13
# 2.Create an instance of Barcode Reader.
14
- dbr = BarcodeReader ()
14
+ reader = BarcodeReader ()
15
15
16
16
# There are two ways to configure runtime parameters. One is through PublicRuntimeSettings, the other is through parameters template.
17
17
# 3. General settings (including barcode format, barcode count and scan region) through PublicRuntimeSettings
18
18
# 3.1 Obtain current runtime settings of instance.
19
- sts = dbr .get_runtime_settings ()
19
+ settings = reader .get_runtime_settings ()
20
20
21
21
# 3.2 Set the expected barcode format you want to read.
22
22
# The barcode format our library will search for is composed of BarcodeFormat group 1 and BarcodeFormat group 2.
23
23
# So you need to specify the barcode format in group 1 and group 2 individually.
24
- sts .barcode_format_ids = EnumBarcodeFormat .BF_ONED | EnumBarcodeFormat . BF_QR_CODE | EnumBarcodeFormat . BF_PDF417 | EnumBarcodeFormat . BF_DATAMATRIX
25
- sts .barcode_format_ids_2 = EnumBarcodeFormat .BF_NULL
24
+ settings .barcode_format_ids = EnumBarcodeFormat .BF_ALL
25
+ settings .barcode_format_ids_2 = EnumBarcodeFormat .BF2_POSTALCODE | EnumBarcodeFormat_2 . BF2_DOTCODE
26
26
27
27
# 3.3 Set the expected barcode count you want to read.
28
- sts .expected_barcodes_count = 10
28
+ settings .expected_barcodes_count = 10
29
29
30
30
# 3.4 Set the ROI(region of interest) to speed up the barcode reading process.
31
31
# Note: DBR supports setting coordinates by pixels or percentages. The origin of the coordinate system is the upper left corner point.
32
- sts .region_measured_by_percentage = 1
33
- sts .region_left = 0
34
- sts .region_right = 100
35
- sts .region_top = 0
36
- sts .region_bottom = 100
32
+ settings .region_measured_by_percentage = 1
33
+ settings .region_left = 0
34
+ settings .region_right = 100
35
+ settings .region_top = 0
36
+ settings .region_bottom = 100
37
37
38
38
# 3.5 Apply the new settings to the instance
39
- dbr .update_runtime_settings (sts )
39
+ reader .update_runtime_settings (settings )
40
40
41
41
# 3. General settings (including barcode format, barcode count and scan region) through parameters template.
42
- # dbr .init_runtime_settings_with_string("{\"ImageParameter\":{\"BarcodeFormatIds\":[\"BF_ONED\",\"BF_PDF417\",\"BF_QR_CODE\",\"BF_DATAMATRIX\"],\"BarcodeFormatIds_2\":null,\"ExpectedBarcodesCount\":10,\"Name\":\"sts\",\"RegionDefinitionNameArray\":[\"region0\"]},\"RegionDefinition\":{\"Bottom\":100,\"Left\":0,\"MeasuredByPercentage\":1,\"Name\":\"region0\",\"Right\":100,\"Top\":0}}")
42
+ # reader .init_runtime_settings_with_string("{\"ImageParameter\":{\"BarcodeFormatIds\":[\"BF_ONED\",\"BF_PDF417\",\"BF_QR_CODE\",\"BF_DATAMATRIX\"],\"BarcodeFormatIds_2\":null,\"ExpectedBarcodesCount\":10,\"Name\":\"sts\",\"RegionDefinitionNameArray\":[\"region0\"]},\"RegionDefinition\":{\"Bottom\":100,\"Left\":0,\"MeasuredByPercentage\":1,\"Name\":\"region0\",\"Right\":100,\"Top\":0}}")
43
43
44
44
# Replace by your own image path
45
45
image_path = os .path .dirname (os .path .abspath (__file__ )) + os .path .sep + "../images/AllSupportedBarcodeTypes.png"
46
46
47
47
# 4.Decode barcodes from an image file.
48
- results = dbr .decode_file (image_path )
48
+ results = reader .decode_file (image_path )
49
49
50
50
# 5.Output the barcode text.
51
51
if results != None :
52
52
i = 0
53
53
for res in results :
54
- barcode_format = res . barcode_format_string
55
-
56
- print ("Barcode " + str ( i ) + ":" + barcode_format + "," + res .barcode_text )
54
+ print ( "Barcode " + str ( i ))
55
+ print ( "Barcode Format : " + text_result . barcode_format_string )
56
+ print ("Barcode Text : " + text_result .barcode_text )
57
57
i = i + 1
58
58
else :
59
59
print ("No data detected." )
60
+
61
+ # 6.Release resource
62
+ del reader
63
+
60
64
except BarcodeReaderError as bre :
61
- print (bre )
65
+ print (bre )
0 commit comments