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_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.
  • [in] template_name <optional><str> : The template name.

Return value

text_results <*list[class TextResult]*> : All text results.

Exceptions

BarcodeReaderError The exception thrown by Dynamsoft Barcode Reader.

Code Snippet

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

reader = BarcodeReader()
reader.init_license(license_key)
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 text results.

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 = 't0260NwAAAHV***************'
image_file = r'C:\Program Files (x86)\Dynamsoft\{Version number}\Images\AllSupportedBarcodeTypes.tif'

image = cv2.imread(image_file)

reader = BarcodeReader()
reader.init_license(license_key)
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

All barcode text results decoded successfully.

Exceptions

BarcodeReaderError The exception thrown by Dynamsoft Barcode Reader.

Code Snippet

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

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

reader = BarcodeReader()
reader.init_license(license_key)
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)

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

In this article:

version 7.5.0

  • Latest version
  • Version 10.x
    • 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
Change +