移动视觉API需要太长时间才能检测到面部 [英] mobile vision API takes too long to detect face

查看:94
本文介绍了移动视觉API需要太长时间才能检测到面部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using mobile vision API to detect face in android app.

我已经使用了Faces的SparseArray来存储对面部的引用,但是detector.detect(frame)方法花费的时间太长(15秒)来检测面部.

I have used SparseArray of Face to store the references to faces, but the detector.detect(frame) method takes too long (15 seconds) to detect face.

注意:我正在将相机拍摄的图像的位图传递给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();
}

推荐答案

我目前正在浏览此示例应用程序,但遇到相同的问题,该应用程序不断返回未检测到人脸的信息.

I am currently going through this sample app and I came across the same issue where the app keeps returning that the face is not detected.

通读文档后,可在此处我看到我应该使用 detector.isOperational()进行测试是否已下载必需的文件以使检测正常进行.我使用这种方法来建议文件正在像这样下载:

After reading through the documentation found here I saw that I should be using detector.isOperational() to test if the required files have been downloaded in order for the detection to work. I used this method to advise that the files are being downloaded like this:

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();
        }


    }

接下来,我意识到检测器永远无法运行.经过更多研究,我发现问题出在我的设备没有足够的存储空间来保存所需的其他文件.我切换到另一台设备时,第一次尝试遇到未运行"错误,此后一直在运行.

Next I realized that the detector was never operational. After more research I found the problem to be that my device did not have enough storage space to save the additional files needed. I switched to another device got the 'Not Operational' error on the first try and it has been working ever since then.

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

Also, freeing up some space and moving the app to external storage allowed it to work on my first device.

这篇关于移动视觉API需要太长时间才能检测到面部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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