Commit d432c408 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch 'reyeleye' into 'master'

Fix left eye right eye landmarks

Closes #7

See merge request !14
parents 0c111108 61458972
Pipeline #29823 passed with stages
in 22 minutes and 53 seconds
......@@ -49,7 +49,6 @@ class DlibLandmarkExtraction(object):
self.predictor = dlib.shape_predictor(self.model)
self.bob_landmark_format = bob_landmark_format
def __call__(self, image, bb=None, xy_output=False):
# Detecting the face if the bounding box is not passed
......@@ -71,10 +70,10 @@ class DlibLandmarkExtraction(object):
points = list(map(lambda p: (p.y, p.x), points.parts()))
bob_landmarks = dict()
bob_landmarks['leye'] = ((points[37][0] + points[40][0])//2,
bob_landmarks['reye'] = ((points[37][0] + points[40][0])//2,
(points[37][1] + points[40][1])//2)
bob_landmarks['reye'] = ((points[43][0] + points[46][0])//2,
bob_landmarks['leye'] = ((points[43][0] + points[46][0])//2,
(points[43][1] + points[46][1])//2)
bob_landmarks['nose'] = (points[33][0], points[33][1])
......@@ -116,5 +115,5 @@ class DlibLandmarkExtraction(object):
"http://dlib.net/files/"
"shape_predictor_68_face_landmarks.dat.bz2",
]
bob.extension.download.download_and_unzip(urls, zip_file)
......@@ -13,7 +13,7 @@ def test_face_detector():
"""
Test FaceDetector class.
"""
image = np.zeros((3, 100, 100))
result = FaceDetector().detect_single_face(image)
assert result is None
......@@ -49,5 +49,6 @@ def test_landmark():
# Testing bob landmarks
detector = bob.ip.dlib.DlibLandmarkExtraction(bob_landmark_format=True)
points_dlib = detector(test_file)
assert np.allclose([p in ['leye', 'reye', 'nose', 'mouthleft', 'mouthright'] for p in points_dlib], True)
assert all([p in ['leye', 'reye', 'nose', 'mouthleft', 'mouthright'] for p in points_dlib])
# leye x must be higher than reye y to conform to Bob format
assert points_dlib['leye'][1] > points_dlib['reye'][1]
......@@ -66,7 +66,7 @@ The detection of landmarks can be done as the following:
>>> dlib_color_image = bob.io.base.load(bob.io.base.test_utils.datafile('testimage.jpg', 'bob.ip.facedetect'))
>>> points = bob.ip.dlib.DlibLandmarkExtraction(bob_landmark_format=True)(dlib_color_image)
>>> print (points['reye'])
(173, 222)
(178, 128)
.. plot:: plot/plot_landmarks.py
:include-source: False
......
......@@ -3,7 +3,6 @@ import bob.io.image
import bob.io.base.test_utils
import bob.ip.dlib
import numpy
import os
from matplotlib import pyplot
import bob.ip.draw
from bob.ip.facedetect import BoundingBox
......
......@@ -2,14 +2,10 @@ 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
from matplotlib.patches import Rectangle
import bob.ip.draw
#print "###################################"
#print os.path.join(pkg_resources.resource_filename(__name__, 'data'), 'multiple-faces.jpg')
# detect multiple dlib
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'))
......@@ -22,23 +18,20 @@ points = detector(image)
bob_detector = bob.ip.dlib.DlibLandmarkExtraction(bob_landmark_format=True)
bob_points = bob_detector(bob_image)
for p in points:
bob.ip.draw.plus(image, p, radius=10, color=(255, 0, 0))
for p in bob_points:
bob.ip.draw.plus(bob_image, bob_points[p], radius=10, color=(255, 0, 0))
# face detections
bob.ip.draw.box(image, bounding_box.topleft, bounding_box.size, color=(255, 0, 0))
ax = pyplot.subplot(1, 2, 1)
ax.set_title("Dlib landmarks")
pyplot.imshow(bob.io.image.to_matplotlib(image).astype("uint8"))
bob.io.image.imshow(image.astype("uint8"))
pyplot.axis('off')
x = [p[1] for p in points]
y = [p[0] for p in points]
pyplot.plot(x, y, '+', color='r')
ax.add_patch(Rectangle(bounding_box.topleft[::-1], bounding_box.size[1], bounding_box.size[0], edgecolor='r', facecolor='none'))
ax = pyplot.subplot(1, 2, 2)
ax.set_title("Dlib landmarks for Bob")
pyplot.imshow(bob.io.image.to_matplotlib(bob_image).astype("uint8"))
bob.io.image.imshow(bob_image.astype("uint8"))
pyplot.axis('off')
x = [p[1] for p in bob_points.values()]
y = [p[0] for p in bob_points.values()]
pyplot.plot(x, y, '+', color='r')
......@@ -2,14 +2,11 @@ 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
from matplotlib.patches import Rectangle
import bob.ip.draw
import bob.ip.facedetect
#print "###################################"
#print os.path.join(pkg_resources.resource_filename(__name__, 'data'), 'multiple-faces.jpg')
# detect multiple bob
bob_color_image = bob.io.base.load(bob.io.base.test_utils.datafile('multiple-faces.jpg', 'bob.ip.dlib'))
......@@ -20,19 +17,18 @@ dlib_color_image = bob.io.base.load(bob.io.base.test_utils.datafile('multiple-fa
dlib_bounding_box, _ = bob.ip.dlib.FaceDetector().detect_all_faces(dlib_color_image)
# create figure
for b in bob_bounding_box:
bob.ip.draw.box(bob_color_image, b.topleft, b.size, color=(255, 0, 0))
for b in dlib_bounding_box:
bob.ip.draw.box(dlib_color_image, b.topleft, b.size, color=(255, 0, 0))
ax = pyplot.subplot(1, 2, 1)
ax.set_title("Dlib")
ax.set_title("bob.ip.dlib")
pyplot.imshow(bob.io.image.to_matplotlib(dlib_color_image).astype("uint8"))
pyplot.axis('off')
for b in dlib_bounding_box:
ax.add_patch(Rectangle(b.topleft[::-1], b.size[1], b.size[0], edgecolor='r', facecolor='none'))
ax = pyplot.subplot(1, 2, 2)
ax.set_title("Bob")
ax.set_title("bob.ip.facedetect")
pyplot.imshow(bob.io.image.to_matplotlib(bob_color_image).astype("uint8"))
pyplot.axis('off')
for b in bob_bounding_box:
ax.add_patch(Rectangle(b.topleft[::-1], b.size[1], b.size[0], edgecolor='r', facecolor='none'))
......@@ -2,15 +2,11 @@ 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
from matplotlib.patches import Rectangle
import bob.ip.draw
import bob.ip.facedetect
#print "###################################"
#print os.path.join(pkg_resources.resource_filename(__name__, 'data'), 'multiple-faces.jpg')
# detect multiple bob
bob_color_image = bob.io.base.load(bob.io.base.test_utils.datafile('testimage.jpg', 'bob.ip.facedetect'))
bob_bounding_box, _ = bob.ip.facedetect.detect_single_face(bob_color_image)
......@@ -20,17 +16,18 @@ dlib_color_image = bob.io.base.load(bob.io.base.test_utils.datafile('testimage.j
dlib_bounding_box, _ = bob.ip.dlib.FaceDetector().detect_single_face(dlib_color_image)
# create figure
bob.ip.draw.box(bob_color_image, bob_bounding_box.topleft, bob_bounding_box.size, color=(255, 0, 0))
# bob.ip.draw.box(bob_color_image, bob_bounding_box.topleft, bob_bounding_box.size, color=(255, 0, 0))
bob.ip.draw.box(dlib_color_image, dlib_bounding_box.topleft, dlib_bounding_box.size, color=(255, 0, 0))
# bob.ip.draw.box(dlib_color_image, dlib_bounding_box.topleft, dlib_bounding_box.size, color=(255, 0, 0))
ax = pyplot.subplot(1, 2, 1)
ax.set_title("Dlib")
ax.set_title("bob.ip.dlib")
pyplot.imshow(bob.io.image.to_matplotlib(dlib_color_image).astype("uint8"))
pyplot.axis('off')
ax.add_patch(Rectangle(dlib_bounding_box.topleft[::-1], dlib_bounding_box.size[1], dlib_bounding_box.size[0], edgecolor='r', facecolor='none'))
ax = pyplot.subplot(1, 2, 2)
ax.set_title("Bob")
ax.set_title("bob.ip.facedetect")
pyplot.imshow(bob.io.image.to_matplotlib(bob_color_image).astype("uint8"))
pyplot.axis('off')
ax.add_patch(Rectangle(bob_bounding_box.topleft[::-1], bob_bounding_box.size[1], bob_bounding_box.size[0], edgecolor='r', facecolor='none'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment