📅  最后修改于: 2023-12-03 15:15:04.600000             🧑  作者: Mango
Firebase ML Vision is a powerful tool that allows developers to build intelligent apps that can recognize faces, detect text, and more. With the Firebase ML Vision Pub Dev package, developers can use pre-built models to detect objects and recognize text in images, making it easy to build powerful image recognition features into their applications.
To use Firebase ML Vision Pub Dev package, you need to have the Flutter SDK installed. Once you have installed Flutter, you can install the Firebase ML Vision Pub Dev package by adding it to your pubspec.yaml
file:
dependencies:
firebase_ml_vision: ^0.10.0
Then run flutter pub get
to install the package.
Once you have installed the Firebase ML Vision Pub Dev package, you can use it to perform image recognition tasks in your Flutter application. Here are some examples of how you can use Firebase ML Vision Pub Dev package:
import 'package:firebase_ml_vision/firebase_ml_vision.dart';
final imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
final visionImage = FirebaseVisionImage.fromFile(imageFile);
final faceDetector = FirebaseVision.instance.faceDetector();
final faces = await faceDetector.processImage(visionImage);
for (var face in faces) {
final rect = face.boundingBox;
final age = face.age; // if classification was enabled
final smile = face.smilingProbability; // if classification was enabled
final leftEyeOpen = face.leftEyeOpenProbability; // if classification was enabled
final rightEyeOpen = face.rightEyeOpenProbability; // if classification was enabled
}
import 'package:firebase_ml_vision/firebase_ml_vision.dart';
final imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
final visionImage = FirebaseVisionImage.fromFile(imageFile);
final textRecognizer = FirebaseVision.instance.textRecognizer();
final visionText = await textRecognizer.processImage(visionImage);
for (var block in visionText.blocks) {
final blockText = block.text;
final blockConfidence = block.confidence;
final blockLanguages = block.recognizedLanguages;
final blockBoundingBox = block.boundingBox;
for (var line in block.lines) {
final lineText = line.text;
final lineConfidence = line.confidence;
final lineLanguages = line.recognizedLanguages;
final lineBoundingBox = line.boundingBox;
for (var element in line.elements) {
final elementText = element.text;
final elementConfidence = element.confidence;
final elementLanguages = element.recognizedLanguages;
final elementBoundingBox = element.boundingBox;
}
}
}
import 'package:firebase_ml_vision/firebase_ml_vision.dart';
final imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
final visionImage = FirebaseVisionImage.fromFile(imageFile);
final labelDetector = FirebaseVision.instance.imageLabeler();
final labels = await labelDetector.processImage(visionImage);
for (var label in labels) {
final text = label.text;
final entityId = label.entityId;
final confidence = label.confidence;
}
Firebase ML Vision Pub Dev is a powerful tool that makes it easy for developers to build image recognition features into their Flutter applications. With pre-built models for face detection, text recognition, and object detection, it greatly simplifies the process of developing intelligent apps.