Skip to content
Snippets Groups Projects
Commit 45c1e696 authored by Amir Mohammadi's avatar Amir Mohammadi
Browse files

[doc] improve example using bob.ip.facedetect

parent 1e2dfe3b
Branches
Tags
1 merge request!12Fix the documentation to use bob.ip.facedetect instead of opencv
Pipeline #
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
from pkg_resources import resource_filename from pkg_resources import resource_filename
return resource_filename('bob.ip.flandmark', join('data', f)) 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. :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`). 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: ...@@ -64,8 +64,11 @@ The code below shall detect most frontal faces in a provided image:
>>> import bob.ip.facedetect >>> import bob.ip.facedetect
>>> lena = bob.io.base.load(get_file('lena.jpg')) >>> lena = bob.io.base.load(get_file('lena.jpg'))
>>> bounding_box, quality = bob.ip.facedetect.detect_single_face(lena) >>> 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 >>> y, x = bounding_box.topleft
>>> height, width = bounding_box.size >>> height, width = bounding_box.size
>>> width = height # make it square
>>> print((y, x, height, width)) >>> print((y, x, height, width))
(...) (...)
......
from matplotlib import pyplot
from bob.ip.flandmark import Flandmark from bob.ip.flandmark import Flandmark
from bob.ip.draw import box, cross from bob.ip.draw import box, cross
from bob.ip.color import rgb_to_gray from bob.ip.color import rgb_to_gray
from bob.ip.facedetect import detect_single_face
import bob.io.image
def get_data(f): def get_data(f):
from os.path import join from os.path import join
from pkg_resources import resource_filename from pkg_resources import resource_filename
from bob.io.base import load from bob.io.base import load
import bob.io.image
return load(resource_filename('bob.ip.flandmark', join('data', f))) return load(resource_filename('bob.ip.flandmark', join('data', f)))
lena = get_data('lena.jpg') lena = get_data('lena.jpg')
lena_gray = rgb_to_gray(lena) 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() localizer = Flandmark()
keypoints = localizer.locate(lena_gray, y, x, height, width) keypoints = localizer.locate(lena_gray, y, x, height, width)
# draw the keypoints and bounding box # 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: 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment