如何找出侦测到的脸是真还是假 [英] How to find out detected face is real or fake

查看:100
本文介绍了如何找出侦测到的脸是真还是假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个与安全相关的项目,需要检查是否检测到任何人脸,如果检测到人脸,请执行一些操作,如果未检测到人脸,则关闭应用程序.

一切都完美无缺,我使用的是SurfaceView,它已实现SurfaceHolder.Callback,在打开的相机中,相机使用此方法检测到人脸的方法名称为startFaceDetection.

参考代码

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();
    }
}

现在,如果我向摄像机显示然后被检测为人的话,是否有任何人张贴的问题,但是我希望真正的人脸检测不是伪造的海报人脸.

可能是处理我的要求的方式.

1)定期捕获10张图像,并检查所有变化是否相同,这意味着那里有静止的面孔(如安装在墙上的海报).

2)编写任何适当的算法来告诉检测到的脸是真实的人脸还是假脸.

3)任何可用的库都可以说真的可以使用人脸.

如果有人有任何想法请提出建议,如何解决以上问题(有任何代码,然后与我分享),感谢您的答复!

如何使用适应性学习方法来得出真实或假图片/视频帧.

解决方案

您可以使用视差效果.首先,您从2个不同的位置(相距2厘米)拍摄2张照片.那么您可以比较图像并查看:

*如果它们非常相似(几乎相同),则图像为2d并且是海报

*如果它们非常不同,则为3d脸

您可以执行此操作的另一种方法是使用相机闪光灯.闪光灯会在照片上产生一点反射,这会阻止人们使用视频绕过您的系统,因为屏幕会引起很多眩光,从而会挡住脸部,从而使相机无法检测到脸部.您所需要做的就是添加闪光灯(最好以100Hz的频率闪烁,这样人们看不到它,但是它会显示在图片中)

我希望这会有所帮助:)

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.

解决方案

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 :)

这篇关于如何找出侦测到的脸是真还是假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