Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Harrytsz
face_recognition
提交
b10c1190
F
face_recognition
项目概览
Harrytsz
/
face_recognition
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
face_recognition
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b10c1190
编写于
3月 17, 2017
作者:
A
Adam Geitgey
提交者:
GitHub
3月 17, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make sure detected face locations don't cross outside image bounds (#15)
上级
3976fae6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
27 addition
and
2 deletion
+27
-2
face_recognition/api.py
face_recognition/api.py
+14
-2
tests/test_face_recognition.py
tests/test_face_recognition.py
+13
-0
tests/test_images/obama_partial_face.jpg
tests/test_images/obama_partial_face.jpg
+0
-0
tests/test_images/obama_partial_face2.jpg
tests/test_images/obama_partial_face2.jpg
+0
-0
未找到文件。
face_recognition/api.py
浏览文件 @
b10c1190
...
...
@@ -12,6 +12,8 @@ except:
print
(
"pip install git+https://github.com/ageitgey/face_recognition_models"
)
quit
()
face_detector
=
dlib
.
get_frontal_face_detector
()
predictor_model
=
face_recognition_models
.
pose_predictor_model_location
()
pose_predictor
=
dlib
.
shape_predictor
(
predictor_model
)
...
...
@@ -39,6 +41,17 @@ def _css_to_rect(css):
return
dlib
.
rectangle
(
css
[
3
],
css
[
0
],
css
[
1
],
css
[
2
])
def
_trim_css_to_bounds
(
css
,
image_shape
):
"""
Make sure a tuple in (top, right, bottom, left) order is within the bounds of the image.
:param css: plain tuple representation of the rect in (top, right, bottom, left) order
:param image_shape: numpy shape of the image array
:return: a trimmed plain tuple representation of the rect in (top, right, bottom, left) order
"""
return
max
(
css
[
0
],
0
),
min
(
css
[
1
],
image_shape
[
1
]),
min
(
css
[
2
],
image_shape
[
0
]),
max
(
css
[
3
],
0
)
def
_face_distance
(
faces
,
face_to_compare
):
"""
Given a list of face encodings, compared them to a known face encoding and get a euclidean distance
...
...
@@ -70,7 +83,6 @@ def _raw_face_locations(img, number_of_times_to_upsample=1):
:param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
:return: A list of dlib 'rect' objects of found face locations
"""
face_detector
=
dlib
.
get_frontal_face_detector
()
return
face_detector
(
img
,
number_of_times_to_upsample
)
...
...
@@ -82,7 +94,7 @@ def face_locations(img, number_of_times_to_upsample=1):
:param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
:return: A list of tuples of found face locations in css (top, right, bottom, left) order
"""
return
[
_
rect_to_css
(
fac
e
)
for
face
in
_raw_face_locations
(
img
,
number_of_times_to_upsample
)]
return
[
_
trim_css_to_bounds
(
_rect_to_css
(
face
),
img
.
shap
e
)
for
face
in
_raw_face_locations
(
img
,
number_of_times_to_upsample
)]
def
_raw_face_landmarks
(
face_image
,
face_locations
=
None
):
...
...
tests/test_face_recognition.py
浏览文件 @
b10c1190
...
...
@@ -50,6 +50,19 @@ class Test_face_recognition(unittest.TestCase):
self
.
assertEqual
(
len
(
detected_faces
),
1
)
self
.
assertEqual
(
detected_faces
[
0
],
(
142
,
617
,
409
,
349
))
def
test_partial_face_locations
(
self
):
img
=
api
.
load_image_file
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'test_images'
,
'obama_partial_face.jpg'
))
detected_faces
=
api
.
face_locations
(
img
)
self
.
assertEqual
(
len
(
detected_faces
),
1
)
self
.
assertEqual
(
detected_faces
[
0
],
(
142
,
191
,
365
,
0
))
img
=
api
.
load_image_file
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'test_images'
,
'obama_partial_face2.jpg'
))
detected_faces
=
api
.
face_locations
(
img
)
self
.
assertEqual
(
len
(
detected_faces
),
1
)
self
.
assertEqual
(
detected_faces
[
0
],
(
142
,
551
,
409
,
349
))
def
test_raw_face_landmarks
(
self
):
img
=
api
.
load_image_file
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'test_images'
,
'obama.jpg'
))
face_landmarks
=
api
.
_raw_face_landmarks
(
img
)
...
...
tests/test_images/obama_partial_face.jpg
0 → 100644
浏览文件 @
b10c1190
413.1 KB
tests/test_images/obama_partial_face2.jpg
0 → 100644
浏览文件 @
b10c1190
467.1 KB
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录