QR Code scanner in JS with Open CV and WeChat's Algorithm
QR Code scanner in JS with Open CV and WeChat's Algorithm
QR Code scanner for JavaScript, based on a WebAssembly build of OpenCV and 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.
npm i qr-scanner-wechatimport { scan } from 'qr-scanner-wechat'
const result = await scan(canvas) // Or ImageElementUpon the first call of scan, around 2.5MB gzipped of WebAssembly and models will be loaded asynchronously.
You can also preload them with:
import { ready, scan } from 'qr-scanner-wechat'
await ready()
const result = await scan(canvas)In case you want to scan with streams like camera inputs, here is some code snippet for reference
…It's also possible to do scanning on Node.js. To do so, you'll need some additional transformations to an ImageData-compatible format. We recommend using sharp and here is an example:
import { scan } from 'qrcode-openev-wechat'
import sharp from 'sharp'
const image = sharp('/path/to/image.png') // or Buffer, anything sharp supports
const { data, info } = await image
// .resize(1000) // you can resize first to improve the performance
.ensureAlpha()
.raw()
.toBuffer({
resolveWithObject: true,
})
const result = await scan({
data: Uint8ClampedArray.from(data),
width: info.width,
height: info.height,
})
console.log(result?.text)MIT License © 2023 Anthony Fu
No open issues yet, or sync has not completed.