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
6c25e874
Commit
6c25e874
authored
Jun 09, 2018
by
vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove unused stuff
parent
83d51e42
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
100 deletions
+30
-100
NetInput.ts
src/NetInput.ts
+2
-2
types.ts
src/types.ts
+19
-0
utils.ts
src/utils.ts
+9
-98
No files found.
src/NetInput.ts
View file @
6c25e874
import
{
TMediaElement
,
TNetInput
}
from
'./types'
;
import
{
Dimensions
,
TMediaElement
,
TNetInput
}
from
'./types'
;
import
{
Dimensions
,
getContext2dOrThrow
,
getElement
,
getMediaDimensions
}
from
'./utils'
;
import
{
getContext2dOrThrow
,
getElement
,
getMediaDimensions
}
from
'./utils'
;
export
class
NetInput
{
export
class
NetInput
{
private
_canvases
:
HTMLCanvasElement
[]
private
_canvases
:
HTMLCanvasElement
[]
...
...
src/types.ts
View file @
6c25e874
export
type
TMediaElement
=
HTMLImageElement
|
HTMLVideoElement
|
HTMLCanvasElement
export
type
TMediaElement
=
HTMLImageElement
|
HTMLVideoElement
|
HTMLCanvasElement
export
type
TNetInputArg
=
string
|
TMediaElement
export
type
TNetInputArg
=
string
|
TMediaElement
export
type
TNetInput
=
TNetInputArg
|
Array
<
TNetInputArg
>
export
type
TNetInput
=
TNetInputArg
|
Array
<
TNetInputArg
>
export
type
Dimensions
=
{
width
:
number
height
:
number
}
export
type
DrawBoxOptions
=
{
lineWidth
:
number
color
:
string
}
export
type
DrawTextOptions
=
{
fontSize
:
number
fontStyle
:
string
color
:
string
}
\ No newline at end of file
src/utils.ts
View file @
6c25e874
import
{
FaceDetectionNet
}
from
'./faceDetectionNet/types'
;
import
{
FaceDetectionNet
}
from
'./faceDetectionNet/types'
;
import
{
DrawBoxOptions
,
DrawTextOptions
}
from
'./types'
;
export
function
isFloat
(
num
:
number
)
{
return
num
%
1
!==
0
}
export
function
round
(
num
:
number
)
{
return
Math
.
floor
(
num
*
100
)
/
100
}
export
function
getElement
(
arg
:
string
|
any
)
{
export
function
getElement
(
arg
:
string
|
any
)
{
if
(
typeof
arg
===
'string'
)
{
if
(
typeof
arg
===
'string'
)
{
...
@@ -22,93 +31,6 @@ export function getMediaDimensions(media: HTMLImageElement | HTMLVideoElement) {
...
@@ -22,93 +31,6 @@ export function getMediaDimensions(media: HTMLImageElement | HTMLVideoElement) {
return
media
return
media
}
}
export
function
isFloat
(
num
:
number
)
{
return
num
%
1
!==
0
}
export
function
round
(
num
:
number
)
{
return
Math
.
floor
(
num
*
100
)
/
100
}
export
type
Dimensions
=
{
width
:
number
height
:
number
}
export
function
toNetInput
(
canvasArg
:
string
|
HTMLCanvasElement
,
mediaArg
:
string
|
HTMLImageElement
|
HTMLVideoElement
,
dims
?:
Dimensions
):
HTMLCanvasElement
{
const
canvas
=
getElement
(
canvasArg
)
const
media
=
getElement
(
mediaArg
)
if
(
!
(
canvas
instanceof
HTMLCanvasElement
))
{
throw
new
Error
(
'drawMediaToCanvas - expected canvas to be of type: HTMLCanvasElement'
)
}
if
(
!
(
media
instanceof
HTMLImageElement
||
media
instanceof
HTMLVideoElement
))
{
throw
new
Error
(
'drawMediaToCanvas - expected media to be of type: HTMLImageElement | HTMLVideoElement'
)
}
const
{
width
,
height
}
=
dims
||
getMediaDimensions
(
media
)
canvas
.
width
=
width
canvas
.
height
=
height
const
ctx
=
getContext2dOrThrow
(
canvas
)
ctx
.
drawImage
(
media
,
0
,
0
,
width
,
height
)
return
canvas
}
export
function
mediaToImageData
(
media
:
HTMLImageElement
|
HTMLVideoElement
,
dims
?:
Dimensions
):
ImageData
{
if
(
!
(
media
instanceof
HTMLImageElement
||
media
instanceof
HTMLVideoElement
))
{
throw
new
Error
(
'mediaToImageData - expected media to be of type: HTMLImageElement | HTMLVideoElement'
)
}
const
canvas
=
toNetInput
(
document
.
createElement
(
'canvas'
),
media
)
const
ctx
=
getContext2dOrThrow
(
canvas
)
const
{
width
,
height
}
=
dims
||
getMediaDimensions
(
media
)
return
ctx
.
getImageData
(
0
,
0
,
width
,
height
)
}
export
function
mediaSrcToImageData
(
src
:
string
|
HTMLImageElement
|
HTMLVideoElement
):
Promise
<
ImageData
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
typeof
src
!==
'string'
)
{
if
(
!
(
src
instanceof
HTMLImageElement
||
src
instanceof
HTMLVideoElement
))
{
return
reject
(
'mediaSrcToImageData - expected src to be of type: string | HTMLImageElement | HTMLVideoElement'
)
}
return
resolve
(
mediaToImageData
(
src
))
}
const
img
=
new
Image
()
img
.
onload
=
()
=>
resolve
(
mediaToImageData
(
img
))
img
.
onerror
=
reject
img
.
src
=
src
})
}
export
function
bufferToImgSrc
(
buf
:
Blob
):
Promise
<
string
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
(
buf
instanceof
Blob
))
{
return
reject
(
'bufferToImgSrc - expected buf to be of type: Blob'
)
}
const
reader
=
new
FileReader
()
reader
.
onload
=
()
=>
resolve
(
reader
.
result
)
reader
.
onerror
=
reject
reader
.
readAsDataURL
(
buf
)
})
}
export
async
function
bufferToImageData
(
buf
:
Blob
):
Promise
<
ImageData
>
{
if
(
!
(
buf
instanceof
Blob
))
{
throw
new
Error
(
'bufferToImageData - expected buf to be of type: Blob'
)
}
return
mediaSrcToImageData
(
await
bufferToImgSrc
(
buf
))
}
export
function
bufferToImage
(
buf
:
Blob
):
Promise
<
HTMLImageElement
>
{
export
function
bufferToImage
(
buf
:
Blob
):
Promise
<
HTMLImageElement
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
(
buf
instanceof
Blob
))
{
if
(
!
(
buf
instanceof
Blob
))
{
...
@@ -127,11 +49,6 @@ export function bufferToImage(buf: Blob): Promise<HTMLImageElement> {
...
@@ -127,11 +49,6 @@ export function bufferToImage(buf: Blob): Promise<HTMLImageElement> {
})
})
}
}
export
type
DrawBoxOptions
=
{
lineWidth
:
number
color
:
string
}
export
function
drawBox
(
export
function
drawBox
(
ctx
:
CanvasRenderingContext2D
,
ctx
:
CanvasRenderingContext2D
,
x
:
number
,
x
:
number
,
...
@@ -145,12 +62,6 @@ export function drawBox(
...
@@ -145,12 +62,6 @@ export function drawBox(
ctx
.
strokeRect
(
x
,
y
,
w
,
h
)
ctx
.
strokeRect
(
x
,
y
,
w
,
h
)
}
}
export
type
DrawTextOptions
=
{
fontSize
:
number
fontStyle
:
string
color
:
string
}
export
function
drawText
(
export
function
drawText
(
ctx
:
CanvasRenderingContext2D
,
ctx
:
CanvasRenderingContext2D
,
x
:
number
,
x
:
number
,
...
...
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