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
a644af17
Commit
a644af17
authored
Jun 16, 2018
by
vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
getters for coordinates the contours for landmarks and draw contours
parent
0c75bc37
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
8 deletions
+95
-8
faceLandmarks.html
examples/views/faceLandmarks.html
+21
-6
FaceLandmarks.ts
src/faceLandmarkNet/FaceLandmarks.ts
+28
-0
utils.ts
src/utils.ts
+46
-2
No files found.
examples/views/faceLandmarks.html
View file @
a644af17
...
@@ -23,21 +23,36 @@
...
@@ -23,21 +23,36 @@
<div
id=
"selectList"
></div>
<div
id=
"selectList"
></div>
</div>
</div>
</div>
</div>
<p>
<input
type=
"checkbox"
id=
"drawLinesCheckbox"
checked=
"checked"
onchange=
"onChangeDrawLines(event)"
/>
<label
for=
"drawLinesCheckbox"
>
Draw Lines
</label>
</p>
</div>
</div>
</div>
</div>
<script>
<script>
let
net
let
net
let
drawLines
=
true
let
landmarks
let
currentImg
async
function
onSelectionChanged
(
uri
)
{
function
onChangeDrawLines
(
e
)
{
const
imgBuf
=
await
fetchImage
(
uri
)
drawLines
=
$
(
e
.
target
).
prop
(
'checked'
)
const
img
=
await
faceapi
.
bufferToImage
(
imgBuf
)
redraw
()
const
canvas
=
faceapi
.
createCanvasFromMedia
(
img
)
}
function
redraw
()
{
const
canvas
=
faceapi
.
createCanvasFromMedia
(
currentImg
)
$
(
'#faceContainer'
).
empty
()
$
(
'#faceContainer'
).
empty
()
$
(
'#faceContainer'
).
append
(
canvas
)
$
(
'#faceContainer'
).
append
(
canvas
)
faceapi
.
drawLandmarks
(
canvas
,
landmarks
,
{
lineWidth
:
drawLines
?
2
:
4
,
drawLines
})
}
const
landmarks
=
await
net
.
detectLandmarks
(
canvas
)
async
function
onSelectionChanged
(
uri
)
{
faceapi
.
drawLandmarks
(
canvas
,
landmarks
,
{
lineWidth
:
4
})
const
imgBuf
=
await
fetchImage
(
uri
)
currentImg
=
await
faceapi
.
bufferToImage
(
imgBuf
)
landmarks
=
await
net
.
detectLandmarks
(
currentImg
)
redraw
()
}
}
async
function
run
()
{
async
function
run
()
{
...
...
src/faceLandmarkNet/FaceLandmarks.ts
View file @
a644af17
...
@@ -28,6 +28,34 @@ export class FaceLandmarks {
...
@@ -28,6 +28,34 @@ export class FaceLandmarks {
)
)
}
}
public
getJawOutline
()
{
return
this
.
_faceLandmarks
.
slice
(
0
,
17
)
}
public
getLeftEyeBrow
()
{
return
this
.
_faceLandmarks
.
slice
(
17
,
22
)
}
public
getRightEyeBrow
()
{
return
this
.
_faceLandmarks
.
slice
(
22
,
27
)
}
public
getNose
()
{
return
this
.
_faceLandmarks
.
slice
(
27
,
36
)
}
public
getLeftEye
()
{
return
this
.
_faceLandmarks
.
slice
(
36
,
42
)
}
public
getRightEye
()
{
return
this
.
_faceLandmarks
.
slice
(
42
,
48
)
}
public
getMouth
()
{
return
this
.
_faceLandmarks
.
slice
(
48
,
68
)
}
public
forSize
(
width
:
number
,
height
:
number
):
FaceLandmarks
{
public
forSize
(
width
:
number
,
height
:
number
):
FaceLandmarks
{
return
new
FaceLandmarks
(
this
.
getRelativePositions
(),
{
width
,
height
})
return
new
FaceLandmarks
(
this
.
getRelativePositions
(),
{
width
,
height
})
}
}
...
...
src/utils.ts
View file @
a644af17
import
{
FaceDetection
}
from
'./faceDetectionNet/FaceDetection'
;
import
{
FaceDetection
}
from
'./faceDetectionNet/FaceDetection'
;
import
{
FaceLandmarks
}
from
'./faceLandmarkNet/FaceLandmarks'
;
import
{
FaceLandmarks
}
from
'./faceLandmarkNet/FaceLandmarks'
;
import
{
Dimensions
,
DrawBoxOptions
,
DrawLandmarksOptions
,
DrawOptions
,
DrawTextOptions
}
from
'./types'
;
import
{
Dimensions
,
DrawBoxOptions
,
DrawLandmarksOptions
,
DrawOptions
,
DrawTextOptions
}
from
'./types'
;
import
{
Point
}
from
'./Point'
;
export
function
isFloat
(
num
:
number
)
{
export
function
isFloat
(
num
:
number
)
{
return
num
%
1
!==
0
return
num
%
1
!==
0
...
@@ -163,6 +164,33 @@ export function drawDetection(
...
@@ -163,6 +164,33 @@ export function drawDetection(
})
})
}
}
function
drawContour
(
ctx
:
CanvasRenderingContext2D
,
points
:
Point
[],
isClosed
:
boolean
=
false
)
{
ctx
.
beginPath
()
points
.
slice
(
1
).
forEach
(({
x
,
y
},
prevIdx
)
=>
{
const
from
=
points
[
prevIdx
]
ctx
.
moveTo
(
from
.
x
,
from
.
y
)
ctx
.
lineTo
(
x
,
y
)
})
if
(
isClosed
)
{
const
from
=
points
[
points
.
length
-
1
]
const
to
=
points
[
0
]
if
(
!
from
||
!
to
)
{
return
}
ctx
.
moveTo
(
from
.
x
,
from
.
y
)
ctx
.
lineTo
(
to
.
x
,
to
.
y
)
}
ctx
.
stroke
()
}
export
function
drawLandmarks
(
export
function
drawLandmarks
(
canvasArg
:
string
|
HTMLCanvasElement
,
canvasArg
:
string
|
HTMLCanvasElement
,
faceLandmarks
:
FaceLandmarks
,
faceLandmarks
:
FaceLandmarks
,
...
@@ -181,8 +209,23 @@ export function drawLandmarks(
...
@@ -181,8 +209,23 @@ export function drawLandmarks(
const
{
drawLines
}
=
Object
.
assign
({
drawLines
:
false
},
(
options
||
{}))
const
{
drawLines
}
=
Object
.
assign
({
drawLines
:
false
},
(
options
||
{}))
const
ctx
=
getContext2dOrThrow
(
canvas
)
const
ctx
=
getContext2dOrThrow
(
canvas
)
const
{
lineWidth
,
color
}
=
drawOptions
const
{
lineWidth
,
color
}
=
drawOptions
ctx
.
fillStyle
=
color
if
(
drawLines
)
{
ctx
.
strokeStyle
=
color
ctx
.
lineWidth
=
lineWidth
drawContour
(
ctx
,
faceLandmarks
.
getJawOutline
())
drawContour
(
ctx
,
faceLandmarks
.
getLeftEyeBrow
())
drawContour
(
ctx
,
faceLandmarks
.
getRightEyeBrow
())
drawContour
(
ctx
,
faceLandmarks
.
getNose
())
drawContour
(
ctx
,
faceLandmarks
.
getLeftEye
(),
true
)
drawContour
(
ctx
,
faceLandmarks
.
getRightEye
(),
true
)
drawContour
(
ctx
,
faceLandmarks
.
getMouth
(),
true
)
return
}
// else draw points
const
ptOffset
=
lineWidth
/
2
const
ptOffset
=
lineWidth
/
2
ctx
.
fillStyle
=
color
faceLandmarks
.
getPositions
().
forEach
(
pt
=>
ctx
.
fillRect
(
pt
.
x
-
ptOffset
,
pt
.
y
-
ptOffset
,
lineWidth
,
lineWidth
))
faceLandmarks
.
getPositions
().
forEach
(
pt
=>
ctx
.
fillRect
(
pt
.
x
-
ptOffset
,
pt
.
y
-
ptOffset
,
lineWidth
,
lineWidth
))
}
}
\ No newline at end of file
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