Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
谢明辉
/
VVAS-Match
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit e3e2a55d
authored
Dec 04, 2020
by
xmh
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1.0.0
1 parent
d0cf0291
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
15 deletions
src/main/java/com/viontech/match/service/PersonService.java
src/main/java/com/viontech/match/service/PoolService.java
src/main/java/com/viontech/match/service/PersonService.java
View file @
e3e2a55
...
...
@@ -135,7 +135,7 @@ public class PersonService {
continue
;
}
if
(
feature
.
length
>
Constant
.
BODY_FEATURE_DIMS
)
{
feature
=
Arrays
.
copyOf
(
feature
,
Constant
.
BODY_FEATURE_DIMS
);
feature
=
Arrays
.
copyOf
Range
(
feature
,
3
,
Constant
.
BODY_FEATURE_DIMS
+
3
);
}
String
fid
=
bodyFeature
.
getBid
();
...
...
@@ -181,17 +181,20 @@ public class PersonService {
private
void
matchFace
(
List
<
FaceFeature
>
faceFeatures
,
String
poolId
,
List
<
Person
>
matchResult
)
throws
IOException
{
if
(
faceFeatures
!=
null
&&
faceFeatures
.
size
()
>
0
)
{
for
(
FaceFeature
faceFeature
:
faceFeatures
)
{
Double
[]
feature
=
faceFeature
.
getFeature
();
if
(
feature
==
null
||
feature
.
length
!=
Constant
.
FACE_FEATURE_DIMS
)
{
log
.
info
(
"人脸特征维数小于512,跳过比对"
);
continue
;
}
Script
script
=
new
Script
(
ScriptType
.
INLINE
,
Script
.
DEFAULT_SCRIPT_LANG
,
"(cosineSimilarity(params.face, 'data') + 1) / 2 * 100"
,
Collections
.
singletonMap
(
"face"
,
feature
));
ScriptScoreQueryBuilder
queryBuilder
=
QueryBuilders
.
scriptScoreQuery
(
QueryBuilders
.
existsQuery
(
"data"
),
script
);
matchResult
.
addAll
(
match0
(
poolId
,
script
));
matchResult
.
addAll
(
match0
(
poolId
,
queryBuilder
));
}
}
else
{
log
.
info
(
"no face feature"
);
...
...
@@ -203,30 +206,29 @@ public class PersonService {
for
(
BodyFeature
faceFeature
:
bodyFeatures
)
{
Double
[]
feature
=
faceFeature
.
getFeature
();
if
(
feature
==
null
||
feature
.
length
<
Constant
.
BODY_FEATURE_DIMS
)
{
log
.
info
(
"人体特征维数小于2048,跳过比对"
);
continue
;
}
if
(
feature
.
length
>
Constant
.
BODY_FEATURE_DIMS
)
{
feature
=
Arrays
.
copyOf
(
feature
,
Constant
.
BODY_FEATURE_DIMS
);
feature
=
Arrays
.
copyOf
Range
(
feature
,
3
,
Constant
.
BODY_FEATURE_DIMS
+
3
);
}
Script
script
=
new
Script
(
ScriptType
.
INLINE
,
Script
.
DEFAULT_SCRIPT_LANG
,
"(cosineSimilarity(params.body, 'body') + 1) / 2 * 100"
,
Collections
.
singletonMap
(
"body"
,
feature
));
ScriptScoreQueryBuilder
queryBuilder
=
QueryBuilders
.
scriptScoreQuery
(
QueryBuilders
.
existsQuery
(
"body"
),
script
);
matchResult
.
addAll
(
match0
(
poolId
,
script
));
matchResult
.
addAll
(
match0
(
poolId
,
queryBuilder
));
}
}
else
{
log
.
info
(
"no body feature"
);
}
}
private
List
<
Person
>
match0
(
String
poolId
,
Script
script
)
throws
IOException
{
private
List
<
Person
>
match0
(
String
poolId
,
Script
ScoreQueryBuilder
scriptScoreQueryBuilder
)
throws
IOException
{
List
<
Person
>
persons
=
new
ArrayList
<>();
ScriptScoreQueryBuilder
queryBuilder
=
QueryBuilders
.
scriptScoreQuery
(
QueryBuilders
.
matchAllQuery
(),
script
);
SearchSourceBuilder
builder
=
new
SearchSourceBuilder
()
.
size
(
Constant
.
MATCH_RESULT_SIZE
)
.
query
(
q
ueryBuilder
)
.
query
(
scriptScoreQ
ueryBuilder
)
.
fetchSource
(
new
String
[]{
"personId"
,
"age"
,
"gender"
,
"fid"
},
null
);
SearchRequest
searchRequest
=
new
SearchRequest
(
poolId
)
.
source
(
builder
);
...
...
src/main/java/com/viontech/match/service/PoolService.java
View file @
e3e2a55
...
...
@@ -52,7 +52,7 @@ public class PoolService {
log
.
info
(
"特征池创建操作开始:[{}}"
,
poolId
);
try
{
CreateIndexRequest
createIndexRequest
=
new
CreateIndexRequest
(
poolId
);
XContentBuilder
builder
=
getCreateIndex
X
ContentBuilder
();
XContentBuilder
builder
=
getCreateIndexContentBuilder
();
createIndexRequest
.
mapping
(
builder
);
CreateIndexResponse
createIndexResponse
=
client
.
indices
().
create
(
createIndexRequest
,
RequestOptions
.
DEFAULT
);
...
...
@@ -100,7 +100,7 @@ public class PoolService {
return
ResponseVo
.
success
(
rid
);
}
catch
(
ElasticsearchStatusException
e
)
{
if
(
e
.
status
()
==
RestStatus
.
NOT_FOUND
)
{
return
ResponseVo
.
error
(
rid
,
4
,
"po
llID not exist
"
);
return
ResponseVo
.
error
(
rid
,
4
,
"po
olId not exists
"
);
}
else
{
return
ResponseVo
.
error
(
rid
,
e
.
getDetailedMessage
());
}
...
...
@@ -116,6 +116,9 @@ public class PoolService {
List
<
Person
>
personPool
=
requestVo
.
getPersonPool
();
Integer
updateType
=
requestVo
.
getUpdateType
();
log
.
info
(
"特征池修改操作开始:[{}],updateType:[{}]"
,
poolId
,
updateType
);
if
(!
client
.
indices
().
exists
(
new
GetIndexRequest
(
poolId
),
RequestOptions
.
DEFAULT
))
{
return
ResponseVo
.
error
(
rid
,
4
,
"poolId not exists"
);
}
try
{
BulkResponse
bulkItemResponses
=
personService
.
addPerson
(
poolId
,
personPool
);
if
(
bulkItemResponses
!=
null
&&
bulkItemResponses
.
hasFailures
())
{
...
...
@@ -165,32 +168,33 @@ public class PoolService {
}
public
XContentBuilder
getCreateIndex
X
ContentBuilder
()
throws
IOException
{
public
XContentBuilder
getCreateIndexContentBuilder
()
throws
IOException
{
XContentBuilder
builder
=
XContentFactory
.
jsonBuilder
();
builder
.
startObject
();
{
builder
.
startObject
(
"properties"
);
{
// 人脸特征
builder
.
startObject
(
"data"
);
{
builder
.
field
(
"type"
,
"dense_vector"
);
builder
.
field
(
"dims"
,
Constant
.
FACE_FEATURE_DIMS
);
}
builder
.
endObject
();
// 人体特征
builder
.
startObject
(
"body"
);
{
builder
.
field
(
"type"
,
"dense_vector"
);
builder
.
field
(
"dims"
,
Constant
.
BODY_FEATURE_DIMS
);
}
builder
.
endObject
();
// 人员id
builder
.
startObject
(
"personId"
);
{
builder
.
field
(
"type"
,
"keyword"
);
}
builder
.
endObject
();
// 特征id
builder
.
startObject
(
"fid"
);
{
builder
.
field
(
"type"
,
"text"
);
...
...
@@ -200,12 +204,16 @@ public class PoolService {
builder
.
startObject
(
"age"
);
{
builder
.
field
(
"type"
,
"integer"
);
builder
.
field
(
"doc_values"
,
false
);
builder
.
field
(
"index"
,
false
);
}
builder
.
endObject
();
builder
.
startObject
(
"gender"
);
{
builder
.
field
(
"type"
,
"keyword"
);
builder
.
field
(
"doc_values"
,
false
);
builder
.
field
(
"index"
,
false
);
}
builder
.
endObject
();
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment