Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
eye_distance
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
任婷婷
eye_distance
Commits
95264ad6
Commit
95264ad6
authored
Sep 30, 2019
by
任婷婷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first commit
parents
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
0 deletions
+79
-0
1.jpg
1.jpg
+0
-0
README.md
README.md
+6
-0
eyedist.py
eyedist.py
+73
-0
shape_predictor_68_face_landmarks.dat
shape_predictor_68_face_landmarks.dat
+0
-0
No files found.
1.jpg
0 → 100644
View file @
95264ad6
43.3 KB
README.md
0 → 100644
View file @
95264ad6
1.
requirements
dlib
opencv-python
2.
demo
python eyedist.py
eyedist.py
0 → 100644
View file @
95264ad6
import
dlib
import
os
import
math
#from align import AlignDlib
import
cv2
import
pandas
as
pd
from
numpy
import
array
import
io
import
requests
from
PIL
import
Image
import
numpy
as
np
class
TooManyFaces
(
Exception
):
pass
class
NoFaces
(
Exception
):
pass
def
load_model
(
PREDICTOR_PATH
):
detector
=
dlib
.
get_frontal_face_detector
()
predictor
=
dlib
.
shape_predictor
(
PREDICTOR_PATH
)
return
detector
,
predictor
def
eyedist
(
img
,
predictor
,
detector
):
rects
=
None
if
img
is
not
None
:
rects
=
detector
(
img
,
1
)
else
:
print
(
"input img is empty"
)
if
len
(
rects
)
>
1
:
raise
TooManyFaces
if
len
(
rects
)
==
0
:
raise
NoFaces
lks
=
predictor
(
img
,
rects
[
0
])
.
parts
()
left_corner
=
lks
[
39
]
right_corner
=
lks
[
42
]
left_tail
=
lks
[
36
]
right_tail
=
lks
[
45
]
left_dist
=
math
.
hypot
(
left_corner
.
x
-
left_tail
.
x
,
left_corner
.
y
-
left_tail
.
y
)
right_dist
=
math
.
hypot
(
right_corner
.
x
-
right_tail
.
x
,
right_corner
.
y
-
right_tail
.
y
)
corner_dist
=
math
.
hypot
(
left_corner
.
x
-
right_corner
.
x
,
left_corner
.
y
-
right_corner
.
y
)
if
left_dist
>=
right_dist
:
ratio
=
float
(
corner_dist
/
left_dist
)
else
:
ratio
=
float
(
corner_dist
/
right_dist
)
cate
=
None
if
ratio
>
1.3
:
cate
=
'guokuan'
elif
1.1
<
ratio
<=
1.3
:
#elif ratio>1.1 and ratio<=1.3:
cate
=
'luekuan'
elif
1
<
ratio
<=
1.1
:
cate
=
'shizhong'
elif
0.95
<
ratio
<=
1
:
cate
=
'luezhai'
elif
ratio
<=
0.95
:
cate
=
'guozhai'
return
cate
,
ratio
if
__name__
==
'__main__'
:
PREDICTOR_PATH
=
'shape_predictor_68_face_landmarks.dat'
detector
,
predictor
=
load_model
(
PREDICTOR_PATH
)
img
=
cv2
.
imread
(
'1.jpg'
)
category
,
ratio
=
eyedist
(
img
,
predictor
,
detector
)
print
(
'category:'
,
category
,
'ratio:'
,
ratio
)
shape_predictor_68_face_landmarks.dat
0 → 100644
View file @
95264ad6
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment