这个识别库原本是上传图片后再识别的,但项目需要调取摄像头,调取摄像头的话就势必要频繁抓取图像用于识别
不使用jsQR或zxing也是因为不支持同时多二维码识别
Barcode Detection API可以直接用视频流识别多二维码,但识别率低
只有这个库识别率高
使用的识别库
getImgQRCodeInfo error RuntimeError: Aborted(). Build with -sASSERTIONS for more info.
at abort (VM3270 opencv.js:404:15)
at _abort (VM3270 opencv.js:5393:7)
at 00dfaa9e:0x4f03
at 00dfaa9e:0x1f8010
at 00dfaa9e:0x200365
at Mat.constructor$Mat (eval at new_ (VM3270 opencv.js:1:1), <anonymous>:10:10)
at Mat.eval (VM3270 opencv.js:4540:23)
at new Mat (eval at createNamedFunction (VM3270 opencv.js:1:1), <anonymous>:4:34)
at Module.matFromImageData (VM3270 opencv.js:6464:17)
at Module.imread (VM3270 opencv.js:6137:17)
// options.img我改成HTMLCanvasElement类型
const mat = openCV.imread(options.img);
const detector = new openCV.wechat_qrcode_WeChatQRCode(
"detect.prototxt",
"detect.caffemodel",
"sr.prototxt",
"sr.caffemodel"
);
const matVector = new openCV.MatVector();
const results = detector.detectAndDecode(mat, matVector);
// ...其他代码
// 原本index.ts中的Mat没有delete,我加了一个delete(...args: any): any;
// opencv官方的delete,释放内存
mat.delete()
matVector.delete()
这个泄漏不知道是不是库内部的。我之前用 sharp 也会有类似的问题。
暂时没找到合理的解决方案。说一些暴力的吧
对了还有一个点,注意有没有 bloburl 没释放