Python API

Detailed Information

bob.ip.facelandmarks.get_config()[source]

Returns a string containing the configuration information.

class bob.ip.facelandmarks.Result

Bases: bob.ip.facelandmarks.Result

A collections.namedtuple with landmark information

bounding_box

A bounding box extracted with bob.ip.facedetect.

Type

bob.ip.facedetect.BoundingBox

quality

the quality of the extracted bounding-box, as returned by bob.ip.facedetect’s Boosted classifier

Type

float

landmarks

A set of 68 points output by the menpofit landmark detector. The format of this output is a 2D numpy.ndarray in which the first dimension encodes each point and the second, the point coordinates in the format (y, x). The 68 points are ordered in this way, from the menpo documentation:

jaw_indices = [0, 17]
lbrow_indices = [17, 22]
rbrow_indices = [22, 27]
upper_nose_indices = [27, 31]
lower_nose_indices = [31, 36]
leye_indices = [36, 42]
reye_indices = [42, 48]
outer_mouth_indices = [48, 60]
inner_mouth_indices = [60, 68]
Type

numpy.ndarray

bob.ip.facelandmarks.detect_landmarks(data, top=0, min_quality=0.0)

Detects landmarks on an image, returns point-clouds from menpo

This helper will detect faces and landmarks, possibly many, on the input image.

Parameters
  • data (numpy.ndarray) – An uint8 array with either 2 or 3 dimensions, corresponding to a either a gray-scale or color image loaded with Bob.

  • top (int) – An integer which indicates if we should only consider the first N detections or all of them. A value of zero means the selector ignores this field.

  • min_quality (float) – trims the face detector output list by considering a minimum quality for the detection. A value of zero (0.0) means “any quality will do”. Good detections have a typical value which is greater than 30. Use this parameter with care. If this and top are defined and non-zero, then top takes precedence.

Returns

A list of named tuples of type Result, each

containing the result of face detection and landmarks extracted from the input image.

Return type

list

bob.ip.facelandmarks.detect_landmarks_on_boundingbox(data, bounding_box)

Detects landmarks on a color or gray-scale image, returns them

This function will detect landmarks on the input color or gray-scale image.

Parameters
Returns

Containing the 68 detected landmarks around the

bounding box provided as input. Notice this will detect landmarks if there is a face inside the bounding box or not. It is your task to make sure the bounding-box contains a valid face.

Return type

numpy.ndarray

bob.ip.facelandmarks.draw_landmarks(data, results)

Draws bounding boxes and landmarks on the input image

Parameters
  • data (numpy.ndarray) – An uint8 array with either 2 or 3 dimensions, corresponding to a either a gray-scale or color image loaded with Bob.

  • results (list) – A list of named tuples of type Result, each containing the result of face detection and landmarks extracted from the input image.

bob.ip.facelandmarks.save_landmarks(results, fname)

Saves landmarks to an HDF5 file

This function will create an HDF5 file with the following structure:

menpo_landmarks68: Dataset {68, 2} (float64)
face_detector: {
  quality: float64,
  topleft_y: int32,
  topleft_x: int32,
  height: int32,
  width: int32,
}

The points inside the variable menpo_landmarks68 are kept in the format (y, x).

If there is more than a single detection on the input results, then the structure of the format is:

menpo_landmarks68: Dataset {N, 68, 2} (float64)
face_detector (Group): {
  quality: Dataset {N} (float64),
  topleft_y: Dataset {N} (int32),
  topleft_x: Dataset {N} (int32),
  height: Dataset {N} (int32),
  width: Dataset {N} (int32),
}

Where N corresponds to the number of entries in results.

In case the file exists already, then we’ll try to create the entries defined above in case they don’t exist yet on the said file.

Parameters
  • results (list) – A list of named tuples of type Result, each containing the result of face detection and landmarks extracted from the input image.

  • fname (str) – A path with the output filename