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
83d51e42
Commit
83d51e42
authored
Jun 09, 2018
by
vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjust examples to changes
parent
2ae76364
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
47 deletions
+42
-47
faceDetection.html
examples/views/faceDetection.html
+7
-10
faceDetectionVideo.html
examples/views/faceDetectionVideo.html
+21
-16
faceRecognition.html
examples/views/faceRecognition.html
+10
-12
faceSimilarity.html
examples/views/faceSimilarity.html
+4
-9
No files found.
examples/views/faceDetection.html
View file @
83d51e42
<!DOCTYPE html>
<html>
<head>
<script
src=
"face-recognition.
min.
js"
></script>
<script
src=
"face-recognition.js"
></script>
<script
src=
"axios.min.js"
></script>
<script
src=
"commons.js"
></script>
<link
rel=
"stylesheet"
href=
"styles.css"
>
...
...
@@ -16,7 +16,7 @@
<div
class=
"indeterminate"
></div>
</div>
<div
style=
"position: relative"
class=
"margin"
>
<img
id=
"img"
src=
""
style=
"max-width: 800px;"
/>
<img
id=
"i
nputI
mg"
src=
""
style=
"max-width: 800px;"
/>
<canvas
id=
"overlay"
/>
</div>
<div
class=
"row side-by-side"
>
...
...
@@ -57,22 +57,19 @@
}
async
function
updateResults
()
{
const
imgEl
=
$
(
`#img`
).
get
(
0
)
result
=
await
net
.
locateFaces
(
await
facerecognition
.
mediaSrcToImageData
(
imgEl
.
src
),
minConfidence
)
const
input
=
new
facerecognition
.
NetInput
(
'inputImg'
)
const
{
width
,
height
}
=
input
const
canvas
=
$
(
'#overlay'
).
get
(
0
)
const
width
=
$
(
`#img`
).
width
()
const
height
=
$
(
`#img`
).
height
()
canvas
.
width
=
width
canvas
.
height
=
height
result
=
await
net
.
locateFaces
(
input
,
minConfidence
)
facerecognition
.
drawDetection
(
'overlay'
,
result
.
map
(
det
=>
det
.
forSize
(
width
,
height
)))
}
async
function
onSelectionChanged
(
uri
)
{
const
imgBuf
=
await
fetchImage
(
uri
)
$
(
`#i
mg`
).
get
(
0
).
src
=
await
facerecognition
.
bufferToImgSrc
(
imgBuf
)
$
(
`#i
nputImg`
).
get
(
0
).
src
=
(
await
facerecognition
.
bufferToImage
(
imgBuf
)).
src
updateResults
()
}
...
...
examples/views/faceDetectionVideo.html
View file @
83d51e42
<!DOCTYPE html>
<html>
<head>
<script
src=
"face-recognition.
min.
js"
></script>
<script
src=
"face-recognition.js"
></script>
<script
src=
"axios.min.js"
></script>
<script
src=
"commons.js"
></script>
<link
rel=
"stylesheet"
href=
"styles.css"
>
...
...
@@ -38,6 +38,16 @@
<i
class=
"material-icons left"
>
+
</i>
</button>
</div>
<div
class=
"row side-by-side"
>
<div
class=
"row"
>
<label
for=
"time"
>
Time:
</label>
<input
disabled
value=
"-"
id=
"time"
type=
"text"
class=
"bold"
>
</div>
<div
class=
"row"
>
<label
for=
"fps"
>
Estimated Fps:
</label>
<input
disabled
value=
"-"
id=
"fps"
type=
"text"
class=
"bold"
>
</div>
</div>
</div>
<script>
...
...
@@ -47,37 +57,32 @@
function
onIncreaseThreshold
()
{
minConfidence
=
Math
.
min
(
facerecognition
.
round
(
minConfidence
+
0.1
),
1.0
)
$
(
'#minConfidence'
).
val
(
minConfidence
)
updateResults
()
}
function
onDecreaseThreshold
()
{
minConfidence
=
Math
.
max
(
facerecognition
.
round
(
minConfidence
-
0.1
),
0.1
)
$
(
'#minConfidence'
).
val
(
minConfidence
)
updateResults
()
}
function
displayTimeStats
(
timeInMs
)
{
$
(
'#time'
).
val
(
`
${
timeInMs
}
ms`
)
$
(
'#fps'
).
val
(
`
${
facerecognition
.
round
(
1000
/
timeInMs
)}
`
)
}
async
function
onPlay
(
videoEl
)
{
if
(
videoEl
.
paused
||
videoEl
.
ended
)
return
false
console
.
time
(
'frame'
)
const
width
=
$
(
videoEl
).
innerWidth
()
const
height
=
$
(
videoEl
).
innerHeight
()
videoEl
.
width
=
width
videoEl
.
height
=
height
const
input
=
new
facerecognition
.
NetInput
(
videoEl
)
const
{
width
,
height
}
=
input
const
canvas
=
$
(
'#overlay'
).
get
(
0
)
canvas
.
width
=
width
canvas
.
height
=
height
const
fromPixelsCanvas
=
document
.
createElement
(
'canvas'
)
fromPixelsCanvas
.
width
=
videoEl
.
width
fromPixelsCanvas
.
height
=
videoEl
.
height
fromPixelsCanvas
.
getContext
(
'2d'
).
drawImage
(
videoEl
,
0
,
0
,
videoEl
.
width
,
videoEl
.
height
)
const
ts
=
Date
.
now
()
result
=
await
net
.
locateFaces
(
input
,
minConfidence
)
displayTimeStats
(
Date
.
now
()
-
ts
)
result
=
await
net
.
locateFaces
(
fromPixelsCanvas
,
minConfidence
)
console
.
timeEnd
(
'frame'
)
console
.
log
(
facerecognition
.
tf
.
memory
())
facerecognition
.
drawDetection
(
'overlay'
,
result
.
map
(
det
=>
det
.
forSize
(
width
,
height
)))
setTimeout
(()
=>
onPlay
(
videoEl
))
}
...
...
examples/views/faceRecognition.html
View file @
83d51e42
<!DOCTYPE html>
<html>
<head>
<script
src=
"face-recognition.
min.
js"
></script>
<script
src=
"face-recognition.js"
></script>
<script
src=
"axios.min.js"
></script>
<script
src=
"commons.js"
></script>
<link
rel=
"stylesheet"
href=
"styles.css"
>
...
...
@@ -108,10 +108,10 @@
getImg
().
src
=
src
}
async
function
loadTraining
Data
(
cb
)
{
async
function
loadTraining
Images
(
)
{
return
await
Promise
.
all
(
classes
.
map
(
async
className
=>
({
img
Data
:
await
facerecognition
.
bufferToImageData
(
img
:
await
facerecognition
.
bufferToImage
(
await
fetchImage
(
getFaceImageUri
(
className
,
1
))
),
className
...
...
@@ -135,16 +135,14 @@
async
function
runFaceRecognition
()
{
async
function
next
()
{
const
imgBuf
=
await
fetchImage
(
getFaceImageUri
(
classes
[
currClassIdx
],
currImageIdx
))
const
input
=
await
facerecognition
.
bufferToImage
(
imgBuf
)
const
imgEl
=
$
(
'#face'
).
get
(
0
)
imgEl
.
src
=
await
facerecognition
.
bufferToImgSrc
(
imgBuf
)
const
imageData
=
await
facerecognition
.
mediaSrcToImageData
(
imgEl
.
src
)
imgEl
.
src
=
input
.
src
const
ts
=
Date
.
now
()
const
result
=
await
net
.
forward
(
imageData
)
const
descriptor
=
await
net
.
computeFaceDescriptor
(
input
)
displayTimeStats
(
Date
.
now
()
-
ts
)
const
descriptor
=
await
result
.
data
()
const
bestMatch
=
getBestMatch
(
descriptor
)
$
(
'#prediction'
).
val
(
`
${
bestMatch
.
distance
<
threshold
?
bestMatch
.
className
:
'unkown'
}
(
${
bestMatch
.
distance
}
)`
)
...
...
@@ -166,10 +164,10 @@
net
=
await
initFaceRecognitionNet
()
setStatusText
(
'computing initial descriptors...'
)
const
trainImg
Datas
=
await
loadTrainingData
()
trainDescriptorsByClass
=
await
Promise
.
all
(
trainImg
Data
s
.
map
(
async
({
className
,
img
Data
})
=>
({
descriptor
:
await
net
.
computeFaceDescriptor
(
img
Data
),
const
trainImg
s
=
await
loadTrainingImages
()
trainDescriptorsByClass
=
await
Promise
.
all
(
trainImgs
.
map
(
async
({
className
,
img
})
=>
({
descriptor
:
await
net
.
computeFaceDescriptor
(
img
),
className
})
))
...
...
examples/views/faceSimilarity.html
View file @
83d51e42
<!DOCTYPE html>
<html>
<head>
<script
src=
"face-recognition.
min.
js"
></script>
<script
src=
"face-recognition.js"
></script>
<script
src=
"axios.min.js"
></script>
<script
src=
"commons.js"
></script>
<link
rel=
"stylesheet"
href=
"styles.css"
>
...
...
@@ -53,17 +53,12 @@
$
(
'#distance'
).
css
(
'background-color'
,
bgColor
)
}
async
function
computeDescriptorFromSrc
(
imgEl
)
{
return
net
.
computeFaceDescriptor
(
await
facerecognition
.
mediaSrcToImageData
(
imgEl
.
src
)
)
}
async
function
onSelectionChanged
(
which
,
uri
)
{
const
imgBuf
=
await
fetchImage
(
uri
)
const
input
=
await
facerecognition
.
bufferToImage
(
imgBuf
)
const
imgEl
=
$
(
`#face
${
which
}
`
).
get
(
0
)
imgEl
.
src
=
await
facerecognition
.
bufferToImgSrc
(
imgBuf
)
descriptors
[
`desc
${
which
}
`
]
=
await
computeDescriptorFromSrc
(
imgEl
)
imgEl
.
src
=
input
.
src
descriptors
[
`desc
${
which
}
`
]
=
await
net
.
computeFaceDescriptor
(
input
)
}
async
function
run
()
{
...
...
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