hutts_verification.image_preprocessing package

Submodules

hutts_verification.image_preprocessing.blur_manager module

Wraps all the functionality required for applying blurring techniques to an image.

class BlurManager(blur_type, kernel_size)[source]

Bases: object

The blur is responsible for applying different blur techniques to the images passed.

apply(image)[source]

This performs the blurring.

Parameters:image – The image to be blurred.
Raises:
  • NameError: If invalid blur type is provided i.e. Normal, Gaussian or Median.
Returns:
  • (obj): The blurred OpenCV image.
blur(image, blur_kernel=[(3, 3)])[source]

This function applies basic blurring to the image passed.

Parameters:
  • (obj) (image) – OpenCV image to which basic blurring should be applied to.
  • (int list) (blur_kernel) – Represent the kernel dimension by which basic blurring should be applied to.
Raises:
  • ValueError: If a blur_kernel with an invalid length is provided.
  • TypeError: If a blur_kernel is not of type list.
Returns:
  • (obj): A modified copy of the OpenCV image where basic blurring was applied to the image.
gaussianBlur(image, blur_kernel=[(7, 7)])[source]

This function applies Gaussian blurring to the image passed.

Parameters:
  • (obj) (image) – OpenCV image to which Gaussian blurring should be applied to.
  • (Integer list) (blur_kernel) – Represent the kernel dimension by which basic blurring should be applied to.
Raises:
  • ValueError: If a blur_kernel with an invalid length is provided.
  • TypeError: If a blur_kernel is not of type list.
Returns:
  • (obj): A modified copy of the OpenCV image where Gaussian blurring was applied to the image.
medianBlur(image, blur_kernel=[3])[source]

This function applies Median blurring to the image passed.

Parameters:
  • (obj) (image) – OpenCV image to which Median blurring should be applied to.
  • (int list) (blur_kernel) – Represent the kernel dimension by which median blurring should be applied to.
Raises:
  • TypeError: If a blur_kernel is not of type list.
  • ValueError: If a blur_kernel with an invalid length is provided.
Returns:
(obj): A modified copy of the image where Median blurring was applied to the image.

hutts_verification.image_preprocessing.build_director module

This class is responsible for controlling the PipelineBuilder.

class BuildDirector[source]

Bases: object

The BuildDirector constructs the Pipeline using the PipelineBuilder.

static construct_face_extract_pipeline()[source]

This function constructs the pipeline for face extraction. This includes building different managers with their specific parameters. These managers will be called within the pipeline when executed.

Returns:
  • (obj): Pipeline for facial extraction.
static construct_text_extract_pipeline(preferences, identification_type)[source]

This function constructs the pipeline for text extraction. This includes building different managers with their specific parameters. These managers will be called within the pipeline when executed.

Parameters:
  • (dict) (preferences) – User-specified techniques to use in pipeline.
  • (str) (identification_type) – Contains the type of identification, this is used to determine which techniques are used.
Returns:
  • (obj): Pipeline used for text extraction.

hutts_verification.image_preprocessing.color_manager module

Wraps all the functionality required to manipulate the color channels in an image.

class ColorManager(color_extraction_type, channel='green', kernel_size=(13, 7))[source]

Bases: object

The Color manager is responsible for applying several color management techniques to the image passed.

apply(image)[source]

This performs the specified processing technique.

Parameters:image – The image to which the technique must be applied.
Raises:
  • NameError: If an invalid color extraction type is provided (other than
    histogram, extract, black hat or top hat (white hat)).
Returns:
  • (obj): The modified OpenCV image.
blackHat(image, rect_kernel_size=(13, 7))[source]

This function applies blackhat color changes to the image passed.

Parameters:
  • (obj) (image) – OpenCV image to which black hat color changes should be applied to.
  • (list) (rect_kernel_size) – Represents the kernel dimensions by which blackHat morphology changes should be applied to.
Raises:
  • TypeError: If the kernel size type is not a tuple.
  • ValueError: If the kernel size tuple contains more than 2 items.
Returns:
  • (obj): A modified copy of the image blackHat morphology applied to an image.
extractChannel(image, image_channel='green')[source]

This function extracts a selected color channel from an image.

Parameters:
  • (obj) (image) – OpenCV image for which the image channel should be removed.
  • (str) (image_channel) – Color that should be removed (valid colors: ‘red’, ‘green’, ‘blue’).
Raises:
  • NameError: If invalid colour is selected (not red, green, blue).
Returns:
  • (obj): A copy of the image passed but with a color channel removed.
static histEqualisation(image)[source]

This function applies histogram equalisation to the image passed.

Parameters:(obj) (image) – OpenCV image to which histogram equalisation should be applied to.
Returns:
  • (obj): The Histogram equalised image.
topHat(image, rect_kernel_size=(13, 7))[source]

This function applies tophat color changes to the image passed.

Parameters:
  • (obj) (image) – Image to which top hat color changes should be applied to.
  • (list) (rect_kernel_size) – Represents the kernel dimension by which topHat morphology changes should be applied to.
Raises:
  • TypeError: If the kernel size type is not a tuple.
  • ValueError: If the kernel size tuple contains more than 2 items.
Returns:
  • (obj): A modified copy of the image with topHat morphology applied to it.

hutts_verification.image_preprocessing.face_manager module

Wraps all the functionality necessary for extracting a face from an image.

class FaceDetector(shape_predictor_path)[source]

Bases: object

The FaceDetector class is responsible for:

  1. Detecting the face.
  2. Extracting a face from an image.
  3. Applying blurring on a detected face in an image.
