diff --git a/bob/ip/facelandmarks/__init__.py b/bob/ip/facelandmarks/__init__.py index d5d61f05021867a5aac356dc8a567c2a4a8d4347..0aa15339d9ca4f4b213ca102fc46c215499de646 100644 --- a/bob/ip/facelandmarks/__init__.py +++ b/bob/ip/facelandmarks/__init__.py @@ -1,6 +1,29 @@ #!/usr/bin/env python # vim: set fileencoding=utf-8 : +from .utils import * + + +# gets sphinx autodoc done right - don't remove it +def __appropriate__(*args): + """Says object was actually declared here, an not on the import module. + + Parameters: *args: An iterable of objects to modify + + Resolves `Sphinx referencing issues <https://github.com/sphinx- + doc/sphinx/issues/3048>` """ + + for obj in args: + obj.__module__ = __name__ + + +__appropriate__( + Result, + detect_landmarks_on_boundingbox, + detect_landmarks, + draw_landmarks, + save_landmarks, +) def get_config(): @@ -12,7 +35,5 @@ def get_config(): return bob.extension.get_config(__name__) - # gets sphinx autodoc done right - don't remove it __all__ = [_ for _ in dir() if not _.startswith('_')] - diff --git a/doc/guide.rst b/doc/guide.rst index 7a69e87ef76fd094ff391d6e3dc727eef3dbd1fe..f1aac12c4a6b58e7b5d38d6f16d5b320158e67b5 100644 --- a/doc/guide.rst +++ b/doc/guide.rst @@ -11,7 +11,6 @@ import bob.ip.color import bob.ip.facedetect import bob.ip.facelandmarks - import bob.ip.facelandmarks.utils import pkg_resources #lena_file = '/idiap/user/sbhatta/work/git/bob.ip.facelandmarks/data/lena.jpg' @@ -27,8 +26,8 @@ This Bob package allows you to use the [Menpofit_] package to detect facial landmarks. Given a gray-level image depicting a human face, this package can be used to extract a specific set of 68 landmarks, -as defined in Menpofit. Please refer to the original Menpofit [documentation_] for implementation details. -Here, we show some examples of how to use the ``bob.ip.facelandmarks`` package. +as defined in Menpofit. Please refer to the original Menpofit [documentation_] for implementation details. +Here, we show some examples of how to use the ``bob.ip.facelandmarks`` package. Landmark Detection on a Single Face @@ -42,7 +41,7 @@ The following code-example shows how to extract facial keypoints for a single fa >>> face_image = bob.io.base.load('lena.jpg') # doctest: +SKIP >>> gray_image = bob.ip.color.rgb_to_gray(face_image) - >>> key_points = bob.ip.facelandmarks.utils.detect_landmarks(gray_image, 1) + >>> key_points = bob.ip.facelandmarks.detect_landmarks(gray_image, 1) >>> print(key_points[0].landmarks.shape) (68, 2) @@ -69,23 +68,23 @@ The ``detect_landmarks()`` function has the following signature: `detect_landmar * ``gray_image``: a numpy-array containing the gray-level input image, and, * ``top``: positive integer (default=0), specifying the number of faces to be detected in this image. - * ``min_quality``: positive floating-point number (default=0), specifying the minimum acceptable quality for the result of face-detection. + * ``min_quality``: positive floating-point number (default=0), specifying the minimum acceptable quality for the result of face-detection. The first parameter is obligatory, and should be a valid 2D numpy-array representing a gray-level image. The remaining two parameters are optional. In the example above, ``top`` is specified as 1, hence, landmarks for only one face are extracted. -The function ``detect_landmarks()`` first detects faces in the input image, using ``bob.ip.facedetect``, and then uses the result of the face-detection-step for detecting facial-landmarks. +The function ``detect_landmarks()`` first detects faces in the input image, using ``bob.ip.facedetect``, and then uses the result of the face-detection-step for detecting facial-landmarks. If the ``min_quality`` parameter is specified, then bounding-boxes having a quality-value lower than the specified value are ignored. -The return value of ``detect_landmarks()`` is a list. +The return value of ``detect_landmarks()`` is a list. When only one face is expected in the input, this list will contain only one element. Each element in the list is an object with three members, named as follows: * ``bounding_box``: an object with two elements (topright, and bottomleft), each of which is a tuple (row,col) giving the coordinates of the top-left and bottom-right corners of the detected face-bounding-box. - * ``quality``: a floating-point number between 0 and 100.0, giving a quality-estimate for the result of the face-detection step. + * ``quality``: a floating-point number between 0 and 100.0, giving a quality-estimate for the result of the face-detection step. * ``landmarks``: a numpy-array of shape (68, 2). The first two members, ``bounding_box`` and ``quality``, come from ``bob.ip.facedetect``. @@ -108,10 +107,10 @@ As described in the Menpofit documentation, The facial-landmarks are listed in a If the bounding-box of the desired face is already available (via a preceding call to the function ``face.ip.facedetect.detect_single_face()``), the function ``detect_landmarks_on_boundingbox(gray_image, bounding_box)`` may be used to determine the facial-landmarks within this bounding-box. -Note that the return-value of ``detect_landmarks_on_boundingbox()`` is a 2D numpy-array representing the coordinates of the 68 landmarks (and not an object as in the case of ``detect_landmarks()``). +Note that the return-value of ``detect_landmarks_on_boundingbox()`` is a 2D numpy-array representing the coordinates of the 68 landmarks (and not an object as in the case of ``detect_landmarks()``). .. doctest:: - + >>> gray_image = bob.ip.color.rgb_to_gray(face_image) >>> my_bounding_box, _ = bob.ip.facedetect.detect_single_face(gray_image) >>> my_key_points = bob.ip.facelandmarks.utils.detect_landmarks_on_boundingbox(gray_image, my_bounding_box) @@ -130,9 +129,9 @@ In the following example, the input image contains several faces, out of which, >>> multi_image = bob.io.base.load('multiple-faces.jpg') # doctest: +SKIP >>> gray_image = bob.ip.color.rgb_to_gray(multi_image) - >>> key_points = bob.ip.facelandmarks.utils.detect_landmarks(gray_image, top=5) + >>> key_points = bob.ip.facelandmarks.utils.detect_landmarks(gray_image, top=5) >>> for i in range(5): - ... print(key_points[i].bounding_box.topleft) + ... print(key_points[i].bounding_box.topleft) (136, 2243) (1480, 2226) (1574, 2959) @@ -140,6 +139,6 @@ In the following example, the input image contains several faces, out of which, (107, 3016) -.. _Menpofit: http://www.menpo.org/menpofit/ +.. _Menpofit: http://www.menpo.org/menpofit/ .. _documentation: https://menpofit.readthedocs.io/en/stable/