Web Demos

BARCODE READER SDK DEMO

Explore the flexibe barcode reading settings to optimize for your specific usage scenario.

WEB TWAIN SDK DEMO

Try the most popular web scanner features: scan images, import local images and PDF files, edit, save to local, upload to database, and etc.

BARCODE READER JAVASCRIPT DEMO

Transform any camera-equipped devices into real-time, browser-based barcode and QR code scanners.

MRZ SCANNER WEB DEMO

Detects the machine-readable zone of a passport, scans the text, and parses into human-readable data.

APP STORE DEMOS

BARCODE READER SDK FOR IOS

BARCODE READER SDK FOR ANDROID

VIEW MORE DEMOS >
Dev Center
Table of contents

Thanks for downloading Dynamsoft Barcode Reader Package!

Your download will start shortly. If your download does not begin, click here to retry.

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.
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="")

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.

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 <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="")

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.

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.

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:

Version 7.5.0

Is this page helpful?

YesYes NoNo

In this article:

latest version

  • Latest version
  • Version 9.0.0
  • 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.6.0
  • Version 7.5.0
Change +
© 2003–2022 Dynamsoft. All rights reserved.
Privacy Statement / Site Map / Home / Purchase / Support