From 12e07f5d79f1081ffb8243c69b4afbccc5e86277 Mon Sep 17 00:00:00 2001 From: coco1986509808 <1986509808@qq.com> Date: Thu, 28 Dec 2023 15:14:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dkha/common/enums/ApiUrlEnum.java | 2 + .../dkha/common/modules/vo/CompareMuch.java | 19 ++++++ .../modules/vo/facelib/CompareRequestVo.java | 3 + .../modules/vo/search/FaceCompareVO.java | 4 +- .../server/controllers/CameraController.java | 4 ++ .../server/controllers/CompareController.java | 37 +++++++++++ .../server/controllers/FaceController.java | 3 +- .../dkha/server/controllers/IndexContral.java | 64 +++++++++++++------ .../controllers/ResourcesController.java | 24 +++++++ .../server/controllers/WarningController.java | 4 +- .../services/impl/ControlTaskServiceImpl.java | 8 ++- .../services/impl/FaceCameraServiceImpl.java | 18 +++--- 12 files changed, 155 insertions(+), 35 deletions(-) create mode 100644 face-common/src/main/java/com/dkha/common/modules/vo/CompareMuch.java diff --git a/face-common/src/main/java/com/dkha/common/enums/ApiUrlEnum.java b/face-common/src/main/java/com/dkha/common/enums/ApiUrlEnum.java index 2be6ed3..4c67e3d 100644 --- a/face-common/src/main/java/com/dkha/common/enums/ApiUrlEnum.java +++ b/face-common/src/main/java/com/dkha/common/enums/ApiUrlEnum.java @@ -20,6 +20,8 @@ public enum ApiUrlEnum { //口罩人脸识别项目所用的接口地址重新定义 FACE_SEARCH("message/mask", "人脸检测"), FACE_COMPARISON("compare", "一比一比对"), + +FACE_COMPARISON_MUCH("compares", "一比多比对"), FACELIB_POSTURL("dkha/faceLib", "添加人脸"), FACELIST_POSTURL("dkha/face", "添加人像"), FACE_POSTURL("dkha/face", "添加人像"), diff --git a/face-common/src/main/java/com/dkha/common/modules/vo/CompareMuch.java b/face-common/src/main/java/com/dkha/common/modules/vo/CompareMuch.java new file mode 100644 index 0000000..a1788c7 --- /dev/null +++ b/face-common/src/main/java/com/dkha/common/modules/vo/CompareMuch.java @@ -0,0 +1,19 @@ +package com.dkha.common.modules.vo; + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "人脸库1:N比对返回", description = "人脸检索") +public class CompareMuch { + private Double hitSimilarity; + @ApiModelProperty(value = "比对最相似的人脸地址") + private String rphoto; +} diff --git a/face-common/src/main/java/com/dkha/common/modules/vo/facelib/CompareRequestVo.java b/face-common/src/main/java/com/dkha/common/modules/vo/facelib/CompareRequestVo.java index b7d5e94..dded7d8 100644 --- a/face-common/src/main/java/com/dkha/common/modules/vo/facelib/CompareRequestVo.java +++ b/face-common/src/main/java/com/dkha/common/modules/vo/facelib/CompareRequestVo.java @@ -18,4 +18,7 @@ public class CompareRequestVo { @ApiModelProperty(value = "阀值") private Double minScore; + + @ApiModelProperty(value = "查询的库id") + private String value; } diff --git a/face-common/src/main/java/com/dkha/common/modules/vo/search/FaceCompareVO.java b/face-common/src/main/java/com/dkha/common/modules/vo/search/FaceCompareVO.java index 753b36c..eb62468 100644 --- a/face-common/src/main/java/com/dkha/common/modules/vo/search/FaceCompareVO.java +++ b/face-common/src/main/java/com/dkha/common/modules/vo/search/FaceCompareVO.java @@ -27,7 +27,7 @@ public class FaceCompareVO { private String image1; @ApiModelProperty(value = "人脸图片2") private String image2; -// @ApiModelProperty(value = "拓展字段") -// private String extraMeta; + @ApiModelProperty(value = "拓展字段") + private String extraMeta; } \ No newline at end of file diff --git a/face-server/src/main/java/com/dkha/server/controllers/CameraController.java b/face-server/src/main/java/com/dkha/server/controllers/CameraController.java index d87636d..5b47345 100644 --- a/face-server/src/main/java/com/dkha/server/controllers/CameraController.java +++ b/face-server/src/main/java/com/dkha/server/controllers/CameraController.java @@ -88,7 +88,11 @@ public class CameraController extends CommonResult { public CommonResult insert(@RequestBody @Valid InsertFaceCamera insertFaceCamera) { try { System.out.println("进入添加摄像头方法"); +// for (InsertFaceCamera insertFaceCamera1:insertFaceCamera){ +// faceCameraServiceImpl.insertCamera(insertFaceCamera1); +// } faceCameraServiceImpl.insertCamera(insertFaceCamera); + System.out.println(insertFaceCamera); } catch (DkException e) { return failResult(e.getMessage()); } catch (Exception e) { diff --git a/face-server/src/main/java/com/dkha/server/controllers/CompareController.java b/face-server/src/main/java/com/dkha/server/controllers/CompareController.java index 6fc85ae..9878cf8 100644 --- a/face-server/src/main/java/com/dkha/server/controllers/CompareController.java +++ b/face-server/src/main/java/com/dkha/server/controllers/CompareController.java @@ -1,16 +1,26 @@ package com.dkha.server.controllers; +import com.dkha.common.enums.ApiUrlEnum; import com.dkha.common.exception.DkException; +import com.dkha.common.http.HttpUtil; +import com.dkha.common.modules.vo.CompareMuch; +import com.dkha.common.modules.vo.ReturnVO; +import com.dkha.common.modules.vo.face.ApiFaceOneSearchReturnFaceVO; import com.dkha.common.modules.vo.facelib.CompareRequestVo; +import com.dkha.common.modules.vo.facelib.OneToOneResultVo; +import com.dkha.common.modules.vo.search.FaceCompareVO; import com.dkha.common.result.CommonResult; +import com.dkha.common.util.JsonUtil; import com.dkha.common.util.UtilValidate; import com.dkha.server.services.ICompareService; +import com.fasterxml.jackson.core.type.TypeReference; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -29,6 +39,10 @@ public class CompareController extends CommonResult { @Autowired private ICompareService compareService; + @Value("${api.server.prefix}") + private String apiServerPrefix; + @Autowired + private HttpUtil httpUtil; @PostMapping(value = "/grouping") @ApiOperation(value = "分组比对") @@ -47,6 +61,29 @@ public class CompareController extends CommonResult { @RequestBody CompareRequestVo compareRequestVo) { return successResult(compareService.oneToOne(compareRequestVo)); } + @PostMapping(value = "/oneToMuch") + @ApiOperation(value = "一比多比对") +// @RequiresPermissions("face:onetoone:comparison") + public CommonResult oneToMuchCompare( + @ApiParam(required = true, name = "compareRequestVo", value = "") + @RequestBody CompareRequestVo compareRequestVo) { + System.out.println("comparerequest"+compareRequestVo); + String apiUrl = apiServerPrefix + ApiUrlEnum.FACE_COMPARISON_MUCH.getUrl(); + // String apiUrltest = "http://192.168.1.196:5001/compare"; + FaceCompareVO faceCompareVO = new FaceCompareVO(); + faceCompareVO.setImage1(compareRequestVo.getUrlList().get(0)); + faceCompareVO.setExtraMeta(compareRequestVo.getValue()); + ReturnVO returnVO = (ReturnVO)httpUtil.post(apiUrl, faceCompareVO, ReturnVO.class); + CompareMuch compareMuch = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference() {}); + //返回结果集 + OneToOneResultVo oneToOneResultVo = new OneToOneResultVo(); + if (UtilValidate.isNotEmpty(compareMuch)) { + oneToOneResultVo.getUrls().add(compareMuch.getRphoto()); + oneToOneResultVo.setScore(compareMuch.getHitSimilarity()); + } + System.out.println(oneToOneResultVo); + return successResult(oneToOneResultVo); + } @PostMapping(value = "/oneToOneImage") @ApiOperation(value = "一比一比对上传 Image") //@RequiresPermissions("employment:contract:upload") diff --git a/face-server/src/main/java/com/dkha/server/controllers/FaceController.java b/face-server/src/main/java/com/dkha/server/controllers/FaceController.java index d4bbff8..91447cd 100644 --- a/face-server/src/main/java/com/dkha/server/controllers/FaceController.java +++ b/face-server/src/main/java/com/dkha/server/controllers/FaceController.java @@ -176,7 +176,7 @@ public class FaceController extends CommonResult { // compareFaceLists = oncompareFacelist; for (FaceInformation faceInformation :onfaceInformations){ // if(UtilValidate.isNotEmpty(com.getName())){ - //根据人脸名称去人像库中寻找rphoto + //根据人脸名称,实际是id——portrait去人像库中寻找rphoto QueryWrapper queryWrapper=new QueryWrapper<>(); queryWrapper.eq("id_portrait",faceInformation.getName()); Portrait rphoto = iPortraitService.getBaseMapper().selectOne(queryWrapper); @@ -226,6 +226,7 @@ public class FaceController extends CommonResult { } @GetMapping("test0509") public void getUrl(@RequestParam("url") String url) { + System.out.println(apiServerPrefix); System.out.println("获取url"+url); } diff --git a/face-server/src/main/java/com/dkha/server/controllers/IndexContral.java b/face-server/src/main/java/com/dkha/server/controllers/IndexContral.java index 72b9941..2406d53 100644 --- a/face-server/src/main/java/com/dkha/server/controllers/IndexContral.java +++ b/face-server/src/main/java/com/dkha/server/controllers/IndexContral.java @@ -10,10 +10,8 @@ import com.dkha.common.modules.vo.warning.WarningBayonetReturnVO; import com.dkha.common.result.CommonResult; import com.dkha.common.util.UtilValidate; import com.dkha.server.common.config.InitStartDateConfig; -import com.dkha.server.modules.entities.ControlLibraryMid; -import com.dkha.server.modules.entities.ControlTask; -import com.dkha.server.modules.entities.FaceLibrary; -import com.dkha.server.modules.entities.Portrait; +import com.dkha.server.mappers.FaceInformationMapper; +import com.dkha.server.modules.entities.*; import com.dkha.server.services.IControlTaskService; import com.dkha.server.services.IFaceLibraryService; import com.dkha.server.services.IPortraitService; @@ -29,6 +27,7 @@ import org.springframework.web.bind.annotation.RestController; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -56,6 +55,7 @@ public class IndexContral extends CommonResult{ @Autowired private Gson gson; + @Autowired private IFaceLibraryService iFaceLibraryService; @Autowired @@ -64,6 +64,9 @@ public class IndexContral extends CommonResult{ @Autowired private IPortraitService iPortraitService; + @Autowired + private FaceInformationMapper faceInformationMapper; + @GetMapping("/show") @ApiOperation(value = "首页展示") @@ -76,6 +79,7 @@ public class IndexContral extends CommonResult{ Long b=InitStartDateConfig.initDate.getTime(); // System.out.println("a-b的时间"+ (a-b)); Integer daysOfOperation=(int)((nowdate.getTime()-InitStartDateConfig.initDate.getTime())/(3600000*24)+1);//单位为毫秒 + daysOfOperation += 259; //人像库数量 Integer libNumber=0; //人脸数量 @@ -99,13 +103,29 @@ public class IndexContral extends CommonResult{ try { - //人脸数量 - QueryWrapper queryWrapper=new QueryWrapper<>(); - Portrait portrait=new Portrait(); - portrait.setIsValid("Y"); - queryWrapper.setEntity(portrait); - faceNumber=iPortraitService.getBaseMapper().selectCount(queryWrapper); - faceNumber = faceNumber*10; + Long numbershiwan =1681443666572L; + //要求为 1万*10+9格式的数字。。。。。。以下代码对功能没有实际作用 + //先获取各人像库的idfactor + QueryWrapper queryWrapper1 =new QueryWrapper<>(); + List id = iFaceLibraryService.getBaseMapper().selectList(queryWrapper1); + Long face_id[] =new Long[libNumber]; + for (int i = 0; i < face_id.length; i++) { + face_id[i] = id.get(i).getIdFactory(); + } + //在根据每个人像库的id进行查询 + for (Long id_p: face_id) { + QueryWrapper queryWrapper=new QueryWrapper<>(); + Portrait portrait=new Portrait(); + portrait.setIsValid("Y"); + portrait.setIdFactory(id_p); + queryWrapper.setEntity(portrait); + Integer faceNumber_intime=iPortraitService.getBaseMapper().selectCount(queryWrapper); + if(id_p.equals(numbershiwan)){ +// faceNumber_intime =faceNumber_intime*10; + faceNumber_intime = 10000*10+(faceNumber_intime-10000); + } + faceNumber =faceNumber+faceNumber_intime; + } }catch (Exception e){} try @@ -123,14 +143,18 @@ public class IndexContral extends CommonResult{ pageVO.setPageSize(1); pageVO.setPageNo(1); apiAlarmVO.setPage(pageVO); - ApiVO warningVO = (ApiVO) httpUtil.post(link + ApiUrlEnum.ALARMS_POSTURL.getUrl(), apiAlarmVO, ApiVO.class); - if (!UtilValidate.isEmpty(warningVO)) { - if (!UtilValidate.isEmpty(warningVO) && !UtilValidate.isEmpty(warningVO.getData())) { - WarningBayonetReturnVO wvo = gson.fromJson(gson.toJson(warningVO.getData()), WarningBayonetReturnVO.class); - warnNumber=wvo.getPage().getTotal(); - } - } - warnNumber = warnNumber+5000; + //查询累计抓拍总数 + + QueryWrapper queryWrapper2 = new QueryWrapper<>(); + warnNumber = faceInformationMapper.selectCount(queryWrapper2).longValue(); +// ApiVO warningVO = (ApiVO) httpUtil.post("192.168.1.196:8889/face/warning/todayBayonet", apiAlarmVO, ApiVO.class); +// if (!UtilValidate.isEmpty(warningVO)) { +// if (!UtilValidate.isEmpty(warningVO) && !UtilValidate.isEmpty(warningVO.getData())) { +// WarningBayonetReturnVO wvo = gson.fromJson(gson.toJson(warningVO.getData()), WarningBayonetReturnVO.class); +// warnNumber=wvo.getPage().getTotal(); +// } +// } +// warnNumber = warnNumber+5000; }catch (Exception e) { @@ -140,7 +164,7 @@ public class IndexContral extends CommonResult{ myMap.put("libNumber",libNumber); myMap.put("faceNumber",faceNumber); myMap.put("taskNumber",taskNumber); - myMap.put("warnNumber",warnNumber+5000); + myMap.put("warnNumber",warnNumber); //myMap.put("warnNumber",4); myMap.put("daysOfOperation",daysOfOperation); return successResult(myMap); diff --git a/face-server/src/main/java/com/dkha/server/controllers/ResourcesController.java b/face-server/src/main/java/com/dkha/server/controllers/ResourcesController.java index ea3d20e..0ec22c5 100644 --- a/face-server/src/main/java/com/dkha/server/controllers/ResourcesController.java +++ b/face-server/src/main/java/com/dkha/server/controllers/ResourcesController.java @@ -1,5 +1,6 @@ package com.dkha.server.controllers; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.dkha.common.enums.YNEnums; import com.dkha.common.exception.DkException; @@ -35,6 +36,7 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; /** * @version V1.0 @@ -142,6 +144,22 @@ public class ResourcesController extends CommonResult { "\t}\n" + "}")@RequestBody PageParam pageParam){ Page page = iFaceLibraryService.queryLibrary(pageParam); + + + //以下为了满足甲方的 1万*10+9=100009,无理要求所做,没有实际作用 + List faceLibraryList =page.getRecords(); +// QueryWrapper queryWrapper=new QueryWrapper<>(); +// FaceLibrary shiwanlibrary = iFaceLibraryService.getBaseMapper().selectById(1681443666572L); + for (int i =0;i page = iPortraitService.queryPortrait(pageParam); + System.out.println(pageParam.getNote().get("libraryId")); + if (Long.valueOf(pageParam.getNote().get("libraryId")).equals(1681443666572L)){ + Long i =page.getTotal(); + page.setTotal(100000L+ (i-10000)); +// String.valueOf((Integer.parseInt(s) - 10000)+100000) + } return successResult(page); } diff --git a/face-server/src/main/java/com/dkha/server/controllers/WarningController.java b/face-server/src/main/java/com/dkha/server/controllers/WarningController.java index f3f8d3d..d375e53 100644 --- a/face-server/src/main/java/com/dkha/server/controllers/WarningController.java +++ b/face-server/src/main/java/com/dkha/server/controllers/WarningController.java @@ -451,7 +451,7 @@ public class WarningController extends CommonResult { // e.printStackTrace(); // return failResult("查询异常:" + e.getMessage()); // } - System.out.println(apiAlarmVO); + //System.out.println(apiAlarmVO); QueryWrapper queryWrapper=new QueryWrapper<>(); if(UtilValidate.isNotEmpty(apiAlarmVO.getPage().getStartTimestamp()) &&UtilValidate.isNotEmpty(apiAlarmVO.getPage().getStopTimestamp())) { @@ -473,7 +473,7 @@ public class WarningController extends CommonResult { pages.setCurrent(apiAlarmVO.getPage().getPageNo()); pages.setSize(apiAlarmVO.getPage().getPageSize()); IPage faceInformations = faceInformationMapper.selectPage(pages,queryWrapper); - System.out.println(faceInformations.getRecords()); + //System.out.println(faceInformations.getRecords()); Integer faceInformationsNumber = 0; faceInformationsNumber = faceInformationMapper.selectCount(queryWrapper); pages.setRecords(faceInformations.getRecords()); diff --git a/face-server/src/main/java/com/dkha/server/services/impl/ControlTaskServiceImpl.java b/face-server/src/main/java/com/dkha/server/services/impl/ControlTaskServiceImpl.java index 353337f..88cf0af 100644 --- a/face-server/src/main/java/com/dkha/server/services/impl/ControlTaskServiceImpl.java +++ b/face-server/src/main/java/com/dkha/server/services/impl/ControlTaskServiceImpl.java @@ -19,6 +19,7 @@ import com.dkha.common.util.UtilValidate; import com.dkha.server.mappers.ControlLibraryMidMapper; import com.dkha.server.mappers.ControlTaskMapper; import com.dkha.server.mappers.FaceCameraDao; +import com.dkha.server.mappers.FaceLibraryMapper; import com.dkha.server.modules.entities.*; import com.dkha.server.services.*; import com.google.common.base.Joiner; @@ -52,6 +53,8 @@ public class ControlTaskServiceImpl extends ServiceImpl().eq("camera_name", insertFaceCamera.getCameraName().trim()).eq("is_valid", YNEnums.YES.code)); FaceCameraEntity ipEntity = baseMapper.selectOne(new QueryWrapper().eq("ip", insertFaceCamera.getIp().trim()).eq("is_valid", YNEnums.YES.code)); FaceCameraEntity rtspUrlEntity = baseMapper.selectOne(new QueryWrapper().eq("rtsp_url", insertFaceCamera.getRtspUrl().trim()).eq("is_valid", YNEnums.YES.code)); //版本码表关联 SysDictDataEntity brand = sysDictDataDao.selectById(insertFaceCamera.getIdBrand()); -// System.out.println( insertFaceCamera.getCameraName()); -// System.out.println( insertFaceCamera.getIp()); -// System.out.println( insertFaceCamera.getRtspUrl()); + System.out.println( insertFaceCamera.getCameraName()); + System.out.println( insertFaceCamera.getIp()); + System.out.println( insertFaceCamera.getRtspUrl()); if (UtilValidate.isEmpty(brand)) { throw new DkException("摄像头型号不能为空"); @@ -152,7 +152,7 @@ public class FaceCameraServiceImpl extends ServiceImpl