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

GitHub 儲存庫alesdi/qr_code_vision

qr_code_vision

用於Flutter中AR應用從影像提取QR碼資料的高階與低階函數

qr_code_vision 專案封面
星標
29
分支
13
最近推送(UTC)
2024年4月10日
專案狀態
未封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

This package provides both high-level and low-level functions to extract QR code data from an image, including its location, type and content. In addition, it can be used to efficiently track a QR code position and content between frames, e.g. for AR (Augmented Reality) applications in Flutter. qr_code_vision is written in pure Dart, and is based on the popular jsQR javascript QR reader.

Features

Screen recording of the example

This package is still in early development: it could be subject to radical changes and many features are incomplete or not thoroughly tested.

Usage

In order to locate and decode QR code in an image, you need to first obtain its byte data in an RGBA format. This can be done in many ways depending on the image source and format. for example for a dart:ui Image you can use the toByteData() method.. Then just instantiate a new QrCode object and call scanRgbaBytes(imageData, imageWidth, imageHeight) to attempt to locate and decode the QR code:

// Let frames be a list dart:ui images
final List<ui.Image> frames = getSomeCameraFrames();

final qrCode = QrCode();

for(final frame in frames){
    final byteData =
        (await frame.toByteData(format: ui.ImageByteFormat.rawRgba))!
            .buffer
            .asUint8List();
    qrCode.scanRgbaBytes(byteData, frame.width, frame.height);

    if(qrCode.location == null){
        print('No QR code found');
    }else{
        print('QR code here: ${qrCode.location}');

        if(qrCode.content == null){
            print('The content of the QR code could not be decoded');
        }else{
            print('This is the content: ${qrCode.content.text}');
        }
    }
}

The location property contains extensive information, including position of the finder and alignment patterns in the image and size. The computePerspectiveTransform method can be used to obtain a PerspectiveTransform object that describes the perspective transformation of the QR code and can be used to transform AR elements accordingly (a to3DPerspectiveMatrix() returns an equivalent 4x4 transformation matrix that can be used for example with the Transform widget or Canvas transform method). Refer to the example for more details on how to use this package for simple AR applications.

Note that the qr code location will be updated if the correct pattern is identified, even if the content cannot be read. To avoid this behavior, you can pass the optional ignoreIfUnreadable parameter. In addition, content will be cached for a certain number of frames in case of decoding errors. This can be controlled with the contentCacheLimit parameter of the QrCode constructor or by passing the invalidateContentCache flag when calling scanRgbaBytes.

Missing features and future developments

  • The package currently supports only a single QR code. Multiple QR codes in the same image will lead to unstable and mostly incorrect results.

  • Many improvements could be made to take advantage of multi-frame scanning, for example to select the best finder patterns based on the previous QR code position, or rejecting evident glitches

  • Performance can be very poor for large images, especially with high noise content

  • Code could be greatly optimized and refactored to comply with Dart best practices (most of the code still closely resembles the original jsQR TypeScript code)

Pull requests are very welcome.

Alessandro Diano GitHub avatar
GitHub 作者

Alessandro Diano ↗

Product Manager at WeTransfer

Bending SpoonsMilano, Italy
語言DartRubySwiftKotlinObjective-C

分類

使用的依賴

依賴清單 7 項

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