简体   繁体   English

无法在 android 上使用 firebase ml 套件检测 QR 码,但在 ios 上工作(颤振)

[英]Not detecting QR codes with firebase ml kit on android but works on ios (flutter)

My qr code scanner stopped working on Android and I do not understand why... It worked previously and the scanner still works on iOS.我的二维码扫描仪停止在 Android 上工作,我不明白为什么......它以前工作过,扫描仪仍然在 iOS 上工作。

Firebase ML kit simply returns an empty list when scanning and I have tried many different android devices and QR codes but none work (anymore). Firebase ML 套件在扫描时仅返回一个空列表,我尝试了许多不同的 android 设备和 QR 码,但都没有工作(不再)。

I have tried to clean and reinstall all dependencies, I tried to clear all data in Google Play services and reinstalled the app (so that it reinstalls the ML model)我试图清理并重新安装所有依赖项,我试图清除 Google Play 服务中的所有数据并重新安装应用程序(以便重新安装 ML 模型)

I had an idea that it could possibly be the image format that is not correct, the format from the camera is in YUV_420_888 and I think it is converted into NV21 with the code below, but not 100% sure how that works.我有一个想法,它可能是不正确的图像格式,来自相机的格式是 YUV_420_888,我认为它使用下面的代码转换为 NV21,但不能 100% 确定它是如何工作的。

What's annoying is that this did work before but suddenly stoped working.令人讨厌的是,这之前确实有效,但突然停止工作。

This is my implementation of the QR scanner it recieves an image from the camera stream这是我对 QR 扫描仪的实现,它从相机 stream 接收图像

class QRCodeReader {

  BarcodeDetector _barcodeDetector = FirebaseVision.instance.barcodeDetector(BarcodeDetectorOptions(barcodeFormats: BarcodeFormat.qrCode));

  void dispose() {
    _barcodeDetector.close();
  }

  void scanImage(CameraImage availableImage, ScanCompleted scanCompleted) async {
    final FirebaseVisionImageMetadata metadata = FirebaseVisionImageMetadata(
      rawFormat: availableImage.format.raw,
      size: Size(availableImage.width.toDouble(), availableImage.height.toDouble()),
      planeData: availableImage.planes.map((currentPlane) => FirebaseVisionImagePlaneMetadata(
        bytesPerRow: currentPlane.bytesPerRow,
        height: currentPlane.height,
        width: currentPlane.width
        )).toList(),
      rotation: ImageRotation.rotation0,
    );

    final FirebaseVisionImage visionImage = FirebaseVisionImage.fromBytes(availableImage.planes[0].bytes, metadata);

    //this list is empty on android
    List barCodes = await _barcodeDetector.detectInImage(visionImage);

    for(Barcode barcode in barCodes) {
      //process barcode...
    }

    scanCompleted();
  } 
}

I initialize the stream like this...我像这样初始化 stream ...

_initializeControllerFuture = _controller.initialize();
_initializeControllerFuture.whenComplete(() {
  setState((){
    _controller.startImageStream(_handleImageStream);
  });
});

void _handleImageStream(CameraImage availableImage) {
    if (!_isScanning && !_disposed) {
      final state = Provider.of<ScannerState>(context);
      _isScanning = true;

      qrReader.scanImage(availableImage, () => _isScanning = false);
    }
}

app/build.gradle应用程序/build.gradle

...
dependencies {
    ...
    api 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2'
}

apply plugin: 'com.google.gms.google-services'

build.gradle build.gradle

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

AndroidManifest.xml AndroidManifest.xml

...
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />


    <application
        android:name="io.flutter.app.FlutterApplication"
        ...>
        <meta-data
            android:name="com.google.firebase.ml.vision.DEPENDENCIES"
            android:value="barcode" />
        ...
    </application>

pubspec.yaml pubspec.yaml

...
dependencies:
  ...
  camera: ^0.5.4+2
  firebase_core: ^0.4.0+9
  cloud_firestore: ^0.12.9+4
  cloud_functions: ^0.4.1+1
  firebase_ml_vision: ^0.9.2+1
...

Edit: As suggested by Frank, the issue was the resolution setting on the camera, if it is to low the QR code cannot be detected.编辑:正如弗兰克所建议的,问题是相机上的分辨率设置,如果它太低,则无法检测到 QR 码。 Putting it on "high" or higher sovles this problem.把它放在“高”或更高的位置可以解决这个问题。

I solved this issue by rolling back the camera plugin to version: "camera: ^0.5.2+2"我通过将相机插件回滚到版本解决了这个问题:“相机:^0.5.2+2”

Not sure what exactly breaks the ML vision package for android in the newer version, but this solved the issue for now.不确定在较新版本中究竟是什么破坏了 android 的 ML 视觉 package,但这暂时解决了这个问题。

暂无
暂无

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

相关问题 Firebase Android ML Kit:在 QR 码上隐藏显示值的方法 - Firebase Android ML Kit: Way to hide display values on QR code 条码扫描器使用 ML Kit 仅读取 QR 码 - Barcode scanner is reading only QR codes using ML Kit 为什么ML-kit没有检测到小二维码? - Ml-kit did not detecting small QR-code why? Firebase ML 套件是否支持二维码生成器? - Does Firebase ML kit supports QR Code generator? Firebase ML 套件的 QR 码扫描仪可多次扫描每个 QR 码 - Firebase ML kit's QR Code Scanner Scans each QR Code Multiple Times 使用arcore和ml kit firebase检测到二维码后,如何使用增强现实来更改二维码的颜色 - how to use augmented reality to change the color of a qr code once it is detected using with arcore and ml kit firebase 使用相机和Firebase ML套件在Android设备上进行文字识别不准确 - Text Recognition not accurate on Android device using camera and Firebase ML Kit 机器学习套件 Firebase 翻译文本 null Kotlin ZE84E30B9390CDB64DB6DB2C9AB8784D - ML Kit Firebase translate text null Kotlin Android 用于二维码扫描的 Android ML Kit 库:如何通过降低图像分辨率来提高检测性能 - Android ML Kit library for QR code scanning: How to increase detection performance by reducing image resolution 使用 Android/Kotlin QR Scanner App 和最新版本的 Google ML Kit Scan Barcode 崩溃 - Crash with Android/Kotlin QR Scanner App and the latest version of Google ML Kit Scan Barcode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM