Esempio n. 1
0
        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();
                }
            }
        }
Esempio n. 2
0
        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();
                    }
                }
            }
        }