Aspose.Barcode for Python via Java Generation and Recognition API docs

BarCodeReader encapsulates an image which may contain one or several barcodes, it then can perform ReadBarCodes operation to detect barcodes. More...

Inherits _MwWrapper.

Public Member Functions

def __init__ (self, Optional[Union[str, os.PathLike, bytes, BinaryIO, Image.Image, None]] image, Optional[Union[List[DecodeType], DecodeType, None]] decode_types)
 Initializes a new instance of the BarCodeReader. More...
 
None abort (self)
 
None barcode_image (self, Optional[Union[str, "os.PathLike"], bytes, BinaryIO, Image.Image, None] image, Optional[Union[List[RectLike], RectLike]] areas)
 Sets bitmap image and areas for Recognition. More...
 
Union[List[DecodeType], DecodeTypebarcode_read_type (self)
 
None barcode_read_type (self, Union[List[DecodeType], DecodeType] types)
 Sets SingleDecodeType type array for Recognition. More...
 
Optional[BarcodeSettingsbarcode_settings (self)
 
bool contains_any (self, Union[List[DecodeType], DecodeType] decode_types)
 
bool export_to_xml (self, str xml_file)
 
Optional[List[BarCodeResult]] found_barcodes (self)
 
int found_count (self)
 
def from_image_with_areas (cls, Optional[Union[str, os.PathLike, bytes, BinaryIO, Image.Image]] image, Optional[Union[List[RectLike], RectLike]] areas, Optional[Union[List[DecodeType], DecodeType]] decode_types)
 Initializes a new instance of the BarCodeReader. More...
 
BarCodeReader import_from_xml (cls, str xml_file)
 Imports BarCode properties from the specified XML file. More...
 
Optional[QualitySettingsquality_settings (self)
 
None quality_settings (self, QualitySettings value)
 
Optional[List[BarCodeResult]] read_barcodes (self)
 
int timeout (self)
 
None timeout (self, int value)
 

Public Attributes

 barcodeSettings
 
 qualitySettings
 
 recognizedResults
 

Detailed Description

BarCodeReader encapsulates an image which may contain one or several barcodes, it then can perform ReadBarCodes operation to detect barcodes.

This sample shows how to detect Code39 and Code128 barcodes.

reader = BarCodeReader("test.png", [DecodeType.CODE_39, DecodeType.CODE_128])
for result in reader.read_barcodes():
print("BarCode Type:", result.code_type_name)
print("BarCode CodeText:", result.code_text)

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
Optional[Union[str, os.PathLike, bytes, BinaryIO, Image.Image, None]]  image,
Optional[Union[List[DecodeType], DecodeType, None]]  decode_types 
)

Initializes a new instance of the BarCodeReader.

Parameters
image encoded as base64 string or path to image
decode_types the array of objects by DecodeType

Member Function Documentation

◆ abort()

None abort (   self)

◆ barcode_image()

None barcode_image (   self,
Optional[Union[str, "os.PathLike"], bytes, BinaryIO, Image.Image, None]  image,
Optional[Union[List[RectLike], RectLike]]  areas 
)

Sets bitmap image and areas for Recognition.

Must be called before ReadBarCodes() method. This sample shows how to detect Code39 and Code128 barcodes.

reader = BarCodeReader(None, None, None)
reader.set_barcode_read_type([DecodeType.CODE_39, DecodeType.CODE_128])
barcode_image = Image.open(image_path)
width, height = barcode_image.size
reader.set_barcode_image(barcode_image, [Assist.Rectangle(0, 0, width, height)])
results = reader.read_barcodes()
for result in results:
print(f"\nBarCode Type: {result.code_type_name}")
print(f"BarCode CodeText: {result.code_text}")
Parameters
imageResource path to image or object of PIL.Image
areas The areas list for recognition
Exceptions
BarCodeException

◆ barcode_read_type() [1/2]

Union[List[DecodeType], DecodeType] barcode_read_type (   self)
Gets the decode types of the input barcode decoding.

◆ barcode_read_type() [2/2]

None barcode_read_type (   self,
Union[List[DecodeType], DecodeType types 
)

Sets SingleDecodeType type array for Recognition.

Must be called before readBarCodes() method.

This sample shows how to detect Code39 and Code128 barcodes.

reader = BarCodeReader(self.image_path, None, None)
reader.barcode_read_type([Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
results = reader.read_barcodes()
for result in results:
print(f"\nBarCode Type: {result.codetype_name()}")
print(f"BarCode CodeText: {result.codetext}")
Parameters
types The SingleDecodeType type array to read.

◆ barcode_settings()

Optional[BarcodeSettings] barcode_settings (   self)
The main BarCode decoding parameters.

Contains parameters that influence the recognized data.

◆ contains_any()

bool contains_any (   self,
Union[List[DecodeType], DecodeType decode_types 
)
Determines whether any of the given decode types is included.

:param decode_types: Types to verify.
:return: True if any of the types are included.

◆ export_to_xml()

bool export_to_xml (   self,
str  xml_file 
)
Exports BarCode properties to an XML file.

◆ found_barcodes()

Optional[List[BarCodeResult]] found_barcodes (   self)
Recognized barcodes as a list of BarCodeResult.

Example:
    reader = Recognition.BarCodeReader(image_path_code39, None, [Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
    reader.read_barcodes()
    for result in reader.found_barcodes:
        print("BarCode CodeText:", result.code_text)

:return: Recognized barcodes.

◆ found_count()

int found_count (   self)
Number of recognized barcodes.

Example:
    reader = Recognition.BarCodeReader(self.image_path, None, [Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
    reader.read_barcodes()
    print(f\"\\nFound {reader.found_count} barcodes\")

:return: Count of recognized barcodes.

◆ from_image_with_areas()

def from_image_with_areas (   cls,
Optional[Union[str, os.PathLike, bytes, BinaryIO, Image.Image]]  image,
Optional[Union[List[RectLike], RectLike]]  areas,
Optional[Union[List[DecodeType], DecodeType]]  decode_types 
)

Initializes a new instance of the BarCodeReader.

Parameters
image encoded as base64 string or path to image
areas array of object by type Rectangle
decode_types the array of objects by DecodeType

◆ import_from_xml()

BarCodeReader import_from_xml (   cls,
str  xml_file 
)

Imports BarCode properties from the specified XML file.

◆ quality_settings() [1/2]

Optional[QualitySettings] quality_settings (   self)
QualitySettings allows configuring recognition quality and speed.

You can quickly set up QualitySettings using presets:
HighPerformance, NormalQuality, HighQuality, MaxBarCodes,
or configure options manually.

Default value: NormalQuality.

\code
reader = BarCodeReader(image_path, None, None)

# set high performance mode
reader.quality_settings = QualitySettings.high_performance()
for result in reader.read_barcodes():
    print("BarCode CodeText:", result.code_text)

# normal quality mode is default
for result in reader.read_barcodes():
    print("BarCode CodeText:", result.code_text)

# set high performance and tweak options
reader.quality_settings = QualitySettings.high_performance()
qs = reader.quality_settings
qs.allow_incorrect_barcodes = True
for result in reader.read_barcodes():
    print("BarCode CodeText:", result.code_text)
\endcode

◆ quality_settings() [2/2]

None quality_settings (   self,
QualitySettings  value 
)

◆ read_barcodes()

Optional[List[BarCodeResult]] read_barcodes (   self)
Reads barcodes from the image.

Example:
    reader = Recognition.BarCodeReader(self.image_path, None, [Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
    for result in reader.read_barcodes():
        print("BarCode CodeText:", result.code_text)

    # or use found_barcodes after reading
    reader.read_barcodes()
    for result in reader.found_barcodes:
        print("BarCode CodeText:", result.code_text)

:return: A list of recognized BarCodeResult objects. If nothing is recognized, an empty list is returned.

◆ timeout() [1/2]

int timeout (   self)
Timeout of the recognition process in milliseconds.

\code
reader = BarCodeReader("test.png")
reader.timeout = 5000
for result in reader.read_barcodes():
    print("BarCode CodeText:", result.code_text)
\endcode

:return: Timeout in milliseconds.

◆ timeout() [2/2]

None timeout (   self,
int  value 
)
Timeout of the recognition process in milliseconds.

:param value: Timeout in milliseconds.

Member Data Documentation

◆ barcodeSettings

barcodeSettings

◆ qualitySettings

qualitySettings

◆ recognizedResults

recognizedResults