plot_landmarks.py 1.4 KB
Newer Older
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
1 2 3 4 5 6 7 8 9 10 11 12 13
import bob.io.base
import bob.io.image
import bob.io.base.test_utils
import bob.ip.dlib
import pkg_resources
import os
from matplotlib import pyplot
import bob.ip.draw

#print "###################################"
#print os.path.join(pkg_resources.resource_filename(__name__, 'data'), 'multiple-faces.jpg')

# detect multiple dlib
14 15 16
image = bob.io.base.load(bob.io.base.test_utils.datafile('testimage.jpg', 'bob.ip.facedetect'))
bob_image = bob.io.base.load(bob.io.base.test_utils.datafile('testimage.jpg', 'bob.ip.facedetect'))
bounding_box, _ = bob.ip.dlib.FaceDetector().detect_single_face(image)
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
17 18 19

# landmarks
detector = bob.ip.dlib.DlibLandmarkExtraction()
20 21 22 23
points = detector(image)

bob_detector = bob.ip.dlib.DlibLandmarkExtraction(bob_landmark_format=True)
bob_points = bob_detector(bob_image)
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
24

25 26
for p in points:
    bob.ip.draw.plus(image, p, radius=10, color=(255, 0, 0))
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
27

28 29
for p in bob_points:
    bob.ip.draw.plus(bob_image, bob_points[p], radius=10, color=(255, 0, 0))
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
30 31

# face detections
32
bob.ip.draw.box(image, bounding_box.topleft, bounding_box.size, color=(255, 0, 0))
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
33 34 35


ax = pyplot.subplot(1, 2, 1)
36 37
ax.set_title("Dlib landmarks")
pyplot.imshow(bob.ip.dlib.utils.bob_to_dlib_image_convertion(image, change_color=False))
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
38 39 40
pyplot.axis('off')

ax = pyplot.subplot(1, 2, 2)
41 42
ax.set_title("Dlib landmarks for Bob")
pyplot.imshow(bob.ip.dlib.utils.bob_to_dlib_image_convertion(bob_image, change_color=False))
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
43 44
pyplot.axis('off')