Skip to content

Commit

Permalink
Update general-settings.py
Browse files Browse the repository at this point in the history
  • Loading branch information
DMGithubPublisher authored Nov 10, 2022
1 parent d90bf70 commit 68d1117
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions samples/general-settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,55 @@
print("License error: "+ error[1])

# 2.Create an instance of Barcode Reader.
dbr = BarcodeReader()
reader = BarcodeReader()

# There are two ways to configure runtime parameters. One is through PublicRuntimeSettings, the other is through parameters template.
# 3. General settings (including barcode format, barcode count and scan region) through PublicRuntimeSettings
# 3.1 Obtain current runtime settings of instance.
sts = dbr.get_runtime_settings()
settings = reader.get_runtime_settings()

# 3.2 Set the expected barcode format you want to read.
# The barcode format our library will search for is composed of BarcodeFormat group 1 and BarcodeFormat group 2.
# So you need to specify the barcode format in group 1 and group 2 individually.
sts.barcode_format_ids = EnumBarcodeFormat.BF_ONED | EnumBarcodeFormat.BF_QR_CODE | EnumBarcodeFormat.BF_PDF417 | EnumBarcodeFormat.BF_DATAMATRIX
sts.barcode_format_ids_2 = EnumBarcodeFormat.BF_NULL
settings.barcode_format_ids = EnumBarcodeFormat.BF_ALL
settings.barcode_format_ids_2 = EnumBarcodeFormat.BF2_POSTALCODE | EnumBarcodeFormat_2.BF2_DOTCODE

# 3.3 Set the expected barcode count you want to read.
sts.expected_barcodes_count = 10
settings.expected_barcodes_count = 10

# 3.4 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.
sts.region_measured_by_percentage = 1
sts.region_left = 0
sts.region_right = 100
sts.region_top = 0
sts.region_bottom = 100
settings.region_measured_by_percentage = 1
settings.region_left = 0
settings.region_right = 100
settings.region_top = 0
settings.region_bottom = 100

# 3.5 Apply the new settings to the instance
dbr.update_runtime_settings(sts)
reader.update_runtime_settings(settings)

# 3. General settings (including barcode format, barcode count and scan region) through parameters template.
# 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}}")
# 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}}")

# Replace by your own image path
image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../images/AllSupportedBarcodeTypes.png"

# 4.Decode barcodes from an image file.
results = dbr.decode_file(image_path)
results = reader.decode_file(image_path)

# 5.Output the barcode text.
if results != None:
i = 0
for res in results:
barcode_format = res.barcode_format_string

print("Barcode " + str(i) + ":" + barcode_format + "," + res.barcode_text)
print("Barcode " + str(i))
print("Barcode Format : " + text_result.barcode_format_string)
print("Barcode Text : " + text_result.barcode_text)
i = i+1
else:
print("No data detected.")

# 6.Release resource
del reader

except BarcodeReaderError as bre:
print(bre)
print(bre)

0 comments on commit 68d1117

Please sign in to comment.