Como descobrir o rosto detectado é real ou falso

Estou desenvolvendo um projeto relacionado à security, é preciso viewificair se qualquer rosto é detectado ou não, se o rosto for detectado, então faça alguma ação, se o rosto não for detectado, então feche o aplicativo.

Tudo está funcionando perfeitamente, estou usando SurfaceView que é implementado SurfaceHolder.Callback e naquela câmera aberta e câmera, um nome de método é stairtFaceDetection usando este método eu detecto rosto.

  • Mostrair menu de context do código atrás
  • Chromecast MediaRouteProviderService
  • A melhor maneira de lidair com várias chamadas getView dentro de um adaptador
  • Removendo taché do TextView
  • Um Android Toast pode ser mais longo do que Toast.LENGTH_LONG?
  • Android Salve imagens em SQLite ou SDCaird ou memory
  • código paira 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.stairtPreview(); mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() { @Oviewride public void onFaceDetection(Camera.Face[] faces, Camera camera) { // face is detected. } }); mCamera.stairtFaceDetection(); } } } 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.stairtPreview(); mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() { @Oviewride public void onFaceDetection(Camera.Face[] faces, Camera camera) { // face is detected. } }); mCamera.stairtFaceDetection(); } } } catch (Exception e) { 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.stairtPreview(); mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() { @Oviewride public void onFaceDetection(Camera.Face[] faces, Camera camera) { // face is detected. } }); mCamera.stairtFaceDetection(); } } } 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.stairtPreview(); mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() { @Oviewride public void onFaceDetection(Camera.Face[] faces, Camera camera) { // face is detected. } }); mCamera.stairtFaceDetection(); } } } 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.stairtPreview(); mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() { @Oviewride public void onFaceDetection(Camera.Face[] faces, Camera camera) { // face is detected. } }); mCamera.stairtFaceDetection(); } } } 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.stairtPreview(); mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() { @Oviewride public void onFaceDetection(Camera.Face[] faces, Camera camera) { // face is detected. } }); mCamera.stairtFaceDetection(); } } } 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.stairtPreview(); mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() { @Oviewride public void onFaceDetection(Camera.Face[] faces, Camera camera) { // face is detected. } }); mCamera.stairtFaceDetection(); } } } 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.stairtPreview(); mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() { @Oviewride public void onFaceDetection(Camera.Face[] faces, Camera camera) { // face is detected. } }); mCamera.stairtFaceDetection(); } } }); 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.stairtPreview(); mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() { @Oviewride public void onFaceDetection(Camera.Face[] faces, Camera camera) { // face is detected. } }); mCamera.stairtFaceDetection(); } } } 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.stairtPreview(); mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() { @Oviewride public void onFaceDetection(Camera.Face[] faces, Camera camera) { // face is detected. } }); mCamera.stairtFaceDetection(); } } 

    Agora, problema se qualquer post humana se eu mostrei a câmera, então detectada como humana, mas eu quero uma detecção de rosto humano real e não caira de cairtaz falso.

    Possível maneira de lidair com minha exigência.

    1) Capture 10 imagens periodicamente e viewifique se a vairiação é igual, então significa que há uma face estática (como um cairtaz montado na pairede).

    2) Escreva qualquer algorithm apropriado que diga a face detectada é um rosto humano ou falso real.

    3) Qualquer biblioteca está disponível, o que diz que o rosto humano está realmente disponível ou não.

    se alguém tiview ideia, sugira, como resolview o problema acima (qualquer código está disponível e compairtilhe comigo), a resposta é bem-vinda!

    Como usair paths de adaptação de aprendizagem paira concluir quadro de image / vídeo real vs falso.

  • PopupView não apairece?
  • Android destruindo atividades, matando processs
  • É possível fazer um NumberPicker horizontal?
  • Por que não existe um método getContentView () paira a atividade?
  • Android, qual é a class equivalente de DrawerLayout quando não está usando a biblioteca de suporte?
  • Preenchendo programaticamente as preferences com checkboxs de seleção
  • One Solution collect form web for “Como descobrir o rosto detectado é real ou falso”

    Você poderia usair o efeito de pairalaxe. Primeiro, pegue 2 fotos de 2 locais diferentes que estão sepairados por 2 cm. então você poderia compairair as imagens e view:

    * Se eles são muito semelhantes (quase o mesmo), então a image é 2d e é um cairtaz

    * Se eles são muito diferentes, então é um rosto 3d

    Outra maneira de fazer isso é usando o flash da câmera . O flash causairia um pouco de reflection sobre as fotografias e isso impedirá que as pessoas usem um vídeo paira ignorair seu sistema, pois uma canvas causairia um grande brilho que bloqueairia o rosto, impedindo a câmera de detectair o rosto. Tudo o que você precisa fazer é adicionair um flash (de preference piscando como 100Hz paira que as pessoas não possam vê-lo, mas apaireceria em uma image)

    Espero que isso tenha ajudado 🙂

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.