bob.ip.facedetect.BoundingBox | A bounding box class storing top, left, height and width of an |
bob.ip.facedetect.FeatureExtractor | This class extracts LBP features of several types from a given image |
bob.ip.facedetect.Cascade([cascade_file, ...]) | This class defines a cascade of strong classifiers bob.learn.boosting.BoostedMachine. |
bob.ip.facedetect.Sampler([patch_size, ...]) | This class generates (samples) bounding boxes for different scales and locations in the image. |
bob.ip.facedetect.TrainingSet([...]) | A set of images including bounding boxes that are used as a training set |
bob.ip.facedetect.detect_single_face((image, ...) | Detects a single face in the given image, i.e., the one with the highest prediction value. |
bob.ip.facedetect.detect_all_faces((image, ...) | Detects a single face in the given image, i.e., the one with the highest prediction value. |
bob.ip.facedetect.default_cascade() | Returns the Cascade that is loaded from the pre-trained cascade file provided by this package. |
bob.ip.facedetect.best_detection(...) | Computes the best detection for the given detections and according predictions. |
bob.ip.facedetect.overlapping_detections(...) | Returns the detections and predictions that overlap with the best |
bob.ip.facedetect.prune_detections(...) | Prunes the given detected bounding boxes according to their predictions |
bob.ip.facedetect.expected_eye_positions(...) | Computes the expected eye positions based on the relative coordinates of the bounding box. |
bob.ip.facedetect.bounding_box_from_annotation([...]) | Creates a bounding box from the given parameters. |
bob.ip.facedetect.read_annotation_file(...) | Reads annotations from the given annotation file. |
Bases: object
A bounding box class storing top, left, height and width of an rectangle
Constructor Documentation:
- bob.ip.facedetect.BoundingBox (topleft, size)
- bob.ip.facedetect.BoundingBox (bounding_box)
Constructs a new Bounding box from the given top-left position and the size of the rectangle
Parameters:
topleft : (float, float)
The top-left position of the bounding boxsize : (float, float)
The size of the bounding boxbounding_box : BoundingBox
The BoundingBox object to use for copy-construction
Class Members:
float <– The area (height x width) of the bounding box, read access only
int <– The bottom position of the bounding box (which is just outside the bounding box) as int, read access only
float <– The bottom position of the bounding box (which is just outside the bounding box) as float, read access only
(int, int) <– The bottom-right position of the bounding box (which is just outside the bounding box) as integral values, read access only
(float, float) <– The bottom-right position of the bounding box (which is just outside the bounding box) as float values, read access only
(float, float) <– The center of the bounding box (as float values), read access only
Checks if the bounding box is inside the given image size
Parameters:
size : (int, int)
The size of the image to test
Returns:
valid : bool
True if the bounding box is inside the image boundaries, False otherwise
int <– The left position of the bounding box as int, read access only
float <– The left position of the bounding box as float, read access only
This function returns a horizontally mirrored version of this BoundingBox
Parameters:
width : int
The width of the image at which this bounding box should be mirrored
Returns:
bounding_box : BoundingBox
The mirrored version of this bounding box
This function returns the overlapping bounding box between this and the given bounding box
Parameters:
other : BoundingBox
The other bounding box to compute the overlap with
Returns:
bounding_box : BoundingBox
The overlap between this and the other bounding box
int <– The right position of the bounding box (which is just outside the bounding box) as int, read access only
float <– The right position of the bounding box (which is just outside the bounding box) as float, read access only
This function returns a scaled version of this BoundingBox
When the centered parameter is set to True, the transformation center will be in the center of this bounding box, otherwise it will be at (0,0)
Parameters:
scale : float
The scale with which this bounding box should be shifted
centered : bool
[Default: False] : Should the scaling done with repect to the center of the bounding box?
Returns:
bounding_box : BoundingBox
The scaled version of this bounding box
This function returns a shifted version of this BoundingBox
Parameters:
offset : (float, float)
The offset with which this bounding box should be shifted
Returns:
bounding_box : BoundingBox
The shifted version of this bounding box
This function computes the Jaccard similarity index between this and the given BoundingBox
Parameters:
other : BoundingBox
The other bounding box to compute the overlap with
Returns:
sim : float
The Jaccard similarity index between this and the given BoundingBox
(int, int) <– The size of the bounding box as integral values, read access only
(float, float) <– The size of the bounding box as float values, read access only
int <– The top position of the bounding box as int, read access only
float <– The top position of the bounding box as float, read access only
(int, int) <– The top-left position of the bounding box as integral values, read access only
(float, float) <– The top-left position of the bounding box as float values, read access only
This class defines a cascade of strong classifiers bob.learn.boosting.BoostedMachine.
For each strong classifier, a threshold exists. When the weighted sum of predictions of classifiers gets below this threshold, the classification is stopped.
Constructor Documentation:
The constructor has two different ways to be called. The first and most obvious way is to load the cascade from the given cascade_file.
The second way instantiates an empty cascade, with the given feature_extractor. Please use the add() function to add new strong classifiers with according thresholds.
Keyword parameters:
- cascade_file : bob.io.base.HDF5File
- An HDF5 file open for reading
- feature_extractor : FeatureExtractor
- A feature extractor that will be used to extract features for the strong classifiers.
Adds a new strong classifier with the given threshold to the cascade.
Keyword parameters:
Creates this cascade from the given boosted machine, by simply splitting off strong classifiers that have classifiers_per_round weak classifiers.
Keyword parameters:
Creates a single strong classifier from this cascade by concatenating all strong classifiers.
Returns:
Loads this cascade from the given HDF5 file.
Keyword parameters:
Prepares the cascade for extracting features of the given image in the given scale.
Keyword parameters:
Saves this cascade into the given HDF5 file.
Keyword parameters:
Bases: object
This class extracts LBP features of several types from a given image patch of a certain size
LBP features are extracted using different variants of bob.ip.base.LBP feature extractors. All LBP features of one patch are stored in a single long feature vector of type numpy.uint16.
Constructor Documentation:
- bob.ip.facedetect.FeatureExtractor (patch_size)
- bob.ip.facedetect.FeatureExtractor (patch_size, extractors)
- bob.ip.facedetect.FeatureExtractor (patch_size, template, [overlap], [square], [min_size], [max_size])
- bob.ip.facedetect.FeatureExtractor (other)
- bob.ip.facedetect.FeatureExtractor (hdf5)
Generates a new feature extractor for the given patch_size using one or several feature extractors
The constructor can be called in different ways:
- The first constructor initializes a feature extractor with no LBP extractor. Please use the append() function to add LBP extractors.
- In the second constructor, a given list of LBP extractors is specified.
- The third constructor initializes a tight set of LBP extractors for different bob.ip.base.LBP.radii, by adding all possible combinations of x- and y- radii, until the patch_size is too small, or min_size (start) or max_size (end) is reached.
- The fourth constructor copies all LBP extractors from the given FeatureExtractor
- The last constructor read the configuration from the given bob.io.base.HDF5File.
Parameters:
patch_size : (int, int)
The size of the patch to extract from the imagesextractors : [bob.ip.base.LBP]
The LBP classes to use as extractorstemplate : bob.ip.base.LBP
The LBP classes to use as template for all extractorsoverlap : bool
[default: False] Should overlapping LBPs be created?square : bool
[default: False] Should only square LBPs be created?min_size : int
[default: 1] The minimum radius of LBPmax_size : int
[default: MAX_INT] The maximum radius of LBP (limited by patch size)other : FeatureExtractor
The feature extractor to use for copy-constructionhdf5 : bob.io.base.HDF5File
The HDF5 file to read the extractors from
Class Members:
Appends the given feature extractor or LBP class to this one
With this function you can either append a complete feature extractor, or a partial axtractor (i.e., a single LBP class) including the offset positions for them
Parameters:
other : FeatureExtractor
All LBP classes and offset positions of the given extractor will be appended
lbp : bob.ip.base.LBP
The LBP extractor that will be added
offsets : [(int,int)]
The offset positions at which the given LBP will be extracted
Extracts all features into the given dataset of (training) features at the given index
This function exists to extract training features for several training patches. To avoid data copying, the full training dataset, and the current training feature index need to be provided.
Parameters:
bounding_box : BoundingBox
The bounding box for which the features should be extracted
dataset : array_like <2D, uint16>
The (training) dataset, into which the features should be extracted; must be of shape (#training_patches, number_of_features)
dataset_index : int
The index of the current training patch
Extracts the features only at the required locations, which defaults to model_indices
Parameters:
bounding_box : BoundingBox
The bounding box for which the features should be extracted
feature_vector : array_like <1D, uint16>
The feature vector, into which the features should be extracted; must be of size number_of_features
indices : array_like<1D,int32>
The indices, for which the features should be extracted; if not given, model_indices is used (must be set beforehands)
Get the LBP feature extractor associated with the given feature index
Parameters:
index : int
The feature index for which the extractor should be retrieved
Returns:
lbp : bob.ip.base.LBP
The feature extractor for the given feature index
[bob.ip.base.LBP] <– The LBP extractors, read access only
array_like <2D, uint8> <– The (prepared) image the next features will be extracted from, read access only
Loads the extractors from the given HDF5 file
Parameters:
hdf5 : bob.ip.base.HDF5File
The file to read from
Computes the mean (and the variance) of the pixel gray values in the given bounding box
Parameters:
bounding_box : BoundingBox
The bounding box for which the mean (and variance) shoulf be calculated
compute_variance : bool
[Default: False] If enabled, the variance is computed as well; requires the compute_integral_square_image enabled in the prepare() function
Returns:
mv : float or (float, float)
The mean (or the mean and the variance) of the pixel gray values for the given bounding box
array_like <1D, int32> <– The indices at which the features are extracted, read and write access
int <– The length of the feature vector that will be extracted by this class, read access only
int <– The maximum label for the features in this class, read access only
Get the offset position associated with the given feature index
Parameters:
index : int
The feature index for which the extractor should be retrieved
Returns:
offset : (int,int)
The offset position for the given feature index
(int, int) <– The expected size of the patch that this extractor can handle, read access only
Take the given image to perform the next extraction steps for the given scale
If compute_integral_square_image is enabled, the (internally stored) integral square image is computed as well. This image is required to compute the variance of the pixels in a given patch, see mean_variance()
Parameters:
image : array_like <2D, uint8 or float>
The image that should be used in the next extraction step
scale : float
The scale of the image to extract
compute_integral_square_image : bool
[Default: False] : Enable the computation of the integral square image
Saves the extractors to the given HDF5 file
Parameters:
hdf5 : bob.ip.base.HDF5File
The file to write to
This class generates (samples) bounding boxes for different scales and locations in the image.
It computes different scales of the image and provides a tight set of BoundingBox of a given patch size for the given image.
Constructor Documentation:
Generates a patch-sampler, which will scan images and sample bounding boxes.
Parameters:
- patch_size : (int, int)
- the size of the patch (i.e., the bounding box) to sample
- scale_factor : float
- image pyramids are computed using the given scale factor between two scales
- lowest_scale : float or None
- patches which will be lower than the given scale times the image resolution will not be taken into account; if 0. all possible patches will be considered
- distance : int
- the distance in both horizontal and vertical direction to generate samples
Scales the given image and extracts bounding boxes, computes the features for the given feature extractor and returns an ITERATOR returning a the bounding_box.
Iterates over the given image and computes the cascade of classifiers.
Returns an iterator over all bounding boxes that are sampled for the given image.
Returns an iterator that iterates over all sampled bounding boxes in the given (scaled) image shape.
Computes the all possible scales for the given image and returns a tuple of the scale and the scaled image shape as an iterator.
A set of images including bounding boxes that are used as a training set
Adds image path and bounding boxes from the given annotations.
Extracts all features from all images in all scales and writes them to file.
Returns the feature extractor used to extract the positive and negative features.
Returns the image name and the bounding boxes stored in the training set as an iterator.
Loads the list of annotations from the given file and appends it to the current list.
Returns positive and negative samples from the set of positives and negatives.
Saves the current list of annotations to the given file.
Computes the best detection for the given detections and according predictions.
This is acheived by computing a weighted sum of detections that overlap with the best detection (the one with the highest prediction), where the weights are based on the predictions. Only detections with according prediction values > 0 are considered.
Keyword Parameters:
Returns:
Creates a bounding box from the given parameters. If ‘sources’ are specified, the according keywords (see available_sources) must be given as well. Otherwise, the source is estimated from the given keyword parameters if possible.
If ‘topleft’ and ‘bottomright’ are given (i.e., the ‘direct’ source), they are taken as is. Note that the ‘bottomright’ is NOT included in the bounding box.
For source ‘ellipse’, the bounding box is computed to capture the whole ellipse, even if it is rotated.
For other sources (i.e., ‘eyes’), the center of the two given positions is computed, and the ‘padding’ is applied. If ‘padding ‘ is None (the default) then the default_paddings of this source are used instead.
Returns the Cascade that is loaded from the pre-trained cascade file provided by this package.
Detects a single face in the given image, i.e., the one with the highest prediction value.
Keyword Parameters:
Return value:
Detects a single face in the given image, i.e., the one with the highest prediction value.
Keyword Parameters:
Return value:
Computes the expected eye positions based on the relative coordinates of the bounding box.
Returns the detections and predictions that overlap with the best detection
For threshold >= 1., all detections will be returned (i.e., no pruning is performed), but the list will be sorted with descendingly predictions.
Parameters:
detections : [BoundingBox]
A list of detected bouding boxes
predictions : array_like <1D, float>
The prediction (quality, weight, ...) values for the detections
threshold : float
The overlap threshold (Jaccard similarity) which should be considered
Returns:
overlapped_detections : [BoundingBox]
The list of overlapping bounding boxes
overlapped_predictions : array_like <float, 1D>
The according predictions (qualities, weights, ...)
Prunes the given detected bounding boxes according to their predictions and returns the pruned bounding boxes and their predictions
For threshold >= 1., all detections will be returned (i.e., no pruning is performed), but the list will be sorted with descendingly predictions.
Parameters:
detections : [BoundingBox]
A list of detected bouding boxes
predictions : array_like <1D, float>
The prediction (quality, weight, ...) values for the detections
threshold : float
The overlap threshold (Jaccard similarity), for which detections should be pruned
number_of_detections : int
[default: MAX_INT] The number of detections that should be returned
Returns:
pruned_detections : [BoundingBox]
The list of pruned bounding boxes
pruned_predictions : array_like <float, 1D>
The according predictions (qualities, weights, ...)
Reads annotations from the given annotation file.
The way, how annotations are read depends on the given annotation_type. Depending on the type, one or several annotations might be present in the annotation file. Currently, these variants are implemented:
Finally, a list of annotations is returned in the format: [{name: (y,x)}].