提交 20d50f36 编写于 作者: A Adam Geitgey

Don't choke on images that use 32 bits per channel. Downsample them.

上级 961e2c61
......@@ -44,14 +44,15 @@ def _face_distance(faces, face_to_compare):
return np.array([np.linalg.norm(face - face_to_compare) for face in faces])
def load_image_file(filename):
def load_image_file(filename, mode='RGB'):
"""
Loads an image file (.jpg, .png, etc) into a numpy array
:param filename: image file to load
:param mode: format to convert the image to. Only 'RGB' (8-bit RGB, 3 channels) and 'L' (black and white) are supported.
:return: image contents as numpy array
"""
return scipy.misc.imread(filename)
return scipy.misc.imread(filename, mode=mode)
def _raw_face_locations(img, number_of_times_to_upsample=1):
......
......@@ -21,9 +21,12 @@ class Test_face_recognition(unittest.TestCase):
def test_load_image_file(self):
img = api.load_image_file(os.path.join(os.path.dirname(__file__), "test_images", "obama.jpg"))
assert img.shape == (1137, 910, 3)
def test_load_image_file_32bit(self):
img = api.load_image_file(os.path.join(os.path.dirname(__file__), "test_images", "32bit.png"))
assert img.shape == (1200, 626, 3)
def test_raw_face_locations(self):
img = api.load_image_file(os.path.join(os.path.dirname(__file__), "test_images", "obama.jpg"))
detected_faces = api._raw_face_locations(img)
......@@ -32,6 +35,14 @@ class Test_face_recognition(unittest.TestCase):
assert detected_faces[0].top() == 142
assert detected_faces[0].bottom() == 409
def test_raw_face_locations_32bit_image(self):
img = api.load_image_file(os.path.join(os.path.dirname(__file__), "test_images", "32bit.png"))
detected_faces = api._raw_face_locations(img)
assert len(detected_faces) == 1
assert detected_faces[0].top() == 290
assert detected_faces[0].bottom() == 558
def test_face_locations(self):
img = api.load_image_file(os.path.join(os.path.dirname(__file__), "test_images", "obama.jpg"))
detected_faces = api.face_locations(img)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册