Deleted the fuctions bob_to_dlib_image_convertion and...

Deleted the fuctions bob_to_dlib_image_convertion and dlib_to_bob_image_convertion and replaced them by the bob.io.color.to_matplotlib

[sphinx] Fixed plots

[sphinx] Forgot to fix one of the plots

[sphinx] Fixed doc test

[sphinx] Fixed doc test

Forgot to import bob.io.image
parent 4cc74988
Pipeline #19894 passed with stage
in 13 minutes and 24 seconds
......@@ -12,10 +12,11 @@ import os
os.environ['GLOG_minloglevel'] = '2'
import caffe
import bob.ip.base
import bob.io.image
from bob.ip.facedetect import BoundingBox
from .legacy import detect_face
from .utils import bob_to_dlib_image_convertion, rectangle2bounding_box2
from .utils import rectangle2bounding_box2
class FaceDetector(object):
......@@ -104,7 +105,7 @@ class FaceDetector(object):
if len(image.shape) != 3:
raise ValueError("Only color images is supported")
bb, landmarks = detect_face(bob_to_dlib_image_convertion(
bb, landmarks = detect_face(bob.io.image.to_matplotlib(
image), self.minsize, self.p_net, self.r_net, self.o_net, self.threshold, self.fastresize, self.factor)
# If there's no face, return none
......
......@@ -52,9 +52,8 @@ def test_face_detection():
del f
result = detector.detect_single_face(image)
assert result[0].topleft == (0, 77)
assert result[0].bottomright == (225, 246)
assert result[0].topleft == (0, 58)
assert result[0].bottomright == (228, 232)
def test_crop():
......
......@@ -2,53 +2,6 @@ import numpy
from bob.ip.facedetect import BoundingBox
def bob_to_dlib_image_convertion(bob_image, change_color=True):
"""
Bob stores color images as (C, W, H), where C is channels, W is the width and H is height; AND the order of the
colors are R,G,B.
On the other hand, Dlib do (W, H, C) AND the order of the colors are the same as OpenCV (B, G, R)
"""
if len(bob_image.shape) == 2:
return bob_image
dlib_image = numpy.zeros(shape=(bob_image.shape[1], bob_image.shape[2], bob_image.shape[0]), dtype="uint8")
if change_color:
dlib_image[:, :, 0] = bob_image[2, :, :] # B
dlib_image[:, :, 1] = bob_image[1, :, :] # G
dlib_image[:, :, 2] = bob_image[0, :, :] # R
else:
dlib_image[:, :, 0] = bob_image[0, :, :] # B
dlib_image[:, :, 1] = bob_image[1, :, :] # G
dlib_image[:, :, 2] = bob_image[2, :, :] # R
return dlib_image
def dlib_to_bob_image_convertion(dlib_image, change_color=True):
"""
Bob stores color images as (C, W, H), where C is channels, W is the width and H is height; AND the order of the
colors are R,G,B.
On the other hand, Dlib do (W, H, C) AND the order of the colors are the same as OpenCV (B, G, R)
"""
if len(dlib_image.shape) == 2:
return dlib_image
bob_image = numpy.zeros(shape=(dlib_image.shape[2], dlib_image.shape[0], dlib_image.shape[1]), dtype="uint8")
if change_color:
bob_image[0, :, :] = dlib_image[:, :, 2] # R
bob_image[1, :, :] = dlib_image[:, :, 1] # G
bob_image[2, :, :] = dlib_image[:, :, 0] # B
else:
bob_image[0, :, :] = dlib_image[:, :, 0] # R
bob_image[1, :, :] = dlib_image[:, :, 1] # G
bob_image[2, :, :] = dlib_image[:, :, 2] # B
return bob_image
def rectangle2bounding_box2(raw_bounding_boxes):
"""
Converts a bob.ip.facedetect.BoundingBox
......
......@@ -41,7 +41,7 @@ The most simple face detection task is to detect a single face in an image. This
>>> color_image = bob.io.base.load(bob.io.base.test_utils.datafile('testimage.jpg', 'bob.ip.facedetect'))
>>> bounding_box, landmarks = bob.ip.mtcnn.FaceDetector().detect_single_face(color_image)
>>> print(bounding_box.topleft)
(68, 70)
(64, 77)
.. plot:: plot/plot_single_faces.py
:include-source: False
......@@ -80,7 +80,7 @@ The detection of landmarks can be done as the following:
>>> color_image = bob.io.base.load(bob.io.base.test_utils.datafile('testimage.jpg', 'bob.ip.facedetect'))
>>> bounding_box, landmarks = bob.ip.mtcnn.FaceDetector().detect_single_face(color_image)
>>> print (landmarks['leye'])
(174, 223)
(174, 219)
......
......@@ -14,17 +14,17 @@ face_crop_aligned = bob.ip.mtcnn.FaceDetector().detect_crop_align(color_image, f
ax = pyplot.subplot(1, 3, 1)
ax.set_title("Before normalization")
pyplot.imshow(bob.ip.mtcnn.utils.bob_to_dlib_image_convertion(color_image , change_color=False))
pyplot.imshow(bob.io.image.to_matplotlib(color_image))
pyplot.axis('off')
ax = pyplot.subplot(1, 3, 2)
ax.set_title("Normalized")
pyplot.imshow(bob.ip.mtcnn.utils.bob_to_dlib_image_convertion(face_crop, change_color=False))
pyplot.imshow(bob.io.image.to_matplotlib(face_crop).astype("uint8"))
pyplot.axis('off')
ax = pyplot.subplot(1, 3, 3)
ax.set_title("Normalized and aligned")
pyplot.imshow(bob.ip.mtcnn.utils.bob_to_dlib_image_convertion(face_crop_aligned, change_color=False))
pyplot.imshow(bob.io.image.to_matplotlib(face_crop_aligned).astype("uint8"))
pyplot.axis('off')
#pyplot.show()
......
......@@ -31,12 +31,12 @@ for b, l in zip(mtcnn_bounding_box, landmarks):
ax = pyplot.subplot(1, 2, 1)
ax.set_title("MTCNN")
pyplot.imshow(bob.ip.mtcnn.utils.bob_to_dlib_image_convertion(mtcnn_color_image, change_color=False))
pyplot.imshow(bob.io.image.to_matplotlib(mtcnn_color_image))
pyplot.axis('off')
ax = pyplot.subplot(1, 2, 2)
ax.set_title("Bob")
pyplot.imshow(bob.ip.mtcnn.utils.bob_to_dlib_image_convertion(bob_color_image, change_color=False))
pyplot.imshow(bob.io.image.to_matplotlib(bob_color_image))
pyplot.axis('off')
#pyplot.show()
......
......@@ -28,12 +28,12 @@ for p in landmarks:
ax = pyplot.subplot(1, 2, 1)
ax.set_title("mtcnn")
pyplot.imshow(bob.ip.mtcnn.utils.bob_to_dlib_image_convertion(mtcnn_color_image, change_color=False))
pyplot.imshow(bob.io.image.to_matplotlib(mtcnn_color_image))
pyplot.axis('off')
ax = pyplot.subplot(1, 2, 2)
ax.set_title("Bob")
pyplot.imshow(bob.ip.mtcnn.utils.bob_to_dlib_image_convertion(bob_color_image, change_color=False))
pyplot.imshow(bob.io.image.to_matplotlib(bob_color_image))
pyplot.axis('off')
#pyplot.show()
......
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