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 BaseJavaClass.

Public Member Functions

def __init__ (self, Union[str, Image.Image, None] image, Optional[Union[List[Assist.Rectangle], Assist.Rectangle]] areas, Optional[Union[List[DecodeType], DecodeType]] decodeTypes)
 Initializes a new instance of the BarCodeReader. More...
 
None abort (self)
 
bool containsAny (self, Union[List[DecodeType], DecodeType] decodeTypes)
 Determines whether any of the given decode types is included. More...
 
bool exportToXml (self, str xmlFile)
 Exports BarCode properties to the xml-file specified. More...
 
List[DecodeTypegetBarCodeDecodeType (self)
 Gets the decode type of the input barcode decoding. More...
 
Optional[BarcodeSettingsgetBarcodeSettings (self)
 The main BarCode decoding parameters. More...
 
Optional[List[BarCodeResult]] getFoundBarCodes (self)
 Gets recognized BarCodeResult array. More...
 
int getFoundCount (self)
 Gets recognized barcodes count. More...
 
Optional[QualitySettingsgetQualitySettings (self)
 QualitySettings allows to configure recognition quality and speed manually. More...
 
int getTimeout (self)
 Gets the timeout of recognition process in milliseconds. More...
 
None init (self)
 
Optional[List[BarCodeResult]] readBarCodes (self)
 Reads BarCodeResult from the image. More...
 
None setBarCodeImage (self, Union[str, Image.Image] imageResource, Optional[Union[List[Assist.Rectangle], Assist.Rectangle]] areas)
 Sets bitmap image and areas for Recognition. More...
 
None setBarCodeReadType (self, Union[List[DecodeType], DecodeType] types)
 Sets SingleDecodeType type array for Recognition. More...
 
None setQualitySettings (self, QualitySettings value)
 QualitySettings allows to configure recognition quality and speed manually. More...
 
None setTimeout (self, int value)
 Sets the timeout of recognition process in milliseconds. More...
 
- Public Member Functions inherited from BaseJavaClass
None __init__ (self, javaClass)
 
def getJavaClass (self)
 
str getJavaClassName (self)
 
bool isNull (self)
 
None printJavaClassName (self)
 
None setJavaClass (self, javaClass)
 

Static Public Member Functions

BarCodeReader construct (javaClass)
 
def convertAreasToJavaFormattedAreas (areas)
 
jpype.JArray convertDecodeTypeToJavaDecodeType (Optional[Union[List[DecodeType], DecodeType]] decodeTypes)
 
Optional[bytes] convertToBase64Image (Union[str, Image.Image, None] image)
 
BarCodeReader importFromXml (str xmlFile)
 Exports BarCode properties to the xml-file specified. More...
 

Public Attributes

 barcodeSettings
 
 qualitySettings
 
 recognizedResults
 
- Public Attributes inherited from BaseJavaClass
 javaClass
 
 javaClassName
 

Static Public Attributes

string javaClassName = "com.aspose.mw.barcode.recognition.MwBarCodeReader"
 

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 = Recognition.BarCodeReader("test.png", None, [DecodeType.CODE_39, DecodeType.CODE_128])
for result in reader.readBarCodes():
print("BarCode Type: " + result.getCodeTypeName())
print("BarCode CodeText: " + result.getCodeText())

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
Union[str, Image.Image, None]  image,
Optional[Union[List[Assist.Rectangle], Assist.Rectangle]]  areas,
Optional[Union[List[DecodeType], DecodeType]]  decodeTypes 
)

Initializes a new instance of the BarCodeReader.

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

Member Function Documentation

◆ abort()

None abort (   self)

◆ construct()

BarCodeReader construct (   javaClass)
static

◆ containsAny()

bool containsAny (   self,
Union[List[DecodeType], DecodeType decodeTypes 
)

Determines whether any of the given decode types is included.

Parameters
decodeTypes Types to verify.
Returns
: bool Value is true if any types are included.

◆ convertAreasToJavaFormattedAreas()

def convertAreasToJavaFormattedAreas (   areas)
static

◆ convertDecodeTypeToJavaDecodeType()

jpype.JArray convertDecodeTypeToJavaDecodeType ( Optional[Union[List[DecodeType], DecodeType]]  decodeTypes)
static

◆ convertToBase64Image()

Optional[bytes] convertToBase64Image ( Union[str, Image.Image, None]  image)
static

◆ exportToXml()

bool exportToXml (   self,
str  xmlFile 
)

Exports BarCode properties to the xml-file specified.

Parameters
xmlFile The name of the file
Returns
: export completed successfully. Returns True in case of success and False otherwise

◆ getBarCodeDecodeType()

List[DecodeType] getBarCodeDecodeType (   self)

Gets the decode type of the input barcode decoding.

◆ getBarcodeSettings()

Optional[BarcodeSettings] getBarcodeSettings (   self)

The main BarCode decoding parameters.

Contains parameters which make influence on recognized data.

Returns
The main BarCode decoding parameters

◆ getFoundBarCodes()

Optional[List[BarCodeResult]] getFoundBarCodes (   self)

Gets recognized BarCodeResult array.

This sample shows how to read barcodes with BarCodeReader

reader = Recognition.BarCodeReader(image_path_code39, None,[Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
reader.readBarCodes()
for result in reader.getFoundBarCodes():
print("\nBarCode CodeText: " + result.getCodeText())
Returns
: The recognized BarCodeResult array

◆ getFoundCount()

int getFoundCount (   self)

Gets recognized barcodes count.


This sample shows how to read barcodes with BarCodeReader

reader = Recognition.BarCodeReader(self.image_path, None,
[Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
reader.readBarCodes()
print(f"\nFound {str(reader.getFoundCount())} barcodes")
Returns
The recognized barcodes count

◆ getQualitySettings()

Optional[QualitySettings] getQualitySettings (   self)

QualitySettings allows to configure recognition quality and speed manually.

You can quickly set up QualitySettings by embedded presets: HighPerformance, NormalQuality,

HighQuality, MaxBarCodes or you can manually configure separate options.

Default value of QualitySettings is NormalQuality.

This sample shows how to use QualitySettings with BarCodeReader

reader = Recognition.BarCodeReader(self.image_path, None, None)
# set high performance mode
reader.setQualitySettings(Recognition.QualitySettings.getHighPerformance())
for result in reader.readBarCodes():
print(f"\nBarCode CodeText: {result.getCodeText()}")
reader = Recognition.BarCodeReader(self.image_path, None, [Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
# normal quality mode is set by default
for result in reader.readBarCodes():
print(f"\nBarCode CodeText: {result.getCodeText()}")
reader = Recognition.BarCodeReader(self.image_path, None, [Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
# set high performance mode
reader.setQualitySettings(Recognition.QualitySettings.getHighPerformance())
# set separate options
qualitySettings = reader.getQualitySettings()
qualitySettings.setAllowIncorrectBarcodes(True)
for result in reader.readBarCodes():
print(f"\nBarCode CodeText: {result.getCodeText()}")

QualitySettings to configure recognition quality and speed.

◆ getTimeout()

int getTimeout (   self)

Gets the timeout of recognition process in milliseconds.

reader = Recognition.BarCodeReader("test.png", None, None)
reader.setTimeout(5000)
for result in reader.readBarCodes():
print("BarCode CodeText: " + result.getCodeText())
Returns
: The timeout.

◆ importFromXml()

BarCodeReader importFromXml ( str  xmlFile)
static

Exports BarCode properties to the xml-file specified.

Parameters
xmlFile: xmlFile The name of the file
Returns
: export completed successfully. Returns True in case of success and False otherwise

◆ init()

None init (   self)

Reimplemented from BaseJavaClass.

◆ readBarCodes()

Optional[List[BarCodeResult]] readBarCodes (   self)

Reads BarCodeResult from the image.

    This sample shows how to read barcodes with BarCodeReader
    \code
     reader = Recognition.BarCodeReader(self.image_path, None, [Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
     for result in reader.readBarCodes():
       print(f"\nBarCode CodeText: {result.getCodeText()}")
     reader = Recognition.BarCodeReader(self.image_path, None, [Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
     reader.readBarCodes()
     for result in reader.getFoundBarCodes():
       print(f"\nBarCode CodeText: {result.getCodeText()}")
    \endcode
    @return: Returns array of recognized @code BarCodeResult @endcode s on the image. If nothing is recognized, zero array is returned.

◆ setBarCodeImage()

None setBarCodeImage (   self,
Union[str, Image.Image]  imageResource,
Optional[Union[List[Assist.Rectangle], Assist.Rectangle]]  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 = Recognition.BarCodeReader(None, None, None)
reader.setBarCodeReadType([Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
barcodeImage = Image.open(self.image_path)
width, height = barcodeImage.size
reader.setBarCodeImage(barcodeImage, [Assist.Rectangle(0, 0, width, height)])
results = reader.readBarCodes()
for result in results:
print(f"\nBarCode Type: {result.getCodeTypeName()}")
print(f"BarCode CodeText: {result.getCodeText()}")
Parameters
imageResource path to image or object of PIL.Image
areas The areas list for recognition
Exceptions
BarCodeException

◆ setBarCodeReadType()

None setBarCodeReadType (   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.
     \code
       reader = Recognition.BarCodeReader(self.image_path, None, None)
       reader.setBarCodeReadType([Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
       results = reader.readBarCodes()
       for result in results:
         print(f"\nBarCode Type: {result.getCodeTypeName()}")
         print(f"BarCode CodeText: {result.getCodeText()}")
     \endcode
    @param: types The SingleDecodeType type array to read.

◆ setQualitySettings()

None setQualitySettings (   self,
QualitySettings  value 
)

QualitySettings allows to configure recognition quality and speed manually.

You can quickly set up QualitySettings by embedded presets: HighPerformance, NormalQuality,

HighQuality, MaxBarCodes or you can manually configure separate options.

Default value of QualitySettings is NormalQuality.

This sample shows how to use QualitySettings with BarCodeReader

reader = Recognition.BarCodeReader(self.image_path, None, None)
# set high performance mode
reader.setQualitySettings(Recognition.QualitySettings.getHighPerformance())
for result in reader.readBarCodes():
print(f"\nBarCode CodeText: {result.getCodeText()}")
reader = Recognition.BarCodeReader(self.image_path, None, [Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
# normal quality mode is set by default
for result in reader.readBarCodes():
print(f"\nBarCode CodeText: {result.getCodeText()}")
reader = Recognition.BarCodeReader(self.image_path, None, [Recognition.DecodeType.CODE_39, Recognition.DecodeType.CODE_128])
# set high performance mode
reader.setQualitySettings(Recognition.QualitySettings.getHighPerformance())
# set separate options
qualitySettings = reader.getQualitySettings()
qualitySettings.setAllowIncorrectBarcodes(True)
for result in reader.readBarCodes():
print(f"\nBarCode CodeText: {result.getCodeText()}")

QualitySettings to configure recognition quality and speed.

◆ setTimeout()

None setTimeout (   self,
int  value 
)

Sets the timeout of recognition process in milliseconds.

reader = Recognition.BarCodeReader("test.png", None, None)
reader.setTimeout(5000)
results = reader.readBarCodes()
for result in results:
print("BarCode CodeText: " + result.getCodeText())
Parameters
value The timeout.

Member Data Documentation

◆ barcodeSettings

barcodeSettings

◆ javaClassName

string javaClassName = "com.aspose.mw.barcode.recognition.MwBarCodeReader"
static

◆ qualitySettings

qualitySettings

◆ recognizedResults

recognizedResults