This package has been deprecated

Author message:

qrcode-opencv-wechat is renamed to qr-scanner-wechat

qrcode-opencv-wechat
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

qrcode-opencv-wechat

NPM version

QR Code scanner in JavaScript, based on a WebAssembly build of OpenCV with Open CV WeChat QR Code Scanner. Provides a much better detection rate and error tolerance.

Ported and rewritten from leidenglai/opencv-js-qrcode for modern browser build and easier usage. Huge thanks to @leidenglai for the previous work and research.

Usage

npm i qrcode-opencv-wechat
import { scan } from 'qrcode-opencv-wechat'

const result = await scan(canvas) // Or ImageElement

Upon the first call of scan, around 3.5MB gzipped of WebAssembly and models will be loaded asynchronously.

You can also preload them with:

import { ready, scan } from 'qrcode-opencv-wechat'

await ready()
const result = await scan(canvas)

Stream

In case you want to scan with streams like camera inputs, here is some code snippet for reference

<video id="video">
import { scan } from 'qrcode-opencv-wechat'

const stream = await navigator.mediaDevices.getUserMedia({
  audio: false,
  video: {
    width: 512,
    height: 512,
  },
})

const video = document.getElementById('video')
video.srcObject = stream
video.play()

async function scanFrame() {
  const canvas = document.createElement('canvas')
  canvas.width = video.value.videoWidth
  canvas.height = video.value.videoHeight
  const ctx = canvas.getContext('2d')
  ctx.drawImage(videoEl.value!, 0, 0, canvas.width, canvas.height)
  const result = await scan(canvas)

  if (result?.text)
    alert(result?.text)
}

setInterval(scanFrame, 100) // scan one frame every 100ms

Sponsors

License

MIT License © 2023 Anthony Fu

Readme

Keywords

none

Package Sidebar

Install

npm i qrcode-opencv-wechat

Weekly Downloads

22,155

Version

0.0.2

License

MIT

Unpacked Size

6.31 MB

Total Files

7

Last publish

Collaborators

  • antfu