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.
In short, the term face recognition extends beyond detecting the presence of a human face to determine whose face it is. The process uses a computer application that captures a digital image of an individual's face -- sometimes taken from a video frame -- and compares it to images in a database of stored records.
DeepFace - Most Popular Deep Face Recognition in 2022 (Guide) - viso.ai.
The most significant difference between real and fake faces is the existence of depth information. Real faces have three dimensions, with the nose and ears being relatively far from each other. This distance can be used to adequately represent the depth information.
You could use the parallax effect. First you take a 2 pictures from 2 different locations which are like 2cm apart. then you could compare the images and see:
*If they are very similar(almost same) then the image is 2d and it is a poster
*If they are very different then it is a 3d Face
Another way you could do this is by using the camera flash. The flash would cause a bit of reflection on photographs and this would prevent people from using a video to bypass your system as a screen would cause a lot of glare would would block the face preventing the camera from detecting the face. All you would need to do is add a flash(preferably blinking at like 100Hz so the people can't see it but it would show up in a picture)
I hope this helped :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With