RPA.DocumentAI.Base64AI

Gets through all the recognized signatures in the queried image and returns only the ones passing the confidence & similarity thresholds.

Arguments

ArgumentTypeDefault value
match_responseDict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, Nonenull
confidence_thresholdfloat0.8
similarity_thresholdfloat0.8

Additionally, this keyword simplifies the original input match_response structure and returns a dictionary with all the detected and accepted reference signatures as keys, and lists of similar enough query signatures as values.

  • Each reference signature (key) is a tuple of (index, coordinates).
  • Each query signature (sub-value) is a dictionary of {index, coords, similarity}.
  • The coordinates describe the bounding-box enclosing the detected signature portion from the original image, as follows: (left, top, right, bottom) corners.

Use the original match_response object and the indexes from here if you need to retrieve extra details not found here (e.g. confidence score). Use the Get Signature Image to save and preview the image crop belonging to the signature of choice.

param match_response:The raw JSON-like response retrieved with the Get Matching Signatures keyword.
param confidence_threshold:The minimum accepted confidence score (0.0-1.0) for a candidate to be considered a signature. (to avoid false-positives)
param similarity_threshold:The minimum accepted similarity score (0.0-1.0) for a query signature to be considered an alike signature. (to discard different or fraudulent signatures)
returns:A dictionary of accepted reference signatures and their similar ones found in the queried image.

Example: Robot Framework

*** Tasks *** Match Signatures &{matches} = Filter Matching Signatures ${sigs} Log Dictionary ${matches}

Example: Python

matches = lib.filter_matching_signatures(sigs) print(matches)

Helper keyword to get found fields from a prediction result. For example see Scan Document File or Scan Document URL keyword.

Arguments

ArgumentTypeDefault value
predictionDict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, Nonenull
param prediction:prediction result dictionary
return:list of found fields

Returns a list of matching signatures found from the reference into the queried image.

Arguments

ArgumentTypeDefault value
reference_imagePath, strnull
query_imagePath, strnull

The input images can be paths to the files or URLs.

The output JSON-like dictionary contains all the details from the API, like the detected signatures in both the reference and query image and for every such signature, its bounding-box geometry, confidence and similarity score. Use the Filter Matching Signatures over this value to get a simpler structure.

param reference_image:The reference image (jpg/png) to check query signatures against. (e.g. driving license, ID card)
param query_image:The query image containing signatures similar to the ones from the reference image. (e.g. signed contract, bank check)
returns:A JSON-like dictionary revealing recognized signatures and how much they resemble with each other.

Example: Robot Framework

*** Tasks *** Match Signatures ${ref_image} = Set Variable driving-license.jpg ${query_image} = Set Variable signed-check.png ${sigs} = Get Matching Signatures ${ref_image} ${query_image}

Example: Python

from RPA.DocumentAI.Base64AI import Base64AI lib = Base64AI() sigs = lib.get_matching_signatures( "driving-license.jpg", "signed-check.png" )

Portal example: https://github.com/robocorp/example-signature-match-assistant

Retrieves and saves locally the image cut belonging to the provided index.

Arguments

ArgumentTypeDefault value
match_responseDict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, Nonenull
null
indexintnull
referenceboolFalse
pathPath, str, NoneNone

The image data itself is provided with the original match_response object as base64 encoded content. This utility keyword retrieves, decodes and saves it on the local disk customized with the path parameter. By default, the searched index is considered a query image, switch to the reference type by enabling it with the reference parameter.

param match_response:The raw JSON-like response retrieved with the Get Matching Signatures keyword.
param index:The image ID (numeric) found along the coordinates in the output of the Filter Matching Signatures keyword. (the list order is stable)
param reference:Set this to True if you're looking for a reference (not query) image instead. (off by default)
param path:Set an explicit output path (including file name) for the locally saved image. (uses the output directory as default)
returns:The image path of the locally saved file.

Example: Robot Framework

*** Tasks *** Match Signatures @{ref_sigs} = Get Dictionary Keys ${matches} @{qry_sigs} = Get From Dictionary ${matches} ${ref_sigs}[${0}] &{qry_sig} = Set Variable ${qry_sigs}[${0}] ${path} = Get Signature Image ${sigs} index=${qry_sig}[index] Log To Console Preview query signature image crop: ${path}

Example: Python

qry_sig = list(matches.values())[0][0] path = lib.get_signature_image(sigs, index=qry_sig["index"]) print("Preview query signature image crop: ", path)

Get user data including details on credits used and credits remaining for the Base64 service.

Returned user data contains following keys:

  • givenName
  • familyName
  • email
  • hasWorkEmail
  • companyName
  • numberOfCredits
  • numberOfPages
  • numberOfUploads
  • numberOfCreditsSpentOnDocuments (visible if used)
  • numberOfCreditsSpentOnFaceDetection (visible if used)
  • numberOfCreditsSpentOnFaceRecognition (visible if used)
  • hasActiveAwsContract
  • subscriptionType
  • subscriptionPeriod
  • tags
  • ccEmails
  • status
  • remainingCredits (calculated by the keyword)
return:object containing details on the API user

Robot Framework example:

${userdata}= Get User Data Log To Console I have still ${userdata}[remainingCredits] credits left

Python example:

userdata = baselib.get_user_data() print(f"I have still {userdata['remainingCredits']} credits left")

Scan a document file. Can be given a model_types to specifically target certain models.

Arguments

ArgumentTypeDefault value
file_pathstrnull
model_typesList[str], str, NoneNone
mockboolFalse
param file_path:filepath to the file
param model_types:single model type or list of model types
param mock:set to True to use /mock/scan endpoint instead of /scan
return:result of the document scan

Robot Framework example:

${results}= Scan Document File ... ${CURDIR}${/}files${/}IMG_8277.jpeg ... model_types=finance/check/usa,finance/invoice FOR ${result} IN @{results} Log To Console Model: ${result}[model] Log To Console Fields: ${result}[fields] Log To Console Text (OCR): ${result}[ocr] END

Python example:

result = baselib.scan_document_file( "./files/Invoice-1120.pdf", model_types="finance/invoice,finance/check/usa", ) for r in result: print(f"Model: {r['model']}") for key, val in r["fields"].items(): print(f"{key}: {val['value']}") print(f"Text (OCR): {r['ocr']}")

Scan a document URL. Can be given a model_types to specifically target certain models.

Arguments

ArgumentTypeDefault value
urlstrnull
model_typesList[str], str, NoneNone
mockboolFalse
param url:valid url to a file
param model_types:single model type or list of model types
param mock:set to True to use /mock/scan endpoint instead of /scan
return:result of the document scan

Robot Framework example:

${results}= Scan Document URL ... https://base64.ai/static/content/features/data-extraction/models//2.png FOR ${result} IN @{results} Log To Console Model: ${result}[model] Log To Console Fields: ${result}[fields] Log To Console Text (OCR): ${result}[ocr] END

Python example:

result = baselib.scan_document_url( "https://base64.ai/static/content/features/data-extraction/models//2.png" ) for r in result: print(f"Model: {r['model']}") for key, props in r["fields"].items(): print(f"FIELD {key}: {props['value']}") print(f"Text (OCR): {r['ocr']}")

Set Base64 AI request headers with email and key related to API.

Arguments

ArgumentTypeDefault value
api_emailstrnull
api_keystrnull
param api_email:email address related to the API
param api_key:key related to the API

Robot Framework example:

${secrets}= Get Secret base64ai-auth Set Authorization ${secrets}[email-address] ${secrets}[apikey]

Python example:

secrets = Vault().get_secret("base64ai-auth") baselib = Base64AI() baselib.set_authorization(secrets["email-address"], secrets["apikey"])