侦测到脸部后拍照 [英] Take photo when face detected

查看:69
本文介绍了侦测到脸部后拍照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我想在检测到脸部时自动仅拍摄一张照片. 我已经实现了自动拍照,但是由于它可以连续检测到脸部,因此无需时间即可拍摄很多照片.我怎样才能每隔X分钟搜索一次以查找人脸或每隔X分钟进行拍照?预先谢谢你.

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

               }
        }


    }};

推荐答案

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

               }
        }


    }};

然后,您可以在myShutterCallback中进行所需的任何处理,然后调用faceDetectionListener.setProcessing(false)拍摄另一张照片.这样可以保证一次只能拍摄一张照片.

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.

这篇关于侦测到脸部后拍照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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