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
- 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)
- 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)
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
- 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
- classmethod from_raw_values(values: dict[str, str]) CzechQRInvoiceData
Populate fields from values dictionary