zoukankan      html  css  js  c++  java
  • 学习记录3

    人脸特征进行对比的代码实现:

    将前端传入的图像经过人像特征提取后,和库中已存在的人像信息对比分析

    /*
    人脸识别
    */
    @RequestMapping(value = "/faceSearch", method = RequestMethod.POST)
    @ResponseBody
    public Result<FaceSearchResDto> faceSearch(String file, Integer groupId) throws Exception {
    byte[] decode = Base64.decode(base64Process(file));
    BufferedImage bufImage = ImageIO.read(new ByteArrayInputStream(decode));
    ImageInfo imageInfo = ImageFactory.bufferedImage2ImageInfo(bufImage);

    //人脸特征获取
    byte[] bytes = faceEngineService.extractFaceFeature(imageInfo);
    if (bytes == null) {
    return Results.newFailedResult(ErrorCodeEnum.NO_FACE_DETECTED);
    }
    //人脸比对,获取比对结果
    List<FaceUserInfo> userFaceInfoList = faceEngineService.compareFaceFeature(bytes, groupId);

    if (CollectionUtil.isNotEmpty(userFaceInfoList)) {
    FaceUserInfo faceUserInfo = userFaceInfoList.get(0);
    FaceSearchResDto faceSearchResDto = new FaceSearchResDto();
    BeanUtil.copyProperties(faceUserInfo, faceSearchResDto);
    List<ProcessInfo> processInfoList = faceEngineService.process(imageInfo);
    if (CollectionUtil.isNotEmpty(processInfoList)) {
    //人脸检测
    List<FaceInfo> faceInfoList = faceEngineService.detectFaces(imageInfo);
    int left = faceInfoList.get(0).getRect().getLeft();
    int top = faceInfoList.get(0).getRect().getTop();
    int width = faceInfoList.get(0).getRect().getRight() - left;
    int height = faceInfoList.get(0).getRect().getBottom() - top;

    Graphics2D graphics2D = bufImage.createGraphics();
    graphics2D.setColor(Color.RED);//红色
    BasicStroke stroke = new BasicStroke(5f);
    graphics2D.setStroke(stroke);
    graphics2D.drawRect(left, top, width, height);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ImageIO.write(bufImage, "jpg", outputStream);
    byte[] bytes1 = outputStream.toByteArray();
    faceSearchResDto.setImage("data:image/jpeg;base64," + Base64Utils.encodeToString(bytes1));
    faceSearchResDto.setAge(processInfoList.get(0).getAge());
    faceSearchResDto.setGender(processInfoList.get(0).getGender().equals(1) ? "女" : "男");

    }

    return Results.newSuccessResult(faceSearchResDto);
    }
    return Results.newFailedResult(ErrorCodeEnum.FACE_DOES_NOT_MATCH);
    }

  • 相关阅读:
    MFC
    AC自动机
    KMP
    Power Transmission (Hard Edition)
    Floyd
    地杰斯特算法
    二叉树
    51nod 1002 数塔取数问题【dp】
    51nod1049 最大子段和【动态规划】
    poj2385
  • 原文地址:https://www.cnblogs.com/fengjingfei/p/14916833.html
Copyright © 2011-2022 走看看