Dev Center
Table of contents

Python API Reference - BarcodeReader Decode Methods

Method Description
decode_file Decodes barcodes from a specified image file.
decode_buffer Decodes barcodes from the memory buffer containing image pixels in defined format.
decode_file_stream Decodes barcodes from an image file in memory.
decode_buffer_manually Decodes barcodes from the memory buffer containing image pixels in defined format.
decode_base64_string Decodes barcodes from the base64 encoded string.
init_intermediate_result Inits an intermediateResult struct with default values.
decode_intermediate_results Decodes barcode from intermediate results.

decode_file

Decode barcodes from a specified image file.

BarcodeReader.decode_file(image_file_name, template_name="")

Parameters

  • [in] image_file_name <str> : A string defining the file name. It supports BMP, JPEG, PNG, TIFF and PDF files.
  • [in] template_name <optional><str> : The template name.

Return Value

text_results <*list[class TextResult]*> : All TextResult structs for successfully decoded barcodes.

Exception

BarcodeReaderError The exception thrown by Dynamsoft Barcode Reader.

Code Snippet

from dbr import *
license_key = 'YOUR-LICENSE-KEY'
image_file = r'C:\Program Files (x86)\Dynamsoft\{Version number}\Images\AllSupportedBarcodeTypes.tif'

BarcodeReader.init_license(license_key)
reader = BarcodeReader()
try:
    text_results = reader.decode_file(image_file)
    if text_results != None:
        for text_result in text_results:
            print("Barcode Format :")
            print(text_result.barcode_format_string)
            print("Barcode Text :")
            print(text_result.barcode_text)
            print("Localization Points : ")
            print(text_result.localization_result.localization_points)
            print("-------------")
except BarcodeReaderError as bre:
    print(bre)

decode_buffer

Decodes barcodes from the memory buffer containing image pixels in defined format.

BarcodeReader.decode_buffer(image, image_pixel_format=EnumImagePixelFormat.IPF_RGB_888, template_name="", orientation=0)

Parameters
[in] image <class numpy.ndarray> : The image which is processed by opencv.
[in] image_pixel_format <class EnumImagePixelFormat> : The image pixel format used in the image byte array.
[in] template_name <optional><str> : The template name.
[in] orientation <optional><int> : The orientation of the image data. The value is the angle that the image needs to be rotated clockwise so it shows correctly on the display in its natural orientation. It can be 0, 90, 180, or 270.

Return Value
text_results <*list[class TextResult]*> : All TextResult structs for successfully decoded barcodes.

Exception
BarcodeReaderError : If error happens, this function will throw a BarcodeReaderError exception that can report the detailed error message.

Code Snippet

import cv2
from dbr import *
license_key = 'YOUR-LICENSE-KEY'
image_file = r'C:\Program Files (x86)\Dynamsoft\{Version number}\Images\AllSupportedBarcodeTypes.tif'

image = cv2.imread(image_file)

BarcodeReader.init_license(license_key)
reader = BarcodeReader()
try:
    text_results = reader.decode_buffer(image)
    if text_results != None:
        for text_result in text_results:
            print("Barcode Format :")
            print(text_result.barcode_format_string)
            print("Barcode Text :")
            print(text_result.barcode_text)
            print("Localization Points : ")
            print(text_result.localization_result.localization_points)
            print("-------------")
except BarcodeReaderError as bre:
    print(bre)

decode_file_stream

Decodes barcodes from an image file in memory.

BarcodeReader.decode_file_stream(file_stream, template_name="")

Parameters

  • [in] file_stream <bytes or bytearray> : The image file bytes in memory.
  • [in] templateName <optional><str>: The template name.

Return Value

text_results <*list[class TextResult]*> : All TextResult structs for successfully decoded barcodes.

Exception

BarcodeReaderError The exception thrown by Dynamsoft Barcode Reader.

Code Snippet

from dbr import *
license_key = 'YOUR-LICENSE-KEY'
image_file = r'C:\Program Files (x86)\Dynamsoft\{Version number}\Images\AllSupportedBarcodeTypes.tif'

with open(image_file, "rb") as fread:
    total = fread.read()

BarcodeReader.init_license(license_key)
reader = BarcodeReader()
try:
    text_results = reader.decode_file_stream(bytearray(total))
    if text_results != None:
        for text_result in text_results:
            print("Barcode Format :")
            print(text_result.barcode_format_string)
            print("Barcode Text :")
            print(text_result.barcode_text)
            print("Localization Points : ")
            print(text_result.localization_result.localization_points)
            print("-------------")
except BarcodeReaderError as bre:
    print(bre)

decode_buffer_manually

Decodes barcodes from the memory buffer containing image pixels in defined format.

BarcodeReader.decode_buffer_manually(self, buffer, width, height, stride, image_pixel_format, template_name="", orientation=0)

