diff --git a/doc/guide.rst b/doc/guide.rst index 950d43ba8d68c7ae7ea64596f247942d68a0e5a5..ac88b86b1513990717d0f5a009ae1051ae2d39ba 100644 --- a/doc/guide.rst +++ b/doc/guide.rst @@ -9,9 +9,9 @@ from pkg_resources import resource_filename return resource_filename('bob.ip.flandmark', join('data', f)) -============= - Users Guide -============= +============================================== + Face Landmark Detection Using Python and Bob +============================================== :py:class:`bob.ip.flandmark` detects 8 coordinates of important keypoints in **frontal** human faces. To properly work, the keypoint localizer requires the input of an image (of type ``uint8``, gray-scaled) and of a bounding box describing a rectangle where the face is supposed to be located in the image (see :py:meth:`bob.ip.flandmark.Flandmark.locate`). @@ -64,8 +64,11 @@ The code below shall detect most frontal faces in a provided image: >>> import bob.ip.facedetect >>> lena = bob.io.base.load(get_file('lena.jpg')) >>> bounding_box, quality = bob.ip.facedetect.detect_single_face(lena) + >>> # scale the bounding box to cover more of the face + >>> bounding_box = bounding_box.scale(1.2, True) >>> y, x = bounding_box.topleft >>> height, width = bounding_box.size + >>> width = height # make it square >>> print((y, x, height, width)) (...) diff --git a/doc/plot/show_lena.py b/doc/plot/show_lena.py index eae767065278e2c5bc8524f2cb5cfb36558d6ff4..a34ca56644ee59d5cc2f24166781f283f88ef3ef 100644 --- a/doc/plot/show_lena.py +++ b/doc/plot/show_lena.py @@ -1,24 +1,31 @@ -from matplotlib import pyplot from bob.ip.flandmark import Flandmark from bob.ip.draw import box, cross from bob.ip.color import rgb_to_gray +from bob.ip.facedetect import detect_single_face +import bob.io.image + def get_data(f): from os.path import join from pkg_resources import resource_filename from bob.io.base import load - import bob.io.image return load(resource_filename('bob.ip.flandmark', join('data', f))) + lena = get_data('lena.jpg') lena_gray = rgb_to_gray(lena) -x, y, width, height = [214, 202, 183, 183] #or from bob.ip.facedetect +bounding_box, quality = detect_single_face(lena) +bounding_box = bounding_box.scale(1.2, True) +y, x = bounding_box.topleft +height, width = bounding_box.size +width = height +# x, y, width, height = [214, 202, 183, 183] # Manual annotations localizer = Flandmark() keypoints = localizer.locate(lena_gray, y, x, height, width) # draw the keypoints and bounding box -box(lena, (y, x), (height, width), (255, 0, 0)) # red bounding box +box(lena, (y, x), (height, width), (255, 0, 0)) # red bounding box for k in keypoints: - cross(lena, k.astype(int), 5, (255, 255, 0)) # yellow key points + cross(lena, k.astype(int), 5, (255, 255, 0)) # yellow key points -pyplot.imshow(lena.transpose(1, 2, 0)) +bob.io.image.imshow(lena)