搜尋套件、儲存庫與 APP 分類

套件詳情v0.0.8

google_ml_vision

用於 Google ML Kit 電腦端視覺 API 的 Flutter 外掛程式。它包含條碼掃描、影像標記、文字辨識和人臉偵測。

AndroidiOS
近 30 天下載
88
喜歡數
135
Pub 分數
140

安裝套件

flutter pub add google_ml_vision

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 插件,整合 Google ML Kit 的設備端視覺 API,可在 Flutter 應用中直接實現條碼掃描、影像標記、文字辨識(OCR)和人臉偵測。專為低延遲的即時處理設計,在 Android 與 iOS 裝置上本地運行,確保隱私與效能。該插件透過簡單的方法簡化常見電腦視覺任務的實作,非常適合需要智慧影像分析卻不依賴雲端服務的行動應用。

適用情境

  • 零售應用中的條形碼掃描
  • 從圖像中提取文字
  • 照片應用中的圖像分類
  • 增強現實中的面部檢測
  • 文件掃描和OCR

主要特色

  • 設備端處理
  • 支援多種視覺任務
  • 低延遲性能
  • Privacy-preserving
  • 簡單 API 結合

適合對象

  • 需要即時視覺功能的行動應用程式
  • 注重用戶隱私的開發者
  • 需要離線功能的應用程式
  • 初創公司正在建構文件或AR工具
  • 使用原生機器學習功能的Flutter開發人員

使用建議

  • 需要 Android 5.0+ 或 iOS 10.0+
  • 僅限支援的視覺模型
  • 無基於雲的增強功能
  • 性能因設備而異
  • iOS 可能需要手動設定

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Google ML Kit Vision Plugin

(https://pub.dev/packages/google_ml_vision)

A Flutter plugin to use the capabilities of on-device Google ML Kit Vision APIs

Usage

To use this plugin, add google_ml_vision as a dependency in your pubspec.yaml file.

Using an ML Vision Detector

1. Create a GoogleVisionImage.

Create a GoogleVisionImage object from your image. To create a GoogleVisionImage from an image File object:

final File imageFile = getImageFile();
final GoogleVisionImage visionImage = GoogleVisionImage.fromFile(imageFile);
2. Create an instance of a detector.
final BarcodeDetector barcodeDetector = GoogleVision.instance.barcodeDetector();
final FaceDetector faceDetector = GoogleVision.instance.faceDetector();
final ImageLabeler labeler = GoogleVision.instance.imageLabeler();
final TextRecognizer textRecognizer = GoogleVision.instance.textRecognizer();

You can also configure all detectors, except TextRecognizer, with desired options.

final ImageLabeler labeler = GoogleVision.instance.imageLabeler(
  ImageLabelerOptions(confidenceThreshold: 0.75),
);
3. Call detectInImage() or processImage() with visionImage.
final List<Barcode> barcodes = await barcodeDetector.detectInImage(visionImage);
final List<Face> faces = await faceDetector.processImage(visionImage);
final List<ImageLabel> labels = await labeler.processImage(visionImage);
final VisionText visionText = await textRecognizer.processImage(visionImage);
4. Extract data.

a. Extract barcodes.

for (Barcode barcode in barcodes) {
  final Rectangle<int> boundingBox = barcode.boundingBox;
  final List<Point<int>> cornerPoints = barcode.cornerPoints;

  final String rawValue = barcode.rawValue;

  final BarcodeValueType valueType = barcode.valueType;

  // See API reference for complete list of supported types
  switch (valueType) {
    case BarcodeValueType.wifi:
      final String ssid = barcode.wifi.ssid;
      final String password = barcode.wifi.password;
      final BarcodeWiFiEncryptionType type = barcode.wifi.encryptionType;
      break;
    case BarcodeValueType.url:
      final String title = barcode.url.title;
      final String url = barcode.url.url;
      break;
  }
}

b. Extract faces.

for (Face face in faces) {
  final Rectangle<int> boundingBox = face.boundingBox;

  final double rotY = face.headEulerAngleY; // Head is rotated to the right rotY degrees
  final double rotZ = face.headEulerAngleZ; // Head is tilted sideways rotZ degrees

  // If landmark detection was enabled with FaceDetectorOptions (mouth, ears,
  // eyes, cheeks, and nose available):
  final FaceLandmark leftEar = face.getLandmark(FaceLandmarkType.leftEar);
  if (leftEar != null) {
    final Point<double> leftEarPos = leftEar.position;
  }

  // If classification was enabled with FaceDetectorOptions:
  if (face.smilingProbability != null) {
    final double smileProb = face.smilingProbability;
  }

  // If face tracking was enabled with FaceDetectorOptions:
  if (face.trackingId != null) {
    final int id = face.trackingId;
  }
}

c. Extract labels.

for (ImageLabel label in labels) {
  final String text = label.text;
  final String entityId = label.entityId;
  final double confidence = label.confidence;
}

d. Extract text.

String text = visionText.text;
for (TextBlock block in visionText.blocks) {
  final Rect boundingBox = block.boundingBox;
  final List<Offset> cornerPoints = block.cornerPoints;
  final String text = block.text;
  final List<RecognizedLanguage> languages = block.recognizedLanguages;

  for (TextLine line in block.lines) {
    // Same getters as TextBlock
    for (TextElement element in line.elements) {
      // Same getters as TextBlock
    }
  }
}
5. Release resources with close().
barcodeDetector.close();
faceDetector.close();
labeler.close();
textRecognizer.close();

Getting Started

See the example directory for a complete sample app using Google Machine Learning.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。