【问题标题】:Firebase MLKit Facedetection Slow For AndroidFirebase ML Kit 人脸检测速度慢适用于 Android
【发布时间】:2019-12-24 08:29:05
【问题描述】:

我想从图库图像(位图)中检测人脸。

问题

  1. 我注意到 Firebase MLKIT 在图库中的执行速度非常慢 图像位图。
  2. 我还能使用移动视觉 api 检测图像中的人脸吗?(我只想检测人脸,不想要眼睛、鼻子等)
  3. 我应该如何提高使用 Firebase MLKIT 检测人脸的性能。
  4. 我使用了 Firebase 图像标签。 Firebase 图像标记执行速度很快,但人脸检测相对来说非常慢。

我尝试使用 Mobile vision Api 并成功检测到人脸。在 mobile vision api 的网站上,他们提到了 Firebase MLKIT。 我还尝试了 firebase ML Kit 并成功检测到人脸。我按照这个链接进行演示: [https://github.com/hitanshu-dhawan/FirebaseMLKit]

库版本:

implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.google.firebase:firebase-ml-vision:22.0.0'
implementation 'com.google.firebase:firebase-ml-vision-face-model:18.0.0'
implementation 'com.google.firebase:firebase-ml-vision-image-label-model:18.0.0' 

    FirebaseVisionFaceDetectorOptions option =
     new FirebaseVisionFaceDetectorOptions.Builder()
    .setPerformanceMode(FirebaseVisionFaceDetectorOptions.ACCURATE)
    .setLandmarkMode(FirebaseVisionFaceDetectorOptions.ALL_LANDMARKS)
    .setClassificationMode(FirebaseVisionFaceDetectorOptions.ALL_CLASSIFICATIONS)
    .build();

    FirebaseVisionFaceDetector detector = FirebaseVision.getInstance()
                .getVisionFaceDetector(option);

        detector.detectInImage(image).addOnSuccessListener(
                new OnSuccessListener<List<FirebaseVisionFace>>() {
                    @Override
                    public void onSuccess(List<FirebaseVisionFace> faces) {
    }

我是不是做错了什么?

【问题讨论】:

  • 任何人请帮助我

标签: android firebase performance firebase-mlkit google-mlkit


【解决方案1】:

我认为你可以改变 .setPerformanceMode(FirebaseVisionFaceDetectorOptions.ACCURATE).setPerformanceMode(FirebaseVisionFaceDetectorOptions.FAST)

可能会提高检测速度

【讨论】:

    【解决方案2】:

    我有同样的问题,但文本识别在 Android 上非常慢,每秒大约 1 张图像(华为 Y6 2018)但在 iOS 上速度非常快,我可以轻松地在 iPhone 6s 上每秒运行 10 帧。 我已经尝试了 Firebase 支持的所有图像格式,在我的测试中,最快的变量是 ByteBuffer,所以我在开始识别之前将 Bitmap 转换为 ByteBuffer。

    【讨论】:

      【解决方案3】:

      如果您直接从位图实例化 FirebaseVisionImage,Firebase 人脸检测器会非常慢,如下所示:

      FirebaseVisionImage visionImage = FirebaseVisionImage.fromBitmap(bitmap);
      

      解决方案是将位图转换为字节数组 (byte[]) 并使用此其他构造函数创建 FirebaseVisionImage

      FirebaseVisionImage visionImage = FirebaseVisionImage.fromByteArray(byteArray, metadata);
      

      这一事实似乎没有记录在案。我在a comment on this GitHub issue 中找到了它,并使用了所提出的技术,将人脸检测时间减少了大约 6 倍。同样在该链接中,还有来自 GitHub 用户 jllarraz 的代码 sn-p 用于将位图转换为 nv21 字节数组。

      【讨论】:

        【解决方案4】:

        感谢上述解决方案,但最后我能够非常快速地使用人脸检测器。我只是计算位图的 insamplesize 并减小位图的大小。由于位图大小非常小,能够以更快的速度处理人脸检测,然后一旦我得到坐标,再次通过乘以 insamplesize 将坐标映射到原始图像。这样我用 FirebaseVisionFaceDetectorOptions 快速实现了图像处理。下面是计算 insamplesize 的代码。

        public static int calculateInSampleSize(
                    BitmapFactory.Options options, int reqWidth, int reqHeight) {
            // Raw height and width of image
            final int height = options.outHeight;
            final int width = options.outWidth;
            int inSampleSize = 1;
        
            if (height > reqHeight || width > reqWidth) {
        
                final int halfHeight = height / 2;
                final int halfWidth = width / 2;
        
                // Calculate the largest inSampleSize value that is a power of 2 and keeps both
                // height and width larger than the requested height and width.
                while ((halfHeight / inSampleSize) >= reqHeight
                        && (halfWidth / inSampleSize) >= reqWidth) {
                    inSampleSize *= 2;
                }
            }
        
            return inSampleSize;
        }
        

        【讨论】:

          猜你喜欢
          • 2020-05-23
          • 2019-08-01
          • 2021-10-13
          • 2019-12-03
          • 2018-10-30
          • 2020-08-27
          • 1970-01-01
          • 2023-03-07
          • 2021-01-12
          相关资源
          最近更新 更多