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 7b18ab5b
authored
Jun 13, 2022
by
李乾广
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[chg]比对符合条件的数量优化
1 parent
24f11a6b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
24 deletions
src/main/java/com/viontech/match/service/PersonService.java
src/main/java/com/viontech/match/service/PersonService.java
View file @
7b18ab5
...
...
@@ -108,21 +108,39 @@ public class PersonService {
long
count
=
0
;
List
<
BodyFeature
>
bodyFeatures
=
person
.
getBodyFeatures
();
if
(
CollectionUtils
.
isEmpty
(
bodyFeatures
))
{
log
.
info
(
"CountMatchPerson人体特征为空,PoolIds:[{}],count:{}"
,
poolIds
,
count
);
}
else
{
Double
[]
feature
=
bodyFeatures
.
get
(
0
).
getFeature
();
SearchSourceBuilder
builder
=
getSearchSourceBuilder
(
feature
,
person
,
1
);
ValueCountAggregationBuilder
countAggregationBuilder
=
AggregationBuilders
.
count
(
"countId"
).
field
(
"_id"
);
builder
.
aggregation
(
countAggregationBuilder
);
request
.
source
(
builder
);
log
.
debug
(
"CountMatchPerson条件{}:{}"
,
indices
,
builder
.
toString
());
Double
[]
feature
=
null
;
if
(
CollectionUtils
.
isEmpty
(
bodyFeatures
)
&&
null
==
person
.
getBodyMinScore
())
{
log
.
info
(
"CountMatchPerson人体特征为空并且最小分数为空,直接查数量,PoolIds:[{}],count:{}"
,
poolIds
,
count
);
}
else
if
(
CollectionUtils
.
isNotEmpty
(
bodyFeatures
)){
feature
=
bodyFeatures
.
get
(
0
).
getFeature
();
if
(
feature
==
null
||
feature
.
length
<
Constant
.
BODY_FEATURE_DIMS_2048
)
{
log
.
info
(
"人体特征维数小于2048,跳过比对"
);
ResponseVo
error
=
ResponseVo
.
error
(
rid
,
"人体特征维数小于2048,跳过比对"
);
error
.
setCount
(
0
);
return
error
;
}
else
if
(
feature
.
length
==
Constant
.
BODY_FEATURE_DIMS_2110
)
{
feature
=
Utils
.
transferBodyFeature
(
feature
);
}
SearchResponse
response
=
client
.
search
(
request
,
RequestOptions
.
DEFAULT
);
ParsedValueCount
countId
=
response
.
getAggregations
().
get
(
"countId"
);
count
=
countId
.
getValue
();
if
(
feature
.
length
>
Constant
.
BODY_FEATURE_DIMS_2048
)
{
feature
=
Arrays
.
copyOfRange
(
feature
,
3
,
Constant
.
BODY_FEATURE_DIMS_2048
+
3
);
}
}
else
{
log
.
info
(
"参数错误"
);
ResponseVo
error
=
ResponseVo
.
error
(
rid
,
"参数错误"
);
error
.
setCount
(
0
);
return
error
;
}
SearchSourceBuilder
builder
=
getSearchSourceBuilder
(
feature
,
person
,
1
);
builder
.
size
(
0
);
ValueCountAggregationBuilder
countAggregationBuilder
=
AggregationBuilders
.
count
(
"countId"
).
field
(
"_id"
);
builder
.
aggregation
(
countAggregationBuilder
);
request
.
source
(
builder
);
log
.
debug
(
"CountMatchPerson条件{}:{}"
,
indices
,
builder
.
toString
());
SearchResponse
response
=
client
.
search
(
request
,
RequestOptions
.
DEFAULT
);
ParsedValueCount
countId
=
response
.
getAggregations
().
get
(
"countId"
);
count
=
countId
.
getValue
();
ResponseVo
result
=
ResponseVo
.
success
(
rid
,
"success"
);
result
.
setCount
(
count
);
...
...
@@ -407,14 +425,14 @@ public class PersonService {
* @return
*/
private
SearchSourceBuilder
getSearchSourceBuilder
(
Double
[]
feature
,
Person
person
,
int
type
)
{
Script
script
;
Script
script
=
null
;
BoolQueryBuilder
boolQuery
=
QueryBuilders
.
boolQuery
();
if
(
type
==
0
)
{
if
(
null
!=
feature
&&
type
==
0
)
{
script
=
new
Script
(
ScriptType
.
INLINE
,
Script
.
DEFAULT_SCRIPT_LANG
,
"(cosineSimilarity(params.face, 'data') + 1) / 2 * 100"
,
Collections
.
singletonMap
(
"face"
,
feature
));
boolQuery
.
filter
(
QueryBuilders
.
existsQuery
(
"data"
));
}
else
{
}
else
if
(
null
!=
feature
&&
type
==
1
)
{
script
=
new
Script
(
ScriptType
.
INLINE
,
Script
.
DEFAULT_SCRIPT_LANG
,
"(cosineSimilarity(params.body, 'body') + 1) / 2 * 100"
,
Collections
.
singletonMap
(
"body"
,
feature
));
...
...
@@ -455,14 +473,18 @@ public class PersonService {
if
(
counttimeGTE
!=
null
||
counttimeLTE
!=
null
)
{
boolQuery
.
filter
(
rangeQueryBuilder
);
}
ScriptScoreQueryBuilder
queryBuilder
=
QueryBuilders
.
scriptScoreQuery
(
boolQuery
,
script
);
SearchSourceBuilder
builder
=
new
SearchSourceBuilder
().
query
(
queryBuilder
);
//控制最小分数
if
(
0
==
type
&&
null
!=
person
.
getFaceMinScore
())
{
builder
.
minScore
(
person
.
getFaceMinScore
());
}
else
if
(
1
==
type
&&
null
!=
person
.
getBodyMinScore
())
{
builder
.
minScore
(
person
.
getBodyMinScore
());
SearchSourceBuilder
builder
;
if
(
null
==
script
)
{
builder
=
new
SearchSourceBuilder
().
query
(
boolQuery
);
}
else
{
ScriptScoreQueryBuilder
queryBuilder
=
QueryBuilders
.
scriptScoreQuery
(
boolQuery
,
script
);
builder
=
new
SearchSourceBuilder
().
query
(
queryBuilder
);
//控制最小分数,只有特征比对时才有分数
if
(
0
==
type
&&
null
!=
person
.
getFaceMinScore
())
{
builder
.
minScore
(
person
.
getFaceMinScore
());
}
else
if
(
1
==
type
&&
null
!=
person
.
getBodyMinScore
())
{
builder
.
minScore
(
person
.
getBodyMinScore
());
}
}
return
builder
;
}
...
...
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