npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

opencv-qr

v0.7.0

Published

You can use Opencv JS to decode QR codes in photos.

Downloads

19

Readme

OpencvQr

纯JS识别照片或图片中的二维码

本库的主要特点是:

  • 纯前端处理,无须调用后端OCR API等接口;
  • 可处理标准正方形的二维码,最重要的是可以处理照片上的二维码;二维码变形、旋转都可以识别;
  • 基于opencv 编译后的webassembly版本,编译添加了微信开源的wechat_qrcode,有极高的识别率。

在线测试:https://leidenglai.github.io/opencv-js-qrcode/

demo code: leidenglai/opencv-js-qrcode Example · GitHub

加载二维码识别引擎

本库中采用的是自定义编译的opencv库作为继承,添加了三方组件wechat_qrcode微信二维码引擎,并且去掉不需要的库。封装一些基本方法方便使用。

NPM

npm install opencv-qr --save
// ES6 import
import OpencvQr from "opencv-qr";

// CommonJS require
const OpencvQr = require("opencv-qr");

// 加载模型文件,模型文件请自行保存在静态目录
const cvQr = new OpencvQr({
  dw: "http://xxx.com/models/detect.caffemodel",
  sw: "http://xxx.com/models/sr.caffemodel",
});

Browser

也可直接在浏览器中使用

<script src="dist/OpencvQr.js"></script>
<script>
  const cvQr = new OpencvQr({
    dw: "http://xxx.com/models/detect.caffemodel",
    sw: "http://xxx.com/models/sr.caffemodel",
  });
</script>

使用

OpencvQr暴露一个加载方法和三个使用方法, 支持typescript类型 OpencvQr.d.ts

  // 初始化时需自行加载模型文件,模型文件请自行保存为静态文件,不可编译转换
  const cvQr = new OpencvQr({
    dw: "http://xxx.com/models/detect.caffemodel",
    sw: "http://xxx.com/models/sr.caffemodel",
  });

  // 加载canvas中的图像
  const result = cvQr.load("canvasInput");

  // 返回解析结果字符
  const infos = result?.getInfos();
  // 返回解析的二维码截取图像 ImageData
  const images = result?.getImages();
  // 返回已识别的二维码图像相对于原图的位置信息 坐标和宽高
  const sizes = result?.getSizes();

  // 清除加载图片,释放内存
  result?.clear(); 
  // or
  cvQr.clear();

浏览器兼容性:

暨WebAssembly兼容性,基本上现代浏览器都是支持的: