1111 print ("License error: " + error [1 ])
1212
1313 # 2.Create an instance of Barcode Reader.
14- dbr = BarcodeReader ()
14+ reader = BarcodeReader ()
1515
1616 # There are two ways to configure runtime parameters. One is through PublicRuntimeSettings, the other is through parameters template.
1717 # 3. General settings (including barcode format, barcode count and scan region) through PublicRuntimeSettings
1818 # 3.1 Obtain current runtime settings of instance.
19- sts = dbr .get_runtime_settings ()
19+ settings = reader .get_runtime_settings ()
2020
2121 # 3.2 Set the expected barcode format you want to read.
2222 # The barcode format our library will search for is composed of BarcodeFormat group 1 and BarcodeFormat group 2.
2323 # 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
2626
2727 # 3.3 Set the expected barcode count you want to read.
28- sts .expected_barcodes_count = 10
28+ settings .expected_barcodes_count = 10
2929
3030 # 3.4 Set the ROI(region of interest) to speed up the barcode reading process.
3131 # 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
3737
3838 # 3.5 Apply the new settings to the instance
39- dbr .update_runtime_settings (sts )
39+ reader .update_runtime_settings (settings )
4040
4141 # 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}}")
4343
4444 # Replace by your own image path
4545 image_path = os .path .dirname (os .path .abspath (__file__ )) + os .path .sep + "../images/AllSupportedBarcodeTypes.png"
4646
4747 # 4.Decode barcodes from an image file.
48- results = dbr .decode_file (image_path )
48+ results = reader .decode_file (image_path )
4949
5050 # 5.Output the barcode text.
5151 if results != None :
5252 i = 0
5353 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 )
5757 i = i + 1
5858 else :
5959 print ("No data detected." )
60+
61+ # 6.Release resource
62+ del reader
63+
6064 except BarcodeReaderError as bre :
61- print (bre )
65+ print (bre )
0 commit comments