I am developing one security related project, there is need to check any face is detected or not, if face is detected then do some action, if face is not detected then close app.
Everything is perfect working, i am using SurfaceView
which is implemented SurfaceHolder.Callback
and in that open camera and camera have one method name is startFaceDetection
using this method i detect face.
code for reference
public class SurfaceViewPreview extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camera mCamera;
public SurfaceViewPreview(Context context, AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
try {
if (Camera.getNumberOfCameras() <= 0 || ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED)
return;
mCamera = Camera.open(0);
mCamera.setPreviewDisplay(mHolder);
} catch (Exception e) {
e.printStackTrace();
if (this.mCamera != null) {
this.mCamera.release();
this.mCamera = null;
}
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
if (Camera.getNumberOfCameras() <= 0 || ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED)
return;
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (Camera.getNumberOfCameras() <= 0 || ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED)
return;
mCamera.startPreview();
mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() {
@Override
public void onFaceDetection(Camera.Face[] faces, Camera camera) {
// face is detected.
}
});
mCamera.startFaceDetection();
}
}
Now, problem if any human post if i shown to camera then detected as human, but i want real human face detection not fake poster face.
Possible way to handle my requirement.
1) Capture 10 images periodically and check all variation is same then it means static face is there (like poster which is mounted in wall).
2) Write any proper algorithm which tell to detected face is real human or fake face.
3) Any library is available which is said human face is really available or not.
if anyone have idea please suggest, how to solve above issue (any code is available then share with me), response is appreciated !
how can use adapting learning ways to conclude real vs fake picture/video frame.