gruhn / barcode-detector

Spec compliant polyfill of the Barcode Detection API 🀳

Home Page:https://gruhn.github.io/barcode-detector/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

☝️ package ownership transfered to @Sec-ant. Development continues at @sec-ant/barcode-detector ☝️

BarcodeDetector Polyfill

Spec compliant polyfill of the Barcode Detection API. It can be used for barcode/QR-code recognition in images from various kinds of sources including <canvas>, <img>, <image> (inside SVGs), <video>, File, Blob, ImageData, ImageBitmap, OffscreenCanvas.

simple demo

Design goals:

  • spec compliance
  • support as many barcode formats as possible
  • detect multiple codes in one image
  • provide position/coordinate information of detected codes
  • sufficient performance to process live video streams

Installation

npm install barcode-detector
import BarcodeDetector from "barcode-detector"

// polyfill unless already supported
if (!("BarcodeDetector" in window)) {
  window.BarcodeDetector = BarcodeDetector
}

Usage

// pick barcode formats. Other formats will be ignored
const barcodeDetector = new BarcodeDetector({ formats: ["qr_code"] })

// directly pass an image element, video element, ...
const barcodes = await barcodeDetector.detect(someImageSource)

// can detect multiple barcodes in one image
const [ barcode1, barcode2, ...evenMoreBarcodes ] = barcodes

// access encoded string
const { rawValue } = barcode1

For in-depth documentation checkout the corresponding MDN page.

Supported Formats

src/BarcodeDetectorJsqr.ts:

  • ❌ aztec
  • ❌ code_128
  • ❌ code_39
  • ❌ code_93
  • ❌ codabar
  • ❌ data_matrix
  • ❌ ean_13
  • ❌ ean_8
  • ❌ itf
  • ❌ pdf417
  • βœ”οΈ qr_code
  • ❌ upc_a
  • ❌ upc_e

src/BarcodeDetectorZXing.ts (not exposed at the moment. See #1):

  • βœ”οΈ aztec
  • βœ”οΈ code_128
  • βœ”οΈ code_39
  • ❌ code_93
  • ❌ codabar
  • βœ”οΈ data_matrix
  • βœ”οΈ ean_13
  • βœ”οΈ ean_8
  • βœ”οΈ itf
  • βœ”οΈ pdf417
  • βœ”οΈ qr_code
  • ❌ upc_a
  • ❌ upc_e

About

Spec compliant polyfill of the Barcode Detection API 🀳

https://gruhn.github.io/barcode-detector/

License:MIT License


Languages

Language:TypeScript 84.8%Language:HTML 11.1%Language:Shell 3.1%Language:Dockerfile 1.0%