QR & Bar Codes

Aiviro is capable of processing Bar codes, QR codes, including specialized formats like Czech QR invoice codes. For full list of supported code types, see classes below.

Extractors

class aiviro.actions.codes.extractors.QRCodesExtractor(images: list[ndarray], page: int = 0)

Detects and extracts QR codes from images. For a list of supported codes, see https://pypi.org/project/pyzbar/ package documentation.

Example:

>>> from aiviro.actions.codes import QRCodesExtractor, CzechQRInvoiceDecoder
>>> from numpy import ndarray
>>> image: ndarray  = ... # e.g.: load an image from a source and convert it to a numpy array
>>> qr_data = QRCodesExtractor(images=[image])()
>>> if qr_data:
>>>     decoded_data = CzechQRInvoiceDecoder(qr_data[0])()
>>>     currency = decoded_data.key_cc
>>>     total_amount = decoded_data.key_am
>>>     due_date = decoded_data.key_dt
execute() list[CodeData]

Processes the current page to extract QR codes from the image.

Returns:

List of extracted QR codes as a CodeData objects.

class aiviro.actions.codes.extractors.BarCodesExtractor(images: list[ndarray], page: int = 0)

Inherits from BaseCodesExtractor and provides functionality for extracting specific types of bar codes (CODE39, CODE93, CODE128) from a given image. It parses the input image and processes the data to identify and retrieve bar codes in a structured format.

Example:

>>> from aiviro.modules.pdf import create_pdf_robot
>>> from aiviro.actions.codes import BarCodesExtractor, CzechQRInvoiceDecoder
>>> r = create_pdf_robot("path/to/file.pdf")
>>> bar_codes = BarCodesExtractor(images=r.pages)()
>>> if bar_codes:
>>>     print(bar_codes[0].text)
execute() list[CodeData]

Processes the provided page to extract bar codes (CODE39, CODE93, CODE128) from the image.

Returns:

List of extracted bar codes as a CodeData objects.

class aiviro.actions.codes.extractors.AnyCodesExtractor(images: list[ndarray], code_types: list[ZBarSymbol], page: int = 0)

Extracts any codes from images provided by the user. For a list of supported codes, see https://pypi.org/project/pyzbar/ package documentation.

Parameters:
  • images – Source of the image data for processing

  • code_types – Types of codes to extract

  • page – Index of the page to process

Example:

>>> from aiviro.modules.pdf import create_pdf_robot
>>> from aiviro.actions.codes import AnyCodesExtractor, CzechQRInvoiceDecoder, ZBarSymbol
>>> r = create_pdf_robot("path/to/file.pdf")
>>> required_codes = [ZBarSymbol.ISBN10]  # or any other supported code type
>>> page = 1  # let's say ISBN code is on the second page
>>> isbn_codes = AnyCodesExtractor(images=r.pages, code_types=required_codes, page=page)()
>>> if isbn_codes:
>>>     print(isbn_codes[0].text)
execute() list[CodeData]

Processes the provided page to extract required codes from the image.

Returns:

List of extracted codes as a CodeData objects.

Czech QR Decoder

class aiviro.actions.codes.decoder.CzechQRInvoiceDecoder(raw_text: CodeData)

Decodes QR data based on https://qr-faktura.cz/ format definition. See CzechQRInvoiceData for further information.

Example:

>>> from aiviro.actions.codes import QRCodesExtractor, CzechQRInvoiceDecoder
>>> from numpy import ndarray
>>> img: ndarray  = ... # e.g.: load an image from a source and convert it to a numpy array
>>> qr_data = QRCodesExtractor(images=[img])()
>>> if qr_data:
>>>     decoded_data = CzechQRInvoiceDecoder(qr_data[0])()
>>>     invoice_id = decoded_data.key_id

Data Schemas

pydantic model aiviro.actions.codes.schemas.CodeData
field box: BoundBox [Required]
field page_index: int = -1
field text: str [Required]
field type: str [Required]
pydantic model aiviro.actions.codes.schemas.CzechQRInvoiceData

Data class containing decoded data from QR code. For all possible keys, see https://www.kdpcr.cz/informace/qr-faktura/popis-formatu

field key_acc: str | None = None
field key_am: Decimal | None = None
field key_cc: str | None = None
field key_dd: date | None = None
field key_dt: date | None = None
field key_duzp: date | None = None
field key_fx: Decimal | None = None
field key_fxa: Decimal | None = None
field key_id: str | None = None
field key_ini: str | None = None
field key_inr: str | None = None
field key_msg: str | None = None
field key_on: str | None = None
field key_t0: Decimal | None = None
field key_t1: Decimal | None = None
field key_t2: Decimal | None = None
field key_tb0: Decimal | None = None
field key_tb1: Decimal | None = None
field key_tb2: Decimal | None = None
field key_vii: str | None = None
field key_vir: str | None = None
field key_vs: str | None = None
field raw_values: dict[str, str] [Optional]
classmethod from_raw_values(values: dict[str, str]) CzechQRInvoiceData

Populate fields from values dictionary