Commit 9deca17a by xmh

匹配数量优化,已完成的只显示3张

1 parent f2efc8c3
package com.viontech.label.platform.service.main; package com.viontech.label.platform.service.main;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.excel.EasyExcel;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
...@@ -11,7 +10,6 @@ import com.viontech.keliu.websocket.AlgApiClient; ...@@ -11,7 +10,6 @@ import com.viontech.keliu.websocket.AlgApiClient;
import com.viontech.label.core.constant.Constants; import com.viontech.label.core.constant.Constants;
import com.viontech.label.core.constant.LogOperateType; import com.viontech.label.core.constant.LogOperateType;
import com.viontech.label.core.constant.PicStatus; import com.viontech.label.core.constant.PicStatus;
import com.viontech.label.platform.mapper.LogMapper;
import com.viontech.label.platform.mapper.PicMapper; import com.viontech.label.platform.mapper.PicMapper;
import com.viontech.label.platform.model.*; import com.viontech.label.platform.model.*;
import com.viontech.label.platform.service.adapter.LogService; import com.viontech.label.platform.service.adapter.LogService;
...@@ -19,7 +17,6 @@ import com.viontech.label.platform.service.adapter.PackService; ...@@ -19,7 +17,6 @@ import com.viontech.label.platform.service.adapter.PackService;
import com.viontech.label.platform.service.adapter.PicService; import com.viontech.label.platform.service.adapter.PicService;
import com.viontech.label.platform.service.adapter.UserService; import com.viontech.label.platform.service.adapter.UserService;
import com.viontech.label.platform.utils.StorageUtils; import com.viontech.label.platform.utils.StorageUtils;
import com.viontech.label.platform.vo.LogVo;
import com.viontech.label.platform.vo.PicVo; import com.viontech.label.platform.vo.PicVo;
import com.viontech.label.platform.vo.ReidUploadData; import com.viontech.label.platform.vo.ReidUploadData;
import com.viontech.label.platform.websocket.ReidWebsocket; import com.viontech.label.platform.websocket.ReidWebsocket;
...@@ -34,7 +31,6 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -34,7 +31,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -341,17 +337,27 @@ public class ReidService { ...@@ -341,17 +337,27 @@ public class ReidService {
Person person = new Person().setBodyFeatures(bodyFeatures).setCounttimeGTE(countTimeGTE).setCounttimeLTE(countTimeLTE); Person person = new Person().setBodyFeatures(bodyFeatures).setCounttimeGTE(countTimeGTE).setCounttimeLTE(countTimeLTE);
try { try {
HashMap<String, Object> options = new HashMap<>(2); HashMap<String, Object> options = new HashMap<>(2);
options.put("size", size + picIdArr.length); options.put("size", size + 1);
options.put("agg", true); options.put("agg", true);
CompletableFuture<AlgResult> future = matchClient.matchPerson(2, person, reidPoolName, Collections.emptyList(), options); CompletableFuture<AlgResult> future = matchClient.matchPerson(2, person, reidPoolName, Collections.emptyList(), options);
AlgResult result = future.get(); AlgResult result = future.get();
List<Person> matchBodies = result.getMatchBodies(); List<Person> matchBodies = result.getMatchBodies();
List<String> personUnidList = matchBodies.stream().filter(x -> x.getScore() > 60F).map(Person::getPersonId).filter(x -> !personUnidSet.contains(x)).collect(Collectors.toList()); List<String> personUnidList = matchBodies.stream().filter(x -> x.getScore() > 60F).map(Person::getPersonId).filter(x -> !personUnidSet.contains(x)).collect(Collectors.toList());
if (personUnidList.size() == 0) {
return Collections.emptyMap();
}
PicExample picExample = new PicExample(); PicExample picExample = new PicExample();
picExample.createCriteria().andPersonUnidIn(personUnidList); picExample.createCriteria().andPersonUnidIn(personUnidList);
List<Pic> pics = picService.selectByExample(picExample); List<Pic> pics = picService.selectByExample(picExample);
return pics.stream().collect(Collectors.groupingBy(Pic::getPersonUnid, Collectors.toList())); Map<String, List<Pic>> collect = pics.stream().collect(Collectors.groupingBy(Pic::getPersonUnid, Collectors.toList()));
for (Map.Entry<String, List<Pic>> entry : collect.entrySet()) {
Pic pic = entry.getValue().get(0);
if (pic.getStatus() == PicStatus.FINISH_LABELING.val && entry.getValue().size() > 3) {
entry.setValue(entry.getValue().subList(0, 3));
}
}
return collect;
} catch (Exception e) { } catch (Exception e) {
log.info("", e); log.info("", e);
return null; return null;
......
package com.viontech.label.platform; package com.viontech.label.platform;
import com.google.common.collect.Lists; import com.fasterxml.jackson.databind.ObjectMapper;
import com.viontech.keliu.model.BodyFeature; import com.viontech.keliu.model.*;
import com.viontech.keliu.model.Data; import com.viontech.keliu.util.DateUtil;
import com.viontech.keliu.model.Feature; import com.viontech.keliu.websocket.AlgApiClient;
import com.viontech.keliu.model.Person; import com.viontech.label.core.constant.Constants;
import com.viontech.label.core.constant.PicStatus;
import com.viontech.label.platform.model.Pic;
import com.viontech.label.platform.model.PicExample;
import com.viontech.label.platform.service.adapter.PicService;
import com.viontech.label.platform.utils.StorageUtils; import com.viontech.label.platform.utils.StorageUtils;
import com.viontech.label.platform.vo.PicVo; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.awt.event.KeyListener; import java.io.File;
import java.util.List; import java.io.IOException;
import java.util.Optional; import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@SpringBootTest @SpringBootTest
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
...@@ -24,25 +29,101 @@ class LabelApplicationTests { ...@@ -24,25 +29,101 @@ class LabelApplicationTests {
@Resource @Resource
private StorageUtils storageUtils; private StorageUtils storageUtils;
@Resource
private PicService picService;
@Resource
private AlgApiClient matchClient;
@Resource
private ObjectMapper objectMapper;
@Test @Test
void contextLoads() throws Exception{ void contextLoads() throws Exception {
PicVo pic = storageUtils.getPic(5L);
Feature bodyFeature = storageUtils.getFeatureByPic(5L); Long[] picIdArr = new Long[]{2911L,2924L,3085L};
List<Data> datas = bodyFeature.getDatas(); Long packId = 1L;
if (datas == null || datas.size() == 0) { long size = 10L;
Integer timeInterval = 60;
List<BodyFeature> bodyFeatures = new ArrayList<>();
String reidPoolName = Constants.getReidPoolName(packId);
Set<String> personUnidSet = new HashSet<>();
Date countTimeGTE = null;
Date countTimeLTE = null;
for (Long picId : picIdArr) {
Pic pic = picService.selectByPrimaryKey(picId);
if (pic == null) {
continue;
}
String personUnid = pic.getPersonUnid();
personUnidSet.add(personUnid);
if (timeInterval != null) {
Date max = DateUtil.addMinutes(pic.getCreateTime(), timeInterval);
Date min = DateUtil.addMinutes(pic.getCreateTime(), -timeInterval);
countTimeLTE = countTimeLTE == null ? max : max.compareTo(countTimeLTE) > 0 ? max : countTimeLTE;
countTimeGTE = countTimeGTE == null ? min : min.compareTo(countTimeGTE) < 0 ? min : countTimeGTE;
}
BodyFeature feature = getBodyFeature(picId);
if (feature == null) {
continue;
}
bodyFeatures.add(feature);
}
if (bodyFeatures.size() == 0) {
System.out.println("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");
return; return;
} }
Person person = new Person().setBodyFeatures(bodyFeatures).setCounttimeGTE(countTimeGTE).setCounttimeLTE(countTimeLTE);
try {
HashMap<String, Object> options = new HashMap<>(2);
options.put("size", size + picIdArr.length);
options.put("agg", true);
CompletableFuture<AlgResult> future = matchClient.matchPerson(2, person, reidPoolName, Collections.emptyList(), options);
AlgResult result = future.get();
List<Person> matchBodies = result.getMatchBodies();
List<String> personUnidList = matchBodies.stream().filter(x -> x.getScore() > 60F).map(Person::getPersonId).filter(x -> !personUnidSet.contains(x)).collect(Collectors.toList());
if (personUnidList.size() == 0) {
System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
}
PicExample picExample = new PicExample();
picExample.createCriteria().andPersonUnidIn(personUnidList);
List<Pic> pics = picService.selectByExample(picExample);
Map<String, List<Pic>> collect = pics.stream().collect(Collectors.groupingBy(Pic::getPersonUnid, Collectors.toList()));
for (Map.Entry<String, List<Pic>> entry : collect.entrySet()) {
Pic pic = entry.getValue().get(0);
if (pic.getStatus() == PicStatus.FINISH_LABELING.val && entry.getValue().size() > 3) {
entry.setValue(entry.getValue().subList(0, 3));
}
}
System.out.println(collect);
} catch (Exception e) {
e.printStackTrace();
}
}
private BodyFeature getBodyFeature(Long picId) throws IOException {
byte[] bytes = FileUtils.readFileToByteArray(new File("C:\\Users\\vion\\Desktop\\" + picId + ".feature"));
Feature featureByPic = objectMapper.readValue(bytes, Feature.class);
Pic pic = picService.selectByPrimaryKey(picId);
List<Data> datas = featureByPic.getDatas();
if (datas == null || datas.size() == 0) {
return null;
}
Data data = datas.stream().filter(item -> "server".equals(item.getType())).findFirst().orElse(null); Data data = datas.stream().filter(item -> "server".equals(item.getType())).findFirst().orElse(null);
if (data == null) { if (data == null) {
return; return null;
} }
Double[] featureData = data.getData(); Double[] featureData = data.getData();
return new BodyFeature().setFeature(featureData).setBid(featureByPic.getFilename()).setCounttime(pic.getCreateTime());
Person person = new Person().setPersonId(pic.getUnid());
person.setBodyFeatures(Lists.newArrayList(new BodyFeature().setFeature(featureData).setPicName(pic.getName())));
System.out.println(person);
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!