Parameters
[in] buffer <bytes or bytearray> : The array of bytes which contain the image data.
[in] width <int> : The width of the image in pixels.
[in] height <int> : The height of the image in pixels.
[in] stride <int> : The stride (or scan width) of the image.
[in] image_pixel_format <class EnumImagePixelFormat> : The image pixel format used in the image byte array. Default value = EnumImagePixelFormat.IPF_RGB_888.
[in] template_name <optional><str> : The template name.
[in] orientation <optional><int> : The orientation of the image data. The value is the angle that the image needs to be rotated clockwise so it shows correctly on the display in its natural orientation. It can be 0, 90, 180, or 270.

Return Value
text_results <list[class TextResult]> : All TextResult structs for successfully decoded barcodes.

Exception
BarcodeReaderError : If error happens, this function will throw a BarcodeReaderError exception that can report the detailed error message.

decode_base64_string

Decodes barcodes from the base64 encoded string.

BarcodeReader.decode_base64_string(base64_string, template_name="")

Parameters

  • [in] base64_string <str> : A base64 encoded string that represents an image.
  • [in] template_name <optional><str> : The template name.

Return Value

text_results <*list[class TextResult]*> : All TextResult structs for successfully decoded barcodes.

Exception

BarcodeReaderError The exception thrown by Dynamsoft Barcode Reader.

Code Snippet

from dbr import *
license_key = 'YOUR-LICENSE-KEY'
base64_string = r'YOUR-BASE64-ENCODED-STRING'

BarcodeReader.init_license(license_key)
reader = BarcodeReader()
try:
    text_results = reader.decode_base64_string(base64_string)
    if text_results != None:
        for text_result in text_results:
            print("Barcode Format :")
            print(text_result.barcode_format_string)
            print("Barcode Text :")
            print(text_result.barcode_text)
            print("-------------")
except BarcodeReaderError as bre:
    print(bre)

init_intermediate_result

Inits an intermediateResult struct with default values.

BarcodeReader.init_intermediate_result(intermediate_result_type)

Parameters

  • [in] intermediate_result_type <EnumIntermediateResultType> : The type of the intermediate result to initialize. Please see EnumIntermediateResultType.

Return Value

intermediate_result <*class IntermediateResult*> : An IntermediateResult struct with default values.

Exception

BarcodeReaderError The exception thrown by Dynamsoft Barcode Reader.

Code Snippet

from dbr import *
license_key = 'YOUR-LICENSE-KEY'
image_file = r'C:\Program Files (x86)\Dynamsoft\{Version number}\Images\AllSupportedBarcodeTypes.tif'

BarcodeReader.init_license(license_key)
reader = BarcodeReader()
try:
    text_results = reader.decode_file(image_file)
    if text_results != None:
        for text_result in text_results:
            print("Barcode Format :")
            print(text_result.barcode_format_string)
            print("Barcode Text :")
            print(text_result.barcode_text)
            print("Localization Points : ")
            print(text_result.localization_result.localization_points)
            print("-------------")
except BarcodeReaderError as bre:
    print(bre)

decode_intermediate_results

Decodes barcode from intermediate results.

BarcodeReader.decode_intermediate_results(intermediate_results, template_name="")

Parameters

  • [in] intermediate_results <list[class IntermediateResults]> : The IntermediateResult array for decoding.
  • [in] template_name <optional><str> : The template name.

Return Value

text_results <*list[class TextResult]*> : All TextResult structs for successfully decoded barcodes.

Exception

BarcodeReaderError The exception thrown by Dynamsoft Barcode Reader.

Code Snippet

from dbr import *
license_key = 'YOUR-LICENSE-KEY'
image_file = r'C:\Program Files (x86)\Dynamsoft\{Version number}\Images\AllSupportedBarcodeTypes.tif'

BarcodeReader.init_license(license_key)
reader = BarcodeReader()
try:
    text_results = reader.decode_file(image_file)
    if text_results != None:
        for text_result in text_results:
            print("Barcode Format :")
            print(text_result.barcode_format_string)
            print("Barcode Text :")
            print(text_result.barcode_text)
            print("Localization Points : ")
            print(text_result.localization_result.localization_points)
            print("-------------")
except BarcodeReaderError as bre:
    print(bre)

This page is compatible for:

Is this page helpful?

YesYes NoNo

In this article:

version 9.6.20

  • Latest version
  • Version 10.x
    • Version 10.4.2100
    • Version 10.4.2000
    • Version 10.4.10
    • Version 10.2.10
    • Version 10.2.0
    • Version 10.0.20
    • Version 10.0.10
    • Version 10.0.0
  • Version 9.x
    • Version 9.6.40
    • Version 9.6.30
    • Version 9.6.20
    • Version 9.6.10
    • Version 9.6.0
    • Version 9.4.0
    • Version 9.2.0
    • Version 9.0.0
  • Version 8.x
    • Version 8.8.0
    • Version 8.6.0
    • Version 8.4.0
    • Version 8.2.0
    • Version 8.1.2
    • Version 8.1.0
    • Version 8.0.0
  • Version 7.x
    • Version 7.6.0
    • Version 7.5.0
  • Documentation Homepage
Change +