Thanks for downloading Dynamsoft Barcode Reader Package!
Your download will start shortly. If your download does not begin, click here to retry.
In this guide, you will learn step by step on how to build a barcode reading application with Dynamsoft Barcode Reader SDK using Python.
Start terminal or command prompt to run the following command.
pip install dbr
Let’s start by creating a console application which demonstrates how to use the minimum code to read barcodes from an image file.
You can download the entire source code from Here.
Create a new source file named DBRPythonSample.py
.
Import dbr package in the source file.
from dbr import *
reader = BarcodeReader()
reader.init_license("<insert DBR license key here>")
Please replace
<insert DBR license key here>
with a valid DBR licensekey. You can request a trial license from Customer Portal.
settings = reader.get_runtime_settings()
settings.barcode_format_ids = EnumBarcodeFormat.BF_ALL
settings.barcode_format_ids_2 = EnumBarcodeFormat_2.BF2_POSTALCODE | EnumBarcodeFormat_2.BF2_DOTCODE
settings.excepted_barcodes_count = 32
reader.update_runtime_settings(settings)
The barcode formats to enable is highly application-specific. We recommend that you only enable the barcode formats your application requires. Check out Barcode Format Enumeration for full supported barcode formats.
If you know exactly the barcode count you want to read, specify
excepted_barcodes_count
to speed up the process and improve the accuracy.
Get and output barcode results.
try:
image = r"[INSTALLATION FOLDER]/Images/AllSupportedBarcodeTypes.png"
text_results = reader.decode_file(image)
if text_results != None:
for text_result in text_results:
print("Barcode Format : " + text_result.barcode_format_string)
if len(text_result.barcode_format_string) == 0:
print("Barcode Format : " + text_result.barcode_format_string_2)
else:
print("Barcode Format : " + text_result.barcode_format_string)
print("Barcode Text : " + text_result.barcode_text)
except BarcodeReaderError as bre:
print(bre)
For the error handling mechanism, the SDK throws BarcodeReaderError for each function. You should add codes for exception handling based on your needs.
The SDK returns multiple barcode information, including barcode count, barcode format, barcode text, location, barcode raw data, etc. Check out TextResult for full supported result data.
Destroy the instance to release all resources.
del reader
DBRPythonSample.py
located in.python DBRPythonSample.py
You can download the entire source code from Here.
latest version