[英]Google's Firebase ML Vision only works on my Samsung Devices
我正在使用具有 QR 碼掃描功能的 Flutter 構建一個 android 應用程序。 我已經打破了QR代碼邏輯到最小再現的情況下在這里。
奇怪的是,QR 掃描僅適用於我的三星設備。 我的 Google Pixel XL 和 Oneplus 6t 在使用 google/firebase ml vision 條碼掃描模型掃描二維碼時都沒有拾取任何東西。
存儲庫中的關鍵代碼位置是:
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 中將相機設置設置為“高”,這對我有用。
當您初始化相機控制器時,您希望執行以下操作:
final newCameraController = CameraController(
cameras.first,
ResolutionPreset.high,
enableAudio: false,
);
這應該讓所有設備都進行掃描。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.