private void asyncIdentity(ImageFrame imageFrame, FaceInfo[] faceInfos) { if (identityStatus != IDENTITY_IDLE) { return; } es.Submit(new Runnable(() => { if (faceInfos == null || faceInfos.Length == 0) { return; } int liveType = PreferencesUtil.getInt(LivenessSettingActivity.TYPE_LIVENSS, LivenessSettingActivity .TYPE_NO_LIVENSS); if (liveType == LivenessSettingActivity.TYPE_NO_LIVENSS) { identity(imageFrame, faceInfos[0]); } else if (liveType == LivenessSettingActivity.TYPE_RGB_LIVENSS) { if (rgbLiveness(imageFrame, faceInfos[0]) > FaceEnvironment.LIVENESS_RGB_THRESHOLD) { identity(imageFrame, faceInfos[0]); } else { // toast("rgb活体分数过低"); } } })); }
protected void onCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.liveness_setting_layout); findView(); int livenessType = PreferencesUtil.getInt(TYPE_LIVENSS, TYPE_NO_LIVENSS); int cameraType = PreferencesUtil.getInt(GlobalFaceTypeModel.TYPE_CAMERA, GlobalFaceTypeModel.ORBBEC); defaultLiveness(livenessType); defaultCamera(cameraType); }
private void choiceIdentityType(String groupId) { int type = PreferencesUtil.getInt(LivenessSettingActivity.TYPE_LIVENSS, LivenessSettingActivity .TYPE_NO_LIVENSS); if (type == LivenessSettingActivity.TYPE_NO_LIVENSS) { Toast.MakeText(this, "当前活体策略:无活体", ToastLength.Long).Show(); Intent intent = new Intent(this, typeof(RgbVideoIdentityActivity)); intent.PutExtra("group_id", groupId); StartActivity(intent); } else if (type == LivenessSettingActivity.TYPE_RGB_LIVENSS) { Toast.MakeText(this, "当前活体策略:单目RGB活体", ToastLength.Long).Show(); Intent intent = new Intent(this, typeof(RgbVideoIdentityActivity)); intent.PutExtra("group_id", groupId); StartActivity(intent); } else if (type == LivenessSettingActivity.TYPE_RGB_IR_LIVENSS) { Toast.MakeText(this, "当前活体策略:双目RGB+IR活体", ToastLength.Long).Show(); Intent intent = new Intent(this, typeof(RgbIrVideoIdentifyActivity)); intent.PutExtra("group_id", groupId); StartActivity(intent); } else if (type == LivenessSettingActivity.TYPE_RGB_DEPTH_LIVENSS) { Toast.MakeText(this, "当前活体策略:双目RGB+Depth活体", ToastLength.Long).Show(); int CameraType = PreferencesUtil.getInt(GlobalFaceTypeModel.TYPE_CAMERA, GlobalFaceTypeModel.ORBBEC); Intent intent = null; if (CameraType == GlobalFaceTypeModel.ORBBEC) { intent = new Intent(this, typeof(OrbbecVideoIdentifyActivity)); } else if (CameraType == GlobalFaceTypeModel.IMIMECT) { intent = new Intent(this, typeof(IminectVideoIdentifyActivity)); } else if (CameraType == GlobalFaceTypeModel.ORBBECPRO) { intent = new Intent(this, typeof(OrbbecProVideoIdentifyActivity)); } if (intent != null) { intent.PutExtra("group_id", groupId); StartActivity(intent); } } }
private void choiceAttrTrackType() { int type = PreferencesUtil.getInt(LivenessSettingActivity.TYPE_LIVENSS, LivenessSettingActivity .TYPE_NO_LIVENSS); if (type == LivenessSettingActivity.TYPE_NO_LIVENSS) { Toast.MakeText(this, "当前活体策略:无活体", ToastLength.Long).Show(); Intent intent = new Intent(this, typeof(RgbVideoAttributeTrackActivity)); StartActivity(intent); } else if (type == LivenessSettingActivity.TYPE_RGB_LIVENSS) { Toast.MakeText(this, "当前活体策略:单目RGB活体", ToastLength.Long).Show(); Intent intent = new Intent(this, typeof(RgbVideoAttributeTrackActivity)); StartActivity(intent); } else if (type == LivenessSettingActivity.TYPE_RGB_IR_LIVENSS) { Toast.MakeText(this, "当前活体策略:双目RGB+IR活体", ToastLength.Long).Show(); Intent intent = new Intent(this, typeof(RgbIrVideoAttributeActivity)); StartActivity(intent); } else if (type == LivenessSettingActivity.TYPE_RGB_DEPTH_LIVENSS) { Toast.MakeText(this, "当前活体策略:双目RGB+Depth活体", ToastLength.Long).Show(); int CameraType = PreferencesUtil.getInt(GlobalFaceTypeModel.TYPE_CAMERA, GlobalFaceTypeModel.ORBBEC); Intent intent = null; if (CameraType == GlobalFaceTypeModel.ORBBEC) { intent = new Intent(this, typeof(OrbbecVideoAttributeActivity)); } else if (CameraType == GlobalFaceTypeModel.IMIMECT) { intent = new Intent(this, typeof(IminectVideoAtrributeActivity)); } else if (CameraType == GlobalFaceTypeModel.ORBBECPRO) { intent = new Intent(this, typeof(OrbbecProVideoAttributeActivity)); } StartActivity(intent); } }
private void identity(ImageFrame imageFrame, FaceInfo faceInfo) { float raw = Java.Lang.Math.Abs(faceInfo.HeadPose[0]); float patch = Java.Lang.Math.Abs(faceInfo.HeadPose[1]); float roll = Java.Lang.Math.Abs(faceInfo.HeadPose[2]); // 人脸的三个角度大于20不进行识别 if (raw > 20 || patch > 20 || roll > 20) { return; } identityStatus = IDENTITYING; long starttime = DateTime.Now.Millisecond; int[] argb = imageFrame.getArgb(); int rows = imageFrame.getHeight(); int cols = imageFrame.getWidth(); int[] landmarks = faceInfo.Landmarks.ToArray(); int type = PreferencesUtil.getInt(GlobalFaceTypeModel.TYPE_MODEL, GlobalFaceTypeModel.RECOGNIZE_LIVE); IdentifyRet identifyRet = null; if (type == GlobalFaceTypeModel.RECOGNIZE_LIVE) { identifyRet = FaceApi.getInstance().identity(argb, rows, cols, landmarks, groupId); } else if (type == GlobalFaceTypeModel.RECOGNIZE_ID_PHOTO) { identifyRet = FaceApi.getInstance().identityForIDPhoto(argb, rows, cols, landmarks, groupId); } if (identifyRet != null) { displayUserOfMaxScore(identifyRet.getUserId(), identifyRet.getScore()); } identityStatus = IDENTITY_IDLE; displayTip("特征抽取对比耗时:" + (DateTime.Now.Millisecond - starttime), featureDurationTv); }
private void livnessTypeTip() { int type = PreferencesUtil.getInt(LivenessSettingActivity.TYPE_LIVENSS, LivenessSettingActivity .TYPE_NO_LIVENSS); if (type == LivenessSettingActivity.TYPE_NO_LIVENSS) { Toast.MakeText(this, "当前活体策略:无活体, 请选用普通USB摄像头", ToastLength.Long).Show(); } else if (type == LivenessSettingActivity.TYPE_RGB_LIVENSS) { Toast.MakeText(this, "当前活体策略:单目RGB活体, 请选用普通USB摄像头", ToastLength.Long).Show(); } else if (type == LivenessSettingActivity.TYPE_RGB_IR_LIVENSS) { Toast.MakeText(this, "当前活体策略:双目RGB+IR活体, 请选用RGB+IR摄像头", ToastLength.Long).Show(); } else if (type == LivenessSettingActivity.TYPE_RGB_DEPTH_LIVENSS) { Toast.MakeText(this, "当前活体策略:双目RGB+Depth活体,请选用RGB+Depth摄像头", ToastLength.Long).Show(); } }
private String filter(FaceInfo faceInfo, ImageFrame imageFrame) { String tip = ""; if (faceInfo.MConf < 0.6) { tip = "人脸置信度太低"; return(tip); } float[] headPose = faceInfo.HeadPose.ToArray(); if (Math.Abs(headPose[0]) > 20 || Math.Abs(headPose[1]) > 20 || Math.Abs(headPose[2]) > 20) { tip = "人脸置角度太大,请正对屏幕"; return(tip); } int width = imageFrame.getWidth(); int height = imageFrame.getHeight(); // 判断人脸大小,若人脸超过屏幕二分一,则提示文案“人脸离手机太近,请调整与手机的距离”; // 若人脸小于屏幕三分一,则提示“人脸离手机太远,请调整与手机的距离” float ratio = (float)faceInfo.MWidth / (float)height; Log.Info("liveness_ratio", "ratio=" + ratio); if (ratio > 0.6) { tip = "人脸离屏幕太近,请调整与屏幕的距离"; return(tip); } else if (ratio < 0.2) { tip = "人脸离屏幕太远,请调整与屏幕的距离"; return(tip); } else if (faceInfo.MCenterX > width * 3 / 4) { tip = "人脸在屏幕中太靠右"; return(tip); } else if (faceInfo.MCenterX < width / 4) { tip = "人脸在屏幕中太靠左"; return(tip); } else if (faceInfo.MCenterY > height * 3 / 4) { tip = "人脸在屏幕中太靠下"; return(tip); } else if (faceInfo.MCenterX < height / 4) { tip = "人脸在屏幕中太靠上"; return(tip); } int liveType = PreferencesUtil.getInt(LivenessSettingActivity.TYPE_LIVENSS, LivenessSettingActivity .TYPE_NO_LIVENSS); if (liveType == LivenessSettingActivity.TYPE_NO_LIVENSS) { saveFace(faceInfo, imageFrame); } else if (liveType == LivenessSettingActivity.TYPE_RGB_LIVENSS) { if (rgbLiveness(imageFrame, faceInfo) > 0.9) { saveFace(faceInfo, imageFrame); } else { toast("rgb活体分数过低"); } } return(tip); }
public void OnClick(View v) { if (v == autoDetectBtn) { if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) != Permission.Granted || ActivityCompat.CheckSelfPermission(this, Manifest .Permission.Camera) != Permission.Granted) { ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.WriteExternalStorage, Manifest.Permission.Camera }, 100); return; } avatarIv.SetImageResource(Resource.Drawable.avatar); faceImagePath = null; int type = PreferencesUtil.getInt(LivenessSettingActivity.TYPE_LIVENSS, LivenessSettingActivity .TYPE_NO_LIVENSS); if (type == LivenessSettingActivity.TYPE_NO_LIVENSS || type == LivenessSettingActivity.TYPE_RGB_LIVENSS) { Intent intent = new Intent(this, typeof(RgbDetectActivity)); intent.PutExtra("source", SOURCE_REG); StartActivityForResult(intent, REQUEST_CODE_AUTO_DETECT); } else if (type == LivenessSettingActivity.TYPE_RGB_IR_LIVENSS) { Intent intent = new Intent(this, typeof(RgbIrLivenessActivity)); intent.PutExtra("source", SOURCE_REG); StartActivityForResult(intent, REQUEST_CODE_AUTO_DETECT); } //else if (type == LivenessSettingActivity.TYPE_RGB_DEPTH_LIVENSS) //{ // int cameraType = PreferencesUtil.getInt(GlobalFaceTypeModel.TYPE_CAMERA, GlobalFaceTypeModel.ORBBEC); // Intent intent3 = null; // if (cameraType == GlobalFaceTypeModel.ORBBEC) // { // intent3 = new Intent(this, typeof(OrbbecLivenessDetectActivity)); // } // else if (cameraType == GlobalFaceTypeModel.IMIMECT) // { // intent3 = new Intent(this, typeof(IminectLivenessDetectActivity)); // } // else if (cameraType == GlobalFaceTypeModel.ORBBECPRO) // { // intent3 = new Intent(this, typeof(OrbbecProLivenessDetectActivity)); // } // if (intent3 != null) // { // intent3.PutExtra("source", SOURCE_REG); // StartActivityForResult(intent3, REQUEST_CODE_AUTO_DETECT); // } //} } else if (v == fromAlbumButton) { if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) != Permission.Granted) { //ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 100); return; } avatarIv.SetImageResource(Resource.Drawable.avatar); faceImagePath = null; Intent intent = new Intent(Intent.ActionPick); intent.SetType("image/*"); StartActivityForResult(intent, REQUEST_CODE_PICK_IMAGE); } else if (v == submitButton) { register(faceImagePath); } }