Google 的 Firebase ML Vision 仅适用于我的三星设备
Google's Firebase ML Vision only works on my Samsung Devices
我正在使用具有 QR 码扫描功能的 flutter 构建一个 android 应用程序。我把二维码的逻辑分解成了一个最小的复现案例here.
奇怪的是,二维码扫描只适用于我的三星设备。我的 Google Pixel XL 和 Oneplus 6t 在使用 google/firebase ml vision 条形码扫描模型扫描 QR 码时都没有拾取任何东西。
存储库中的关键代码位置是:
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) 上不起作用,在我的 [=35= 上不起作用] 像素 XL (android 9)
尝试在 CameraController 中将相机设置设为 'high',成功了。
当你初始化相机控制器时,你想做这样的事情:
final newCameraController = CameraController(
cameras.first,
ResolutionPreset.high,
enableAudio: false,
);
这应该让所有设备进行扫描。
我正在使用具有 QR 码扫描功能的 flutter 构建一个 android 应用程序。我把二维码的逻辑分解成了一个最小的复现案例here.
奇怪的是,二维码扫描只适用于我的三星设备。我的 Google Pixel XL 和 Oneplus 6t 在使用 google/firebase ml vision 条形码扫描模型扫描 QR 码时都没有拾取任何东西。
存储库中的关键代码位置是:
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) 上不起作用,在我的 [=35= 上不起作用] 像素 XL (android 9)
尝试在 CameraController 中将相机设置设为 'high',成功了。
当你初始化相机控制器时,你想做这样的事情:
final newCameraController = CameraController(
cameras.first,
ResolutionPreset.high,
enableAudio: false,
);
这应该让所有设备进行扫描。