Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
face
Project
Overview
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
Иван Кубота
face
Commits
4a1a9629
Commit
4a1a9629
authored
Jun 17, 2018
by
vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
example for face detection + landmarks
parent
21b3c7bf
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
1 deletion
+118
-1
commons.js
examples/public/commons.js
+4
-0
server.js
examples/server.js
+2
-0
detectAndDrawLandmarks.html
examples/views/detectAndDrawLandmarks.html
+112
-0
faceDetectionVideo.html
examples/views/faceDetectionVideo.html
+0
-1
No files found.
examples/public/commons.js
View file @
4a1a9629
...
...
@@ -93,6 +93,10 @@ function renderNavBar(navbarId, exampleUri) {
name
:
'Face Landmarks'
},
{
uri
:
'detect_and_draw_landmarks'
,
name
:
'Detect and Draw Landmarks'
},
{
uri
:
'detect_and_draw_faces'
,
name
:
'Detect and Draw Faces'
},
...
...
examples/server.js
View file @
4a1a9629
...
...
@@ -17,6 +17,7 @@ app.get('/face_recognition', (req, res) => res.sendFile(path.join(viewsDir, 'fac
app
.
get
(
'/face_similarity'
,
(
req
,
res
)
=>
res
.
sendFile
(
path
.
join
(
viewsDir
,
'faceSimilarity.html'
)))
app
.
get
(
'/face_landmarks'
,
(
req
,
res
)
=>
res
.
sendFile
(
path
.
join
(
viewsDir
,
'faceLandmarks.html'
)))
app
.
get
(
'/detect_and_draw_faces'
,
(
req
,
res
)
=>
res
.
sendFile
(
path
.
join
(
viewsDir
,
'detectAndDrawFaces.html'
)))
app
.
get
(
'/detect_and_draw_landmarks'
,
(
req
,
res
)
=>
res
.
sendFile
(
path
.
join
(
viewsDir
,
'detectAndDrawLandmarks.html'
)))
app
.
get
(
'/detect_and_recognize_faces'
,
(
req
,
res
)
=>
res
.
sendFile
(
path
.
join
(
viewsDir
,
'detectAndRecognizeFaces.html'
)))
app
.
listen
(
3000
,
()
=>
console
.
log
(
'Listening on port 3000!'
))
\ No newline at end of file
examples/views/detectAndDrawLandmarks.html
0 → 100644
View file @
4a1a9629
<!DOCTYPE html>
<html>
<head>
<script
src=
"face-api.js"
></script>
<script
src=
"axios.min.js"
></script>
<script
src=
"commons.js"
></script>
<link
rel=
"stylesheet"
href=
"styles.css"
>
<link
rel=
"stylesheet"
href=
"https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.css"
>
<script
type=
"text/javascript"
src=
"https://code.jquery.com/jquery-2.1.1.min.js"
></script>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"
></script>
</head>
<body>
<div
class=
"center-content page-container"
>
<div
id=
"navbar"
></div>
<div
class=
"progress"
id=
"loader"
>
<div
class=
"indeterminate"
></div>
</div>
<div
style=
"position: relative"
class=
"margin"
>
<img
id=
"inputImg"
src=
""
style=
"max-width: 800px;"
/>
<canvas
id=
"overlay"
/>
</div>
<div
class=
"row side-by-side"
>
<div
id=
"selectList"
></div>
<div
class=
"row"
>
<label
for=
"minConfidence"
>
Min Confidence:
</label>
<input
disabled
value=
"0.7"
id=
"minConfidence"
type=
"text"
class=
"bold"
>
</div>
<button
class=
"waves-effect waves-light btn"
onclick=
"onDecreaseMinConfidence()"
>
<i
class=
"material-icons left"
>
-
</i>
</button>
<button
class=
"waves-effect waves-light btn"
onclick=
"onIncreaseMinConfidence()"
>
<i
class=
"material-icons left"
>
+
</i>
</button>
</div>
</div>
<script>
let
minConfidence
=
0.7
let
drawLines
=
true
let
detectionNet
,
landmarkNet
function
onIncreaseMinConfidence
()
{
minConfidence
=
Math
.
min
(
faceapi
.
round
(
minConfidence
+
0.1
),
1.0
)
$
(
'#minConfidence'
).
val
(
minConfidence
)
updateResults
()
}
function
onDecreaseMinConfidence
()
{
minConfidence
=
Math
.
max
(
faceapi
.
round
(
minConfidence
-
0.1
),
0.1
)
$
(
'#minConfidence'
).
val
(
minConfidence
)
updateResults
()
}
async
function
updateResults
()
{
const
inputImgEl
=
$
(
'#inputImg'
).
get
(
0
)
const
{
width
,
height
}
=
inputImgEl
const
canvas
=
$
(
'#overlay'
).
get
(
0
)
canvas
.
width
=
width
canvas
.
height
=
height
const
input
=
new
faceapi
.
NetInput
(
inputImgEl
)
const
locations
=
await
detectionNet
.
locateFaces
(
input
,
minConfidence
)
const
faceTensors
=
(
await
faceapi
.
extractFaceTensors
(
input
,
locations
))
landmarksByFace
=
await
Promise
.
all
(
faceTensors
.
map
(
t
=>
landmarkNet
.
detectLandmarks
(
t
)))
// free memory for face image tensors after we computed their descriptors
faceTensors
.
forEach
(
t
=>
t
.
dispose
())
landmarksByFace
.
forEach
((
landmarks
,
i
)
=>
{
// shift and scale the face landmarks to the face image position in the canvas
const
box
=
locations
[
i
].
forSize
(
width
,
height
).
getBox
()
faceapi
.
drawLandmarks
(
canvas
,
landmarks
.
forSize
(
box
.
width
,
box
.
height
).
shift
(
box
.
x
,
box
.
y
),
{
lineWidth
:
drawLines
?
2
:
4
,
drawLines
,
color
:
'red'
})
})
faceapi
.
drawDetection
(
'overlay'
,
locations
.
map
(
det
=>
det
.
forSize
(
width
,
height
)))
}
async
function
onSelectionChanged
(
uri
)
{
const
imgBuf
=
await
fetchImage
(
uri
)
$
(
`#inputImg`
).
get
(
0
).
src
=
(
await
faceapi
.
bufferToImage
(
imgBuf
)).
src
updateResults
()
}
async
function
run
()
{
detectionNet
=
await
initFaceDetectionNet
()
landmarkNet
=
await
initFaceLandmarkNet
()
$
(
'#loader'
).
hide
()
onSelectionChanged
(
$
(
'#selectList select'
).
val
())
}
$
(
document
).
ready
(
function
()
{
renderNavBar
(
'#navbar'
,
'detect_and_draw_landmarks'
)
renderImageSelectList
(
'#selectList'
,
async
(
uri
)
=>
{
await
onSelectionChanged
(
uri
)
},
'bbt1.jpg'
)
run
()
})
</script>
</body>
</html>
\ No newline at end of file
examples/views/faceDetectionVideo.html
View file @
4a1a9629
...
...
@@ -20,7 +20,6 @@
<canvas
id=
"overlay"
/>
</div>
<div
class=
"row side-by-side"
>
<div
id=
"selectList"
></div>
<div
class=
"row"
>
<label
for=
"minConfidence"
>
Min Confidence:
</label>
<input
disabled
value=
"0.7"
id=
"minConfidence"
type=
"text"
class=
"bold"
>
...
...
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