private void saveFace(FaceInfo faceInfo, ImageFrame imageFrame) { Bitmap bitmap = FaceCropper.getFace(imageFrame.getArgb(), faceInfo, imageFrame.getWidth()); if (source == RegActivity.SOURCE_REG) { // 注册来源保存到注册人脸目录 File faceDir = FileUitls.getFaceDirectory(); if (faceDir != null) { String imageName = Guid.NewGuid().ToString(); File file = new File(faceDir, imageName); // 压缩人脸图片至300 * 300,减少网络传输时间 ImageUtils.resize(bitmap, file, 300, 300); Intent intent = new Intent(); intent.PutExtra("file_path", file.AbsolutePath); SetResult(Result.Ok, intent); Finish(); } else { toast("注册人脸目录未找到"); } } else { try { // 其他来源保存到临时目录 File file = File.CreateTempFile(Guid.NewGuid().ToString() + "", ".jpg"); // 人脸识别不需要整张图片。可以对人脸区别进行裁剪。减少流量消耗和,网络传输占用的时间消耗。 ImageUtils.resize(bitmap, file, 300, 300); Intent intent = new Intent(); intent.PutExtra("file_path", file.AbsolutePath); SetResult(Result.Ok, intent); Finish(); } catch (IOException e) { e.PrintStackTrace(); } } }
public void run() { if (score < 80) { scoreTv.setText(""); matchUserTv.setText(""); matchAvatorIv.setImageBitmap(null); return; } if (userIdOfMaxScore.equals(userId)) { if (score < maxScore) { scoreTv.setText("" + score); } else { maxScore = score; userOfMaxSocre.setText("userId:" + userId + "\nscore:" + score); scoreTv.setText(String.valueOf(maxScore)); } if (matchUserTv.getText().toString().length() > 0) { return; } } else { userIdOfMaxScore = userId; maxScore = score; } scoreTv.setText(String.valueOf(maxScore)); User user = FaceApi.getInstance().getUserInfo(groupId, userId); if (user == null) { return; } matchUserTv.setText(user.getUserInfo()); List <Feature> featureList = user.getFeatureList(); if (featureList != null && featureList.size() > 0) { // featureTv.setText(new String(featureList.get(0).getFeature())); File faceDir = FileUitls.getFaceDirectory(); if (faceDir != null && faceDir.exists()) { File file = new File(faceDir, featureList.get(0).getImageName()); if (file != null && file.exists()) { Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); matchAvatorIv.setImageBitmap(bitmap); } } } // List<Feature> featureList = DBManager.getInstance().queryFeatureByUeserId(userId); // if (featureList != null && featureList.size() > 0) { // File faceDir = FileUitls.getFaceDirectory(); // if (faceDir != null && faceDir.exists()) { // File file = new File(faceDir, featureList.get(0).getImageName()); // if (file != null && file.exists()) { // Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); // testView.setImageBitmap(bitmap); // } // } // } }
private void checkResult(LivenessModel model) { if (model == null) { return; } displayResult(model); int type = model.getLiveType(); bool livenessSuccess = false; // 同一时刻都通过才认为活体通过,开发者也可以根据自己的需求修改策略 if ((type & FaceLiveness.MASK_RGB) == FaceLiveness.MASK_RGB) { livenessSuccess = (model.getRgbLivenessScore() > FaceEnvironment.LIVENESS_RGB_THRESHOLD) ? true : false; } if ((type & FaceLiveness.MASK_IR) == FaceLiveness.MASK_IR) { bool irScore = (model.getIrLivenessScore() > FaceEnvironment.LIVENESS_IR_THRESHOLD) ? true : false; if (!irScore) { livenessSuccess = false; } else { livenessSuccess &= irScore; } } if ((type & FaceLiveness.MASK_DEPTH) == FaceLiveness.MASK_DEPTH) { bool depthScore = (model.getDepthLivenessScore() > FaceEnvironment.LIVENESS_DEPTH_THRESHOLD) ? true : false; if (!depthScore) { livenessSuccess = false; } else { livenessSuccess &= depthScore; } } if (livenessSuccess) { Bitmap bitmap = FaceCropper.getFace(model.getImageFrame().getArgb(), model.getFaceInfo(), model.getImageFrame().getWidth()); if (source == RegActivity.SOURCE_REG) { // 注册来源保存到注册人脸目录 File faceDir = FileUitls.getFaceDirectory(); if (faceDir != null) { string imageName = System.Guid.NewGuid().ToString(); File file = new File(faceDir, imageName); // 压缩人脸图片至300 * 300,减少网络传输时间 ImageUtils.resize(bitmap, file, 300, 300); Intent intent = new Intent(); intent.PutExtra("file_path", file.AbsolutePath); SetResult(Result.Ok, intent); success = true; Finish(); } else { toast("注册人脸目录未找到"); } } else { try { // 其他来源保存到临时目录 File file = File.CreateTempFile(System.Guid.NewGuid().ToString() + "", ".jpg"); ImageUtils.resize(bitmap, file, 300, 300); Intent intent = new Intent(); intent.PutExtra("file_path", file.AbsolutePath); SetResult(Result.Ok, intent); success = true; Finish(); } catch (IOException e) { e.PrintStackTrace(); } } } }