Skip to content

Commit c261b64

Browse files
committedFeb 27, 2018
Remove scipy dependency and bump version
1 parent fe421d4 commit c261b64

File tree

7 files changed

+27
-16
lines changed

7 files changed

+27
-16
lines changed
 

‎docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Mock(MagicMock):
2222
def __getattr__(cls, name):
2323
return MagicMock()
2424

25-
MOCK_MODULES = ['face_recognition_models', 'Click', 'dlib', 'numpy', 'scipy', 'scipy.misc']
25+
MOCK_MODULES = ['face_recognition_models', 'Click', 'dlib', 'numpy', 'PIL']
2626
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
2727

2828
# If extensions (or modules to document with autodoc) are in another

‎face_recognition/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
__author__ = """Adam Geitgey"""
44
__email__ = 'ageitgey@gmail.com'
5-
__version__ = '0.1.0'
5+
__version__ = '1.2.2'
66

77
from .api import load_image_file, face_locations, batch_face_locations, face_landmarks, face_encodings, compare_faces, face_distance

‎face_recognition/api.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
import scipy.misc
3+
import PIL.Image
44
import dlib
55
import numpy as np
66

@@ -81,7 +81,10 @@ def load_image_file(file, mode='RGB'):
8181
:param mode: format to convert the image to. Only 'RGB' (8-bit RGB, 3 channels) and 'L' (black and white) are supported.
8282
:return: image contents as numpy array
8383
"""
84-
return scipy.misc.imread(file, mode=mode)
84+
im = PIL.Image.open(file)
85+
if mode:
86+
im = im.convert(mode)
87+
return np.array(im)
8588

8689

8790
def _raw_face_locations(img, number_of_times_to_upsample=1, model="hog"):
@@ -195,7 +198,6 @@ def face_encodings(face_image, known_face_locations=None, num_jitters=1):
195198
:return: A list of 128-dimensional face encodings (one for each face in the image)
196199
"""
197200
raw_landmarks = _raw_face_landmarks(face_image, known_face_locations, model="small")
198-
199201
return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]
200202

201203

‎face_recognition/cli.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import click
44
import os
55
import re
6-
import scipy.misc
7-
import warnings
86
import face_recognition.api as face_recognition
97
import multiprocessing
108
import itertools
119
import sys
10+
import PIL.Image
11+
import numpy as np
1212

1313

1414
def scan_known_people(known_people_folder):
@@ -43,11 +43,10 @@ def test_image(image_to_check, known_names, known_face_encodings, tolerance=0.6,
4343
unknown_image = face_recognition.load_image_file(image_to_check)
4444

4545
# Scale down image if it's giant so things run a little faster
46-
if unknown_image.shape[1] > 1600:
47-
scale_factor = 1600.0 / unknown_image.shape[1]
48-
with warnings.catch_warnings():
49-
warnings.simplefilter("ignore")
50-
unknown_image = scipy.misc.imresize(unknown_image, scale_factor)
46+
if max(unknown_image.shape) > 1600:
47+
pil_img = PIL.Image.fromarray(unknown_image)
48+
pil_img.thumbnail((1600, 1600), PIL.Image.LANCZOS)
49+
unknown_image = np.array(pil_img)
5150

5251
unknown_encodings = face_recognition.face_encodings(unknown_image)
5352

‎setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.0
2+
current_version = 1.2.1
33
commit = True
44
tag = True
55

‎setup.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
'Click>=6.0',
1515
'dlib>=19.7',
1616
'numpy',
17-
'Pillow',
18-
'scipy>=0.17.0'
17+
'Pillow'
1918
]
2019

2120
test_requirements = [
@@ -25,7 +24,7 @@
2524

2625
setup(
2726
name='face_recognition',
28-
version='1.2.1',
27+
version='1.2.2',
2928
description="Recognize faces from Python or from the command line",
3029
long_description=readme + '\n\n' + history,
3130
author="Adam Geitgey",

‎tests/test_face_recognition.py

+11
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ def test_command_line_interface(self):
246246
self.assertEqual(result.exit_code, 0)
247247
self.assertTrue(target_string in result.output)
248248

249+
def test_command_line_interface_big_image(self):
250+
target_string = 'obama3.jpg,obama'
251+
runner = CliRunner()
252+
image_folder = os.path.join(os.path.dirname(__file__), 'test_images')
253+
image_file = os.path.join(os.path.dirname(__file__), 'test_images', 'obama3.jpg')
254+
255+
result = runner.invoke(cli.main, args=[image_folder, image_file])
256+
257+
self.assertEqual(result.exit_code, 0)
258+
self.assertTrue(target_string in result.output)
259+
249260
def test_command_line_interface_tolerance(self):
250261
target_string = 'obama.jpg,obama'
251262
runner = CliRunner()

0 commit comments

Comments
 (0)
Please sign in to comment.