verification package

Submodules

verification.controllers module

Handles all requests relevant to the verification service of the API.

verification.controllers.manage_text_extractor(image_of_id)[source]

This function manages the text extraction from an ID images. Management includes preparing text extraction preferences and receiving extracted text.

Args:
image_of_id (:obj:’OpenCV image’): An image of an ID that text must be extracted from.
Returns:
preferences (dict): Prepared list of preferences. May contained additional text extraction or logger preferences. extracted_text (json object): A collection of text extracted from the ID.
verification.controllers.manage_text_verification(preferences, extracted_text, entered_details)[source]

The function manages the preparation before text verification and result of the text verification it self Management includes preparing logger functionality and controlling match percentages and messages.

Args:
preferences (list): A list of preferences. Containing details about logger functionality. extracted_text (JSON object): Contains text extracted from ID image. entered_details (dict): Dictionary containing information that needs to be verified
Returns:
text_match_percentage (float): Value representing the accuracy with which the entered details
matches that of the extracted text.
text_match (dict): Contains intermediate match percentages for different details.
For Example the match percentage between just the date_of_birth fields
is_pass (bool): Indicates if text_verification passes.
If match percentage is above threshold provided in preferences then verification passes. If match percentage is below threshold value provided in preferences then verification fails.
verification.controllers.match_faces(image_of_id, face)[source]

This function receives two images that receive images of faces that need to be verified. It is expected that an image of an ID and an image of a Profile picture will be received. Even if the expected images are not received the function will still apply a best effort solution.

Args:
image_of_id (:obj:’OpenCV image’): An image of an ID that contains a face that needs to be verified face (:obj:’OpenCV image’): A image of a face that needs to be verified
Returns:
bool: Represent if two faces indeed match True if distance calculated is
below a threshold value. False if the distance calculated is above threshold value.
float: Return Euclidean distance between the vector representation
of the two faces.
verification.controllers.receive_details()[source]

This function receives the details that need to be verified from the flask handler.

Returns:
entered_details (dict): Details that need to be verified with that extracted from image.
verification.controllers.receive_faces(match_face=True)[source]

This function receives faces/ID from request flask handler. The function checks for multiple means of receiving the faces/ID. These include

Receiving image by file path Receiving image by URL Receiving image by file Stream

It is expected that an image of a face and an image of an ID will be sent. However, if the order is not followed that system will still be able to return the best effort result without loss of accuracy.

Args:
match_face (bool): Indicates if additional profile of a face should be extracted.
If an additional face should not be extracted simply return the ID image.
Returns:
image_of_id (:obj:’OpenCV image’): An image of a ID. face (:obj:’OpenCV image’): An image of a face. If match_face is set to True
verification.controllers.verify_faces()[source]

Sample function to return a match percentage of an ID face image and picture of face URL: http://localhost:5000/verifyFaces

verification.controllers.verify_id()[source]

Sample function to return a match percentage of an ID image and provided personal information and picture of face. URL: http://localhost:5000/verifyID

verification.controllers.verify_info()[source]

Sample function to return a match percentage of an ID image and provided personal information

verification.face_verify module

A class that is used to extract and compare two images of faces and calculate the resulting match.

class verification.face_verify.FaceVerify(shape_predictor_path, face_recognition_path)[source]

Bases: object

The FaceVerify class is responsible for 1. Detecting the face. 2. Generating a threshold value that determines the likeness of two individuals in an image

verify(face1, face2, threshold=0.55)[source]

This function determines a percentage value of how close the faces in the images passed are to each other if the determined value if below the threshold value passed by the user a boolean value of True is returned indicating that the faces in the images passed indeed match.

The Verify function makes use of the dlib library which guarantees 99.38% accuracy on the standard Labeled Faces in the Wild benchmark.

Args:

face1 (:obj:’OpenCV image’): The first image containing the face that should be compared. face2 (:obj:’OpenCV image’): The second image containing the face that should be compared threshold (float): The threshold value determines at what distance the two images are

considered the same person. If a verify score is below the threshold value the faces are considered a match. The Labled Faces in the Wild benchmark recommend a default threshold of 0.6 but a threshold of 0.55 was decided on since a threshold of 0.55 represents the problem better.
Returns:
bool: Represent if two face indeed match True if distance calculated is
below threshold value. False if the distance calculated is above threshold value.

float: Return Euclidean distance between the vector representation of the two faces

Raises:
ValueError: If no face can be detected no faces can be matched and operation should be aborted.

verification.text_verify module

Contains the logic used to verify the extracted text from a form of ID.

class verification.text_verify.TextVerify[source]

Bases: object

This class is responsible for the verification of text that is extracted from an ID.

validate_id_number(id_number, valid_length=13)[source]

Determines whether a given id number is valid or not.

Args:
id_number (str): valid_length (int): Specifies the length of a given id number to be considered as valid.
Returns:
(bool): True if the id number is valid, False otherwise.
Raises:
TypeError: If id_number is not a string containing only numeric characters. TypeError: If valid_length is not an integer.
verify(extracted, verifier, threshold=75.0, min_matches=4, verbose=False)[source]

This function is responsible for the verification of text that is extracted from an ID and is passed in, along with information that is to be used to verify the extracted text.

Args:

extracted (dict): A dictionary containing the information that was extracted from an ID. verifier (dict): A dictionary containing the information against which the extracted data is to be

verified.
threshold (float): A threshold percentage (out of 100) that is used to determine whether or not the
final match percentage is accepted as verified.
min_matches (int): The minimum number of matches that have to be calculated for the final result to be
considered as verified.

verbose (bool): Indicates whether or not to return all of the calculated match percentages.

Returns:
(bool, float | dict): The first value returned is a bool that indicates whether or not the total
percentage match is above the specified threshold value, while the second return value is the total percentage match value if verbose is False, or returns a dict of all the determined percentage match values if verbose is True.
Raises:
TypeError: If extracted is not a dictionary. TypeError: If verifier is not a dictionary. TypeError: If threshold is not a float. TypeError: If min_matches is not an integer. TypeError: If verbose is not a boolean.

Module contents