Commit 9deca17a by xmh

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

1 parent f2efc8c3
package com.viontech.label.platform.service.main;
import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.excel.EasyExcel;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
......@@ -11,7 +10,6 @@ import com.viontech.keliu.websocket.AlgApiClient;
import com.viontech.label.core.constant.Constants;
import com.viontech.label.core.constant.LogOperateType;
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.model.*;
import com.viontech.label.platform.service.adapter.LogService;
......@@ -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.UserService;
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.ReidUploadData;
import com.viontech.label.platform.websocket.ReidWebsocket;
......@@ -34,7 +31,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
......@@ -341,17 +337,27 @@ public class ReidService {
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("size", size + 1);
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) {
return Collections.emptyMap();
}
PicExample picExample = new PicExample();
picExample.createCriteria().andPersonUnidIn(personUnidList);
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) {
log.info("", e);
return null;
......
package com.viontech.label.platform;
import com.google.common.collect.Lists;
import com.viontech.keliu.model.BodyFeature;
import com.viontech.keliu.model.Data;
import com.viontech.keliu.model.Feature;
import com.viontech.keliu.model.Person;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.viontech.keliu.model.*;
import com.viontech.keliu.util.DateUtil;
import com.viontech.keliu.websocket.AlgApiClient;
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.vo.PicVo;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.awt.event.KeyListener;
import java.util.List;
import java.util.Optional;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@SpringBootTest
@RunWith(SpringRunner.class)
......@@ -24,25 +29,101 @@ class LabelApplicationTests {
@Resource
private StorageUtils storageUtils;
@Resource
private PicService picService;
@Resource
private AlgApiClient matchClient;
@Resource
private ObjectMapper objectMapper;
@Test
void contextLoads() throws Exception{
PicVo pic = storageUtils.getPic(5L);
Feature bodyFeature = storageUtils.getFeatureByPic(5L);
List<Data> datas = bodyFeature.getDatas();
if (datas == null || datas.size() == 0) {
void contextLoads() throws Exception {
Long[] picIdArr = new Long[]{2911L,2924L,3085L};
Long packId = 1L;
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;
}
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);
if (data == null) {
return;
return null;
}
Double[] featureData = data.getData();
Person person = new Person().setPersonId(pic.getUnid());
person.setBodyFeatures(Lists.newArrayList(new BodyFeature().setFeature(featureData).setPicName(pic.getName())));
System.out.println(person);
return new BodyFeature().setFeature(featureData).setBid(featureByPic.getFilename()).setCounttime(pic.getCreateTime());
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!