QR, Bar Codes
Note
It’s required to install codes
from Optional dependencies section.
Extractor & Decoder
- class aiviro.modules.codes.CodesExtractor(pdf_data: Optional[Union[aiviro.modules.pdf.robot.PDFRobot, aiviro.modules.pdf.convertor.PDFConvertor, List[numpy.ndarray]]] = None)
Codes extractor detects and extracts QR and Bar codes from PDFs and images. For list of supported codes, see https://pypi.org/project/pyzbar/ package documentation.
- Parameters
pdf_data – Source of the image data for processing
- Example
>>> from aiviro.modules.pdf import create_pdf_robot >>> from aiviro.modules.codes import CodesExtractor >>> r = create_pdf_robot("path/to/file.pdf") >>> ce = CodesExtractor(r) >>> qr_codes = ce.qr_codes(page=1) >>> bar_codes = ce.bar_codes(page=0)
>>> from aiviro.modules.codes import ZBarSymbol >>> r = create_pdf_robot("path/to/file.pdf") >>> ce = CodesExtractor(r) >>> custom_codes = ce.any_codes(code_types=[ZBarSymbol.PDF417])
- qr_codes(page: int = 0) List[aiviro.modules.codes.common.CodeData]
Extracts QR codes.
- Parameters
page – Index of the page to process
- bar_codes(page: int = 0) List[aiviro.modules.codes.common.CodeData]
Extracts Bar codes.
- Parameters
page – Index of the page to process
- any_codes(page: int, code_types: List[pyzbar.wrapper.ZBarSymbol]) List[aiviro.modules.codes.common.CodeData]
Extracts any of the supported codes.
- Parameters
page – Index of the page to process
code_types – Types of codes to extract
- static any_codes_img(image: numpy.ndarray, code_types: List[pyzbar.wrapper.ZBarSymbol]) List[aiviro.modules.codes.common.CodeData]
Extracts any of the supported codes from input image.
- Parameters
image – Image containing codes
code_types – Types of codes to extract
- class aiviro.modules.codes.BaseCodeDecoder
Base class to inherit from for creating custom code decoder.
Czech Invoice Format
- class aiviro.modules.codes.CzechQRInvoiceDecoder
Decodes QR data based on https://qr-faktura.cz/ format definition. See
CzechQRInvoiceData
for further information.- Example
>>> from aiviro.modules.pdf import create_pdf_robot >>> from aiviro.modules.codes import CodesExtractor, CzechQRInvoiceDecoder >>> r = create_pdf_robot("path/to/file.pdf") >>> qr_data = CodesExtractor(r).qr_codes() >>> decoded_data = CzechQRInvoiceDecoder().decode(qr_data)[0] ... >>> invoice_id = decoded_data.get_value("ID")
- class aiviro.modules.codes.CzechQRInvoiceData(_dict_values: typing.Dict[str, str] = <factory>)
Data class containing decoded data from QR code.
- property currency: str
Returns type of currency, based on ‘CC’ key.
- property total_amount: decimal.Decimal
Returns total_amount, based on ‘AM’ key.
- get_decimal(key: str = 'AM') decimal.Decimal
Returns value in Decimal format based on input key.
- get_date(key: str = 'DD') datetime.date
Returns value in date format based on input key.