Take photo when face detected

≯℡__Kan透↙ 提交于 2019-12-21 23:21:04

问题


I have the following code and i want to automatic take only one photo when a face is detected. I have achieve to automatic take photo but it takes many photos without time to process them because it continuously detect the face. How can i make it to search every x minutes to find a face or every x minutes to take photo? Thank you in advance.

FaceDetectionListener faceDetectionListener
= new FaceDetectionListener(){

    @Override
    public void onFaceDetection(Face[] faces, Camera camera) {

        if (faces.length == 0){
            prompt.setText(" No Face Detected! ");
        }else{
            //prompt.setText(String.valueOf(faces.length) + " Face Detected :) ");
              try{
                camera.takePicture(myShutterCallback,myPictureCallback_RAW, myPictureCallback_JPG);

               }
               catch(Exception e){

               }
        }


    }};

回答1:


FaceDetectionListener faceDetectionListener
= new FaceDetectionListener(){

    private boolean processing = false;

    public void setProcessing(boolean processing) {
        this.processing = processing;
    }

    @Override
    public void onFaceDetection(Face[] faces, Camera camera) {
        if (processing) return;

        if (faces.length == 0){
            prompt.setText(" No Face Detected! ");
        }else{
            //prompt.setText(String.valueOf(faces.length) + " Face Detected :) ");
              try{
                   camera.takePicture(myShutterCallback,myPictureCallback_RAW, myPictureCallback_JPG);
                   processing = true;
               }
               catch(Exception e){

               }
        }


    }};

Then you can do whatever processing you want in myShutterCallback and call faceDetectionListener.setProcessing(false) to take another picture. This will guarantee that only one photo will be taken at a time.



来源:https://stackoverflow.com/questions/27431169/take-photo-when-face-detected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!