From 45c1e69668f7d46d24bd7d873372ca95f90a5d9f Mon Sep 17 00:00:00 2001
From: Amir Mohammadi <183.amir@gmail.com>
Date: Mon, 26 Dec 2016 13:23:58 +0100
Subject: [PATCH] [doc] improve example using bob.ip.facedetect

---
 doc/guide.rst         |  9 ++++++---
 doc/plot/show_lena.py | 19 +++++++++++++------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/doc/guide.rst b/doc/guide.rst
index 950d43b..ac88b86 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 eae7670..a34ca56 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)
-- 
GitLab