Android mobile vision API检测人脸花费的时间太长

Android mobile vision API检测人脸花费的时间太长,android,face-detection,vision-api,Android,Face Detection,Vision Api,我正在使用移动视觉API在android应用程序中检测人脸 我已经使用SparseArray of Face来存储对人脸的引用,但是detector.detect(frame)方法检测人脸花费的时间太长(15秒) 注意:我正在将相机拍摄的图像位图传递给detectFaces方法。 我的代码在下面 void detectFaces(Context context, Bitmap picture){ com.google.android.gms.vision.face.FaceDetecto

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

我已经使用SparseArray of Face来存储对人脸的引用,但是detector.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();
}
void detectFaces(上下文、位图图片){
com.google.android.gms.vision.face.FaceDetector=new com.google.android.gms.vision.face.FaceDetector.Builder(上下文)
.SetTrackinEnabled(错误)
.setClassificationType(com.google.android.gms.vision.face.FaceDetector.ALL_分类)
.build();
//构建框架
Frame Frame=new Frame.Builder().setBitmap(picture.build();
//检测人脸
SparseArray faces=探测器。检测(帧);//**这大约需要15秒**
如果(faces.size()==0)
Toast.makeText(上下文,“未检测到人脸”,Toast.LENGTH_SHORT.show();
其他的
{
Toast.makeText(上下文,“检测到的面是:“+faces.size(),Toast.LENGTH_LONG).show();
getClassification(faces.valueAt(0));
}
//释放探测器
检测器。释放();
}

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

在阅读了文档后,我发现我应该使用它来测试所需的文件是否已经下载,以便检测工作。我使用此方法建议按如下方式下载文件:

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


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


另外,释放一些空间并将应用程序移动到外部存储允许它在我的第一台设备上工作。

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

在阅读了文档后,我发现我应该使用它来测试所需的文件是否已经下载,以便检测工作。我使用此方法建议按如下方式下载文件:

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


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


另外,释放一些空间并将应用程序移动到外部存储允许它在我的第一台设备上工作。

您找到了这个问题的解决方案吗???您找到了这个问题的解决方案吗???您没有解决计算时间性能问题。您没有解决计算时间性能问题。