android - Google 的 Firebase ML Vision 仅适用于我的三星设备

标签 android firebase flutter qr-code firebase-mlkit

我正在使用 flutter 构建一个具有二维码扫描功能的 Android 应用程序。我已经将二维码逻辑分解为最小重现案例here .

奇怪的是,二维码扫描仅适用于我的三星设备。使用 google/firebase ml Vision 条形码扫描模型扫描 QR 码时,我的 Google Pixel XL 和 Oneplus 6t 均未拾取任何内容。

存储库中的关键代码位置是:

android/app/build.gradle我在其中包含条形码模型 api:

api 'com.google.firebase:firebase-ml-vision-barcode-model:16.0.2'

lib/src/bloc/services/qr_service.dart我在图像上运行条形码检测:

_processImage(CameraImage image) async {
    if (!_alreadyCheckingImage && !_foundRoomId) {
        _alreadyCheckingImage = true;
        try {
            final barcodes = await barcodeDetector.detectInImage(
                FirebaseVisionImage.fromBytes(
                    _concatenatePlanes(image.planes),
                    FirebaseVisionImageMetadata(
                        rawFormat: image.format.raw,
                        size: Size(image.width.toDouble(), image.height.toDouble()),
                        rotation: ImageRotation.rotation0,
                        planeData: image.planes
                            .map((plane) => FirebaseVisionImagePlaneMetadata(
                                    bytesPerRow: plane.bytesPerRow,
                                    height: plane.height,
                                    width: plane.width,
                                ),
                            )
                            .toList(),
                    ),
                ),
            );
            if (barcodes != null && barcodes.length > 0) {
                try {
                    print('\n~~~');
                    print(barcodes.first.toString());
                    print(barcodes.first.displayValue);
                    print(barcodes.first.valueType);
                    print(barcodes.first.rawValue);
                    print('~~~\n');
                    final barcode = barcodes.first;
                    print(barcode.rawValue);
                    qrResult.sink.add(barcode.rawValue);
                    _foundRoomId = true;
                } catch (err, stack) {
                    print('$err\n$stack');
                }
            }
        } catch (err, stack) {
            debugPrint('$err, $stack');
        }
        _alreadyCheckingImage = false;
    }
}

Uint8List _concatenatePlanes(List<Plane> planes) {
    final WriteBuffer allBytes = WriteBuffer();
    planes.forEach((plane) => allBytes.putUint8List(plane.bytes));
    return allBytes.done().buffer.asUint8List();
}

我希望我做错了什么。但很奇怪的是,这个最低限度的重现在我的三星 S8、三星 J7 和三星 S10+ 上完美运行,但在我的 Oneplus 6t (android 10) 上不起作用,在我的 Google Pixel XL (android 9) 上不起作用

最佳答案

尝试在 CameraController 中将相机设置设置为“高”,这对我来说很有效。

当您初始化相机 Controller 时,您想要执行以下操作:

final newCameraController = CameraController(
 cameras.first,
 ResolutionPreset.high,
 enableAudio: false,
);

这应该让所有设备都可以进行扫描。

关于android - Google 的 Firebase ML Vision 仅适用于我的三星设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59111768/

相关文章:

android - 此 Handler 类应该是静态的,否则可能会发生泄漏 (com.test.test3.ui.MainActivity.1)

java - 调用父类(super class)方法

android - 与 Android 的持续集成 [Codeship]

Android 博客应用程序,我应该使用 Sharedpreferences 还是 Intents?

python - 传感器Python DHT11

mobile - 滚动时如何从 SliverAppBar 淡入/淡出小部件?

flutter - Flutter/Dart:将getter 'length'调用为null

android - Flutter Listview 在使用 FutureBuilder 加载缩略图时卡住

android - 在 Core 2 Duo 10.11.6 Mac OS 上运行 Android Studio 模拟器

Firebase,如何限制来自特定数据集(实时数据库)的检索请求