Google google_ml_kit 的条形扫描仪:^0.6.0
Bar Scanner With Google google_ml_kit: ^0.6.0
美好的一天,
我正在尝试制作数据矩阵条形码扫描仪,我正在尝试使用 google_ml_kit: ^0.6.0,
我一直在尝试按照 flutter 页面中的说明进行操作 https://pub.dev/packages/google_ml_kit。但我没有运气。我是 flutter 和 dart 的新手,非常感谢任何帮助。
在 getBarcodeCode 里面
行中的final List barcodes = await barcodeScanner.processImage(inputImage);
我总是得到 0 个项目。
谢谢你,
import 'dart:developer';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:google_ml_kit/google_ml_kit.dart';
import 'dart:io';
class DashBoard extends StatefulWidget {
static String id = 'DashBoard';
const DashBoard({Key? key}) : super(key: key);
@override
_DashBoardState createState() => _DashBoardState();
}
class _DashBoardState extends State<DashBoard> {
getBarcodeCode(var filePath)async {
final inputImage = InputImage.fromFile(filePath);
final barcodeScanner = GoogleMlKit.vision.barcodeScanner();
final List<Barcode> barcodes = await barcodeScanner.processImage(inputImage);
for (Barcode barcode in barcodes) {
final String? rawValue = barcode.value.rawValue;
log(rawValue.toString());
}
barcodeScanner.close();
}
_imgFromCamera() async {
final picker = ImagePicker();
PickedFile? pickedFile = await picker.getImage(source: ImageSource.camera, imageQuality: 50);
var imageFile = File(pickedFile!.path);
getBarcodeCode(imageFile);
}
_imgFromGallery() async {
final picker = ImagePicker();
PickedFile? pickedFile = await picker.getImage(source: ImageSource.gallery, imageQuality: 50);
var imageFile = File(pickedFile!.path);
getBarcodeCode(imageFile);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Container(
child: Wrap(
children: <Widget>[
ListTile(
leading: new Icon(Icons.photo_library),
title: new Text('Photo Library'),
onTap: () {
_imgFromGallery();
}),
ListTile(
leading: new Icon(Icons.photo_camera),
title: new Text('Camera'),
onTap: () {
_imgFromCamera();
},
),
],
),
),
),
),
);
}
}
如果您使用 ML Kit 进行条形码,我建议使用 qr_mobile_vision flutter 包。它使用 Google Vision API 扫描条形码。
美好的一天, 我正在尝试制作数据矩阵条形码扫描仪,我正在尝试使用 google_ml_kit: ^0.6.0,
我一直在尝试按照 flutter 页面中的说明进行操作 https://pub.dev/packages/google_ml_kit。但我没有运气。我是 flutter 和 dart 的新手,非常感谢任何帮助。
在 getBarcodeCode 里面
行中的final List barcodes = await barcodeScanner.processImage(inputImage); 我总是得到 0 个项目。
谢谢你,
import 'dart:developer';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:google_ml_kit/google_ml_kit.dart';
import 'dart:io';
class DashBoard extends StatefulWidget {
static String id = 'DashBoard';
const DashBoard({Key? key}) : super(key: key);
@override
_DashBoardState createState() => _DashBoardState();
}
class _DashBoardState extends State<DashBoard> {
getBarcodeCode(var filePath)async {
final inputImage = InputImage.fromFile(filePath);
final barcodeScanner = GoogleMlKit.vision.barcodeScanner();
final List<Barcode> barcodes = await barcodeScanner.processImage(inputImage);
for (Barcode barcode in barcodes) {
final String? rawValue = barcode.value.rawValue;
log(rawValue.toString());
}
barcodeScanner.close();
}
_imgFromCamera() async {
final picker = ImagePicker();
PickedFile? pickedFile = await picker.getImage(source: ImageSource.camera, imageQuality: 50);
var imageFile = File(pickedFile!.path);
getBarcodeCode(imageFile);
}
_imgFromGallery() async {
final picker = ImagePicker();
PickedFile? pickedFile = await picker.getImage(source: ImageSource.gallery, imageQuality: 50);
var imageFile = File(pickedFile!.path);
getBarcodeCode(imageFile);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Container(
child: Wrap(
children: <Widget>[
ListTile(
leading: new Icon(Icons.photo_library),
title: new Text('Photo Library'),
onTap: () {
_imgFromGallery();
}),
ListTile(
leading: new Icon(Icons.photo_camera),
title: new Text('Camera'),
onTap: () {
_imgFromCamera();
},
),
],
),
),
),
),
);
}
}
如果您使用 ML Kit 进行条形码,我建议使用 qr_mobile_vision flutter 包。它使用 Google Vision API 扫描条形码。