【问题标题】:mobile vision API takes too long to detect face移动视觉 API 检测人脸的时间过长
【发布时间】:2017-09-29 08:31:23
【问题描述】:

我正在使用移动视觉 API 在 android 应用中检测人脸。

我使用 SparseArray of Face 来存储对人脸的引用,但是检测器.detect(frame) 方法检测人脸的时间太长(15 秒)。

注意:我将相机拍摄的图像的位图传递给detectFaces方法。

我的代码在下面

void detectFaces(Context context, Bitmap picture){
    com.google.android.gms.vision.face.FaceDetector detector = new com.google.android.gms.vision.face.FaceDetector.Builder(context)
            .setTrackingEnabled(false)
            .setClassificationType(com.google.android.gms.vision.face.FaceDetector.ALL_CLASSIFICATIONS)
            .build();

    //Build the frame
    Frame frame = new Frame.Builder().setBitmap(picture).build();

    //Detect the faces
    SparseArray<Face> faces = detector.detect(frame);//**This takes approx 15 second**
    if(faces.size() == 0)
        Toast.makeText(context, "No Face Detected", Toast.LENGTH_SHORT).show();
    else
    {
        Toast.makeText(context,"Face detected are : " + faces.size() , Toast.LENGTH_LONG).show();
        getClassification(faces.valueAt(0));
    }

    //Release the detector
    detector.release();
}

【问题讨论】:

  • 你找到解决这个问题的方法了吗???

标签: android face-detection vision-api


【解决方案1】:

我目前正在浏览这个示例应用程序,并且遇到了相同的问题,即应用程序不断返回未检测到人脸。

在阅读找到here 的文档后,我看到我应该使用detector.isOperational() 来测试是否已下载所需的文件以便检测工作。我使用这种方法来建议文件是这样下载的:

public static void detectFaces(Context context, Bitmap image){
        // Create the face detector, disable tracking and enable classifications

        FaceDetector detector = new FaceDetector.Builder(context)
                .setTrackingEnabled(false)
                .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
                .build();

        if(detector.isOperational()){
            // Build the frame
            Frame frame = new Frame.Builder().setBitmap(image).build();
            ...
        }else{
            Toast.makeText(context, R.string.not_operational, Toast.LENGTH_LONG).show();
        }


    }

接下来我意识到探测器从未运行过。经过更多研究,我发现问题在于我的设备没有足够的存储空间来保存所需的其他文件。我切换到另一台设备在第一次尝试时出现“无法操作”错误,并且从那时起它一直在工作。

此外,释放一些空间并将应用程序移至外部存储设备使其可以在我的第一台设备上运行。

【讨论】:

  • 您没有解决计算时间性能问题。
猜你喜欢
  • 2016-07-03
  • 2018-04-07
  • 2017-12-31
  • 2017-02-23
  • 2018-07-14
  • 1970-01-01
  • 2019-09-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多