blur_face(image)[source]

This function find the faces and apply a blurring effect on the detected region. After the region has been blurred, the blurred region is reapplied to the original image. Blurring the face is implemented as a method in the attempt to reduce noise when extracting text from the image later in the image pipeline.

Parameters:(obj) (image) – OpenCV image containing the face we need to detect and blur.
Raises:
  • ValueError: If no face can be detected.
Returns:
  • (obj): A copy of the image with blurring applied to the face in the image.
detect(image)[source]

This function detects the face in the image passed. By making use of the dlib HOG feature image_preprocessing and linear classifier for frontal face detection we are able to detect the face with less false-positive results and without a major time penalty. More Information dlib frontal_face detection: http://dlib.net/imaging.html#get_frontal_face_detector

A check will be done to see if a face is present in the image. If a face is not detected in the image the execution should log that the face was not found and continue with execution. This is due to the fact that face detection might not be critical to a function (like with text extraction) and rather be used to increase accuracy.

Parameters:(obj) (image) – OpenCV image containing the face we need to detect.
Raises:
  • ValueError: If no face can be detected.
Returns:
  • list(int): This list contains the box coordinates for the region in which the face resides.
extract_face(image)[source]

This function finds a face in the image passed and is optimised to align the face before being returned.

Parameters:(obj) (image) – Image containing the face we need to detect and extract.
Raises:
  • ValueError: If no face can be detected.
Returns:
  • (obj): An image of the aligned face.

hutts_verification.image_preprocessing.pipeline module

This is an object that handles the entire process of extracting data from an image from a high-level perspective.

class Pipeline(blur_manager=None, color_manager=None, face_detector=None, threshold_manager=None)[source]

Bases: object

The Pipeline will perform all necessary processing on the image and is built by the PipelineBuilder.

Parameters:
  • (BlurManager) (blur_manager) – The BlurManager that is used in this pipeline.
  • (ColorManager) (color_manager) – The ColorManager that is used in this pipeline.
  • (FaceDetector) (face_detector) – The FaceDetector that is used in this pipeline.
  • (ThresholdManager) (threshold_manager) – The ThresholdManager that is used in this pipeline.
process_face_extraction(image)[source]

This function applies all the processing needed to extract a face from a image.

Parameters:(obj) (image) – Image to which processing should be applied to.
Returns:
  • (obj): The processed image.
process_text_extraction(useIO, image, remove_face=False)[source]

This function applies all the processing needed to extract text from a image.

Parameters:
  • (boolean) (remove_face) – Whether or not to write images to disk.
  • (obj) (image) – Image that should be processed.
  • (boolean) – If the remove face flag is set to true, extra processes will be activated during the pre-processing phase to remove the face from the image.
Returns:
  • (obj): The processed image.

hutts_verification.image_preprocessing.pipeline_builder module

The class that is responsible for creating a Pipeline. This class is the Builder of the Builder design pattern.

class PipelineBuilder[source]

Bases: object

The PipelineBuilder will assemble all the parts of the Pipeline.

get_result()[source]

This function returns the fully-assembled pipeline.

Returns:
(obj): The Pipeline.
set_blur_manager(value)[source]

This function adds the specified blur manager to the pipeline.

Parameters:(BlurManager) (value) – BlurManager object to be added.
set_color_manager(value)[source]

This function adds the specified color manager to the pipeline.

Parameters:(ColorManager) (value) – ColorManager object to be added.
set_face_detector(value)[source]

This function adds the specified face detector to the pipeline.

Parameters:(FaceDetector) (value) – FaceDetector object to be added.
set_threshold_manager(value)[source]

This function adds the specified threshold manager to the pipeline.

Parameters:(ThresholdManager) (value) – ThresholdManager object to be added.

hutts_verification.image_preprocessing.template_matching module

Wraps the functionality required to dynamically deduce the type of identification documentation that has been provided in an image.

class TemplateMatching[source]

Bases: object

The TemplateMatching class receives template images to identify the type of identification that is used in the image. Thus you provide it with templates and it will identify whether you used an ID card, ID book etc.

identify(source)[source]

This function identifies the src image by searching for the templates provided.

:param source (obj) : The image that needs to be identified.

Returns:
  • (str) : Either type of the image or None if the type could not be identified.

hutts_verification.image_preprocessing.thresholding_manager module

Wraps all the functions related to applying thresholding techniques to an image.

class ThresholdingManager(thresholding_type)[source]

Bases: object

The Thresholding manager is responsible for applying the different types of thresholding techniques.

static adaptiveThresholding(image)[source]

This function applies a simple adaptive thresholding to the image passed.

Parameters:(obj) (image) – Image to which thresholding should be applied.
Raises:
  • TypeError: If a parameter is passed that is not of type Numpy array.
Returns:
  • (obj): The image, with adaptive thresholding applied to it.
apply(image)[source]

This performs the thresholding based on the predefined technique.

Parameters:image – The image to which the thresholding must be applied.
Raises:
  • NameError: If a thresholding type other than ‘adaptive’ or ‘otsu’ is provided.
Returns:
  • (obj): The image, with the appropriate thresholding applied to it.
static otsuThresholding(image)[source]

This function applies a simple Binary Inverse Otsu thresholding to the image passed.

Parameters:(obj) (image) – Image to which thresholding should be applied.
Raises:
  • TypeError: If a parameter is passed that is not of type Numpy array.
Returns:
  • (obj): The image, with otsu thresholding applied to it.

Module contents