FacePass使用recognize完成1:1比对功能

qujiaqi发表于:2019年03月27日 10:58:38更新于:2019年06月03日 17:05:26

FacePass使用recognize完成1:1

new Thread(new Runnable() {
    @Override
    public void run() {
        String root = Environment.getExternalStorageDirectory().getAbsolutePath() + "/3.7/";
        File fileRoot = new File(root);
        for (File f : fileRoot.listFiles()) {
            if (!f.isDirectory()) {
                continue;
            }
            android.util.Log.d("qujiaqi", "file:" + f.getAbsolutePath());
            final Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath() + "/a.jpeg");
            final Bitmap bitmap1 = BitmapFactory.decodeFile(f.getAbsolutePath() + "/b.jpeg");
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mDebugImage.setImageBitmap(bitmap);
                    mDebug2Image.setImageBitmap(bitmap1);
                }
            });
            FacePassHandler handler = mFacePassManager.getFacePassHandler();
            try {
                FacePassConfig config = handler.getAddFaceConfig();
                config.blurThreshold = 0.5f;
                config.faceMinThreshold = 50;
                handler.setAddFaceConfig(config);
                FacePassAddFaceResult addFaceResult = handler.addFace(bitmap1);
                if (addFaceResult.result != 0) {
                    android.util.Log.d("qujiaqi", "add failed:" + addFaceResult.result
                            + ",blur:" + addFaceResult.blur
                            + ",pp:" + addFaceResult.pose.pitch
                            + ",pr:" + addFaceResult.pose.roll
                            + ",py:" + addFaceResult.pose.yaw);
                    continue;
                } else {
                    handler.deleteLocalGroup("temp" + f.getName());
                    boolean a = handler.createLocalGroup("temp" + f.getName());
                    android.util.Log.d("qujiaqi", "create group:" + a);
                    boolean b = handler.bindGroup("temp" + f.getName(), addFaceResult.faceToken);
                    android.util.Log.d("qujiaqi", "bind group:" + b);
                }

                byte[] rgb = BitmapToRGB(bitmap, bitmap.getWidth(), bitmap.getHeight());

                FacePassImage image = new FacePassImage(rgb, bitmap.getWidth(), bitmap.getHeight(), 0, FacePassImageType.RGB);

                FacePassDetectionResult result;
                for (int i = 0; i < 20; i++) {
                    result = handler.feedFrame(image);
                    if (result != null && result.faceList != null) {
                        android.util.Log.d("qujiaqi", "face:" + result.faceList.length);
                    } else {
                        android.util.Log.d("qujiaqi", "face is null");
                    }
                    if (result != null && result.message != null && result.message.length != 0) {
                        FacePassRecognitionResult[] recognitionResult = handler.recognize("temp" + f.getName(), result.message);
                        for (FacePassRecognitionResult r : recognitionResult) {
                            android.util.Log.d("qujiaqi", "file:" + f.getName()
                                    + ",s_score:" + r.detail.searchScore
                                    + ",l_score:" + r.detail.livenessScore);

                            handler.resetMessage(r.trackId);
                        }
                        break;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}).start();


附件:recognize接口做1v1识别.txt • 3.96KB • 下载

附件:FacePassPicUtil.aar.zip • 133.82KB • 下载

    您需要登录后才可以回复