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
f7e839a5
Commit
f7e839a5
authored
Aug 28, 2019
by
Jonathan Derrough
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added FaceMatcher.toJSON() & FaceMatcher.fromJSON(), with unit tests
parent
514c0ec2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
FaceMatcher.ts
src/globalApi/FaceMatcher.ts
+16
-0
FaceMatcher.test.ts
test/tests/globalApi/FaceMatcher.test.ts
+60
-0
No files found.
src/globalApi/FaceMatcher.ts
View file @
f7e839a5
...
@@ -67,4 +67,19 @@ export class FaceMatcher {
...
@@ -67,4 +67,19 @@ export class FaceMatcher {
:
new
FaceMatch
(
'unknown'
,
bestMatch
.
distance
)
:
new
FaceMatch
(
'unknown'
,
bestMatch
.
distance
)
}
}
public
static
toJSON
(
matcher
:
FaceMatcher
,
pretty
=
false
):
string
{
return
JSON
.
stringify
(
matcher
,
null
,
pretty
?
2
:
undefined
);
}
public
static
fromJSON
(
jsonString
:
string
):
FaceMatcher
{
const
poco
:
any
=
JSON
.
parse
(
jsonString
);
const
labeledDescriptors
=
poco
.
_labeledDescriptors
.
map
(({
_label
,
_descriptors
}:
{
_label
:
string
,
_descriptors
:
any
})
=>
{
return
new
LabeledFaceDescriptors
(
_label
,
_descriptors
.
map
((
d
:
any
)
=>
{
return
new
Float32Array
(
Object
.
values
(
d
));
}));
});
return
new
FaceMatcher
(
labeledDescriptors
,
poco
.
_distanceThreshold
);
}
}
}
\ No newline at end of file
test/tests/globalApi/FaceMatcher.test.ts
0 → 100644
View file @
f7e839a5
import
{
FaceMatcher
}
from
'../../../src/globalApi/FaceMatcher'
;
import
{
LabeledFaceDescriptors
}
from
'../../../src'
;
describe
(
'globalApi'
,
()
=>
{
describe
(
'FaceMatcher'
,
()
=>
{
const
json
=
'{"_distanceThreshold":123.321,"_labeledDescriptors":[{"_label":"foo","_descriptors":[{"0":1,"1":2,"2":3},{"0":4,"1":5,"2":6}]},{"_label":"bar","_descriptors":[{"0":7,"1":8,"2":9},{"0":3,"1":2,"2":1}]}]}'
;
const
dt
=
123.321
;
const
l1
=
'foo'
;
const
l2
=
'bar'
;
const
f1
=
new
Float32Array
([
1
,
2
,
3
]);
const
f2
=
new
Float32Array
([
4
,
5
,
6
]);
const
f3
=
new
Float32Array
([
7
,
8
,
9
]);
const
f4
=
new
Float32Array
([
3
,
2
,
1
]);
const
lds
=
[
new
LabeledFaceDescriptors
(
l1
,
[
f1
,
f2
]),
new
LabeledFaceDescriptors
(
l2
,
[
f3
,
f4
])
];
it
(
'toJSON()'
,
()
=>
{
const
fm
=
new
FaceMatcher
(
lds
,
dt
);
expect
(
FaceMatcher
.
toJSON
(
fm
)).
toBe
(
json
);
});
it
(
'fromJSON()'
,
()
=>
{
const
fm
=
FaceMatcher
.
fromJSON
(
json
);
expect
(
fm
.
distanceThreshold
).
toBe
(
dt
);
expect
(
fm
.
labeledDescriptors
.
length
).
toBe
(
2
);
expect
(
fm
.
labeledDescriptors
[
0
].
label
).
toBe
(
l1
);
expect
(
fm
.
labeledDescriptors
[
0
].
descriptors
.
length
).
toBe
(
2
);
expect
(
fm
.
labeledDescriptors
[
0
].
descriptors
[
0
]).
toEqual
(
f1
);
expect
(
fm
.
labeledDescriptors
[
0
].
descriptors
[
1
]).
toEqual
(
f2
);
expect
(
fm
.
labeledDescriptors
[
1
].
label
).
toBe
(
l2
);
expect
(
fm
.
labeledDescriptors
[
1
].
descriptors
.
length
).
toBe
(
2
);
expect
(
fm
.
labeledDescriptors
[
1
].
descriptors
[
0
]).
toEqual
(
f3
);
expect
(
fm
.
labeledDescriptors
[
1
].
descriptors
[
1
]).
toEqual
(
f4
);
});
it
(
'toJSON() => fromJSON()'
,
()
=>
{
const
fm
=
FaceMatcher
.
fromJSON
(
FaceMatcher
.
toJSON
(
new
FaceMatcher
(
lds
,
dt
)));
expect
(
fm
.
distanceThreshold
).
toBe
(
dt
);
expect
(
fm
.
labeledDescriptors
.
length
).
toBe
(
2
);
expect
(
fm
.
labeledDescriptors
[
0
].
label
).
toBe
(
l1
);
expect
(
fm
.
labeledDescriptors
[
0
].
descriptors
.
length
).
toBe
(
2
);
expect
(
fm
.
labeledDescriptors
[
0
].
descriptors
[
0
]).
toEqual
(
f1
);
expect
(
fm
.
labeledDescriptors
[
0
].
descriptors
[
1
]).
toEqual
(
f2
);
expect
(
fm
.
labeledDescriptors
[
1
].
label
).
toBe
(
l2
);
expect
(
fm
.
labeledDescriptors
[
1
].
descriptors
.
length
).
toBe
(
2
);
expect
(
fm
.
labeledDescriptors
[
1
].
descriptors
[
0
]).
toEqual
(
f3
);
expect
(
fm
.
labeledDescriptors
[
1
].
descriptors
[
1
]).
toEqual
(
f4
);
});
});
});
\ 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