简体   繁体   English

使用FaceDetector Google-vision检测到脸部时拍照

[英]take picture when face detected using FaceDetector google-vision

I found the demo code here: https://github.com/googlesamples/android-vision/blob/master/visionSamples/FaceTracker/app/src/main/java/com/google/android/gms/samples/vision/face/facetracker/FaceTrackerActivity.java 我在这里找到了演示代码: https : //github.com/googlesamples/android-vision/blob/master/visionSamples/FaceTracker/app/src/main/java/com/google/android/gms/samples/vision/face /facetracker/FaceTrackerActivity.java

and my question is how to take picture when face detected and save it to device, and when we take 1st picture next picture will be take after 5s when face detected because we can't save to many picture to device. 我的问题是如何在检测到人脸时拍摄照片并将其保存到设备中,而当我们拍摄第一张照片时,由于无法将很多照片保存到设备中,因此在检测到人脸后5秒后将拍摄下一幅照片。

You have to add FaceDetectionListener in camera API then call startFaceDetection() method, 您必须在相机API中添加FaceDetectionListener,然后调用startFaceDetection()方法,

CameraFaceDetectionListener fDListener = new CameraFaceDetectionListener();
mCamera.setFaceDetectionListener(fDetectionListener);
mCamera.startFaceDetection();

Implement Camera.FaceDetectionListener, you receive the detected face in onFaceDetection override method, 实现Camera.FaceDetectionListener,您将在onFaceDetection重写方法中收到检测到的面部,

private class MyFaceDetectionListener 
          implements Camera.FaceDetectionListener {

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

    if (faces.length == 0) {
        Log.i(TAG, "No faces detected");
    } else if (faces.length > 0) {
        Log.i(TAG, "Faces Detected = " + 
              String.valueOf(faces.length));

        public List<Rect> faceRects;
        faceRects = new ArrayList<Rect>();

        for (int i=0; i<faces.length; i++) {
            int left = faces[i].rect.left;
            int right = faces[i].rect.right;
            int top = faces[i].rect.top;
            int bottom = faces[i].rect.bottom;
            Rect uRect = new Rect(left0, top0, right0, bottom0);
            faceRects.add(uRect);
        }

        // add function to draw rects on view/surface/canvas
    }
}

As per your case, new Handler().postDelayed(new Runnable,long seconds) take 2nd picture inside runnable after 5 seconds. 根据您的情况,new Handler()。postDelayed(new Runnable,long seconds)在5秒后在runnable内拍摄第二张图片。 Please let me know if you have any queries. 如果您有任何疑问,请告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android自定义facedetector捕获帧仅在检测到面部时 - android custom facedetector capture frame only if face is detected Google Mobile Vision:没有CameraSource的FaceDetector性能不佳 - Google Mobile Vision: Poor FaceDetector performance without CameraSource 单元测试FaceDetector Google移动视觉java.lang.UnsupportedOperationException - unit testing FaceDetector Google mobile vision java.lang.UnsupportedOperationException 使用Google vision API裁剪地标的一部分 - crop landmarks part of the face using Google vision API 使用“ android-vision”库保存实时检测到的人脸(Track Faces)图像 - Save real-time detected face(Track Faces) image using 'android-vision' library 使用Google Cloud Vision人脸检测API时发生错误 - Error occurs while using Google Cloud Vision Face Detection API 如何使用Android中的Google Vision人脸检测API仅裁剪脸部而不是椭圆形的全身 - how to crop only face instead of whole body in oval form using Google Vision Face detection API in android Maven - 无法解决依赖性冲突,而不是google-vision beta和aws-sdk子组件 - Maven - Unable to resolve dependency conflict b/w google-vision beta & aws-sdk sub-components 如何使用Google Vision api获取检测到的条形码框架以进行条形码检测 - How to get frame of detected Barcode using Google Vision api for Barcode detection 旋转保存Android FaceDetector.Face [] - Saving Android FaceDetector.Face[] on rotation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM