- 小程序编译后的opencv.js和opencv_js.wasm.br需要改什么才能用?
我把WebAssembly改成了WXWebAssembly,onRuntimeInitialized没有被触发。 const cv = require('../../opencv/opencv.js'); onLoad: async function (options) { var _that = this console.log(1); cv['onRuntimeInitialized'] = () => { console.log(3); _that.imread(_that.data.src).then(res => { _that.imshow("src", res) }) _that.removeBg() }; console.log(2); }, function instantiateArrayBuffer(receiver) { return getBinaryPromise() .then(function (binary) { //return WXWebAssembly.instantiate(binary, info); return WXWebAssembly.instantiate( "/opencv/opencv_js.wasm.br", info ); }) .then(receiver, function (reason) { err( "failed to asynchronously prepare wasm: " + reason ); abort(reason); }); } instantiateAsync方法: var result = WXWebAssembly.instantiate( "/opencv/opencv_js.wasm.br", info ); return result.then( receiveInstantiatedSource, function (reason) { err("wasm streaming compile failed: " + reason); err( "falling back to ArrayBuffer instantiation" ); return instantiateArrayBuffer( receiveInstantiatedSource ); } );
05-04 - 小程序如何使用typescript?
import { MultiFormatReader } from '../../utils/src/index.ts'; 已确保index.ts中有 export { default as MultiFormatReader } from './core/MultiFormatReader'; 提示: 页面【pages/qrcode/qrcode]错误: Error: module 'utils/src/index.ts.js' is not defined, require args is '../../utils/src/index.ts'
04-23 - 小程序接入zxing(@zxing/library)无法识别二维码,有人成功过吗?
decode方法报错,Error decoding QR code: e: No MultiFormat Readers were able to detect the code. 对图片截取出二维码或者用选取手机相册的二维码也是一样,二维码没问题 下面是源码 onReady() { this.ctx = wx.createCameraContext(); this.setZoom(); this.listener = this.ctx.onCameraFrame(this.processFrame.bind(this)); this.listener.start(); }, processFrame(frame) { const { width, height, data } = frame; this.setData({ cutSize: height }); /* 对当前帧的视频流进行处理 */ let imageData = new Uint8ClampedArray(data); let result = null try { // 检查数据长度是否符合预期:width * height * 4 if (imageData.length !== width * height * 4) { console.error('图像数据尺寸不匹配'); return; } const reader = new MultiFormatReader(); const luminanceSource = new RGBLuminanceSource(imageData, width, height); const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource)); const hints = new Map(); // 修改 hints 配置 hints.set(DecodeHintType.TRY_HARDER, true); // 深度扫描 hints.set(DecodeHintType.POSSIBLE_FORMATS, [BarcodeFormat.QR_CODE]); // 限定格式 hints.set(DecodeHintType.PURE_BARCODE, true); // 假设整个图像就是二维码 hints.set(DecodeHintType.CHARACTER_SET, 'UTF-8'); // 指定字符集 hints.set(DecodeHintType.ALSO_INVERTED, true); // 允许反转颜色 result = reader.decode(binaryBitmap, hints); this.setData({ scanResult: result.getText() }); //this.stopScan(); } catch (e) { console.log('Error decoding QR code:', e); this.setData({ scanResult: e.message }); } const ctxZO = wx.createCanvasContext('cutCanvasZO'); wx.canvasPutImageData({ canvasId: 'cutCanvasZO', x: 0, y: 0, width: width, height: height, data: imageData, success: () => {}, fail: (err) => { console.error('croppedData 失败', err); } }); },
04-22