From 52e672b0949d68fed080638282f63c54b442aba4 Mon Sep 17 00:00:00 2001 From: Rafael Date: Tue, 19 Nov 2024 14:10:27 +0000 Subject: [PATCH] chore: bw images on xwing --- lib/scanner-node.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/scanner-node.js b/lib/scanner-node.js index 80509ad84..f84bd362d 100644 --- a/lib/scanner-node.js +++ b/lib/scanner-node.js @@ -4,6 +4,7 @@ const Pdf417Parser = require('./compliance/parsepdf417') const { utils: coinUtils } = require('@lamassu/coins') const { cameraExists, stream } = require('./capture/streamer/v4l2camera') const scanner = require('./capture/scanner/zxing') +const sharp = require('sharp') const DEFAULT_FPS = 10 const DEFAULT_DELAYEDSHOT_DELAY = 3 @@ -138,7 +139,7 @@ const capture = (device, config, returnCallback, stillsCallback, process) => { activeStream.on('close', externallyClosedHandler) - activeStream.on('data', async (frame) => { + activeStream.on('data', async (frame) => { if (processing) return processing = true const result = await process(frame) @@ -168,7 +169,8 @@ const scanPDF417 = (resultCallback, idCardStillsCallback) => { const device = getCameraDevice(mode) capture(device, {}, resultCallback, idCardStillsCallback, async frame => { - const result = await scanner.scanPDF417(frame) + const bwFrame = await sharp(frame).greyscale().toBuffer() + const result = await scanner.scanPDF417(bwFrame) return result ? Pdf417Parser.parse(result) : null }) } @@ -177,7 +179,11 @@ const scanQR = (resultCallback) => { const mode = 'qr' const device = getCameraDevice(mode) - capture(device, {}, resultCallback, _.noop, scanner.scanQRcode) + capture(device, {}, resultCallback, _.noop, async frame => { + const bwFrame = await sharp(frame).greyscale().toBuffer() + return scanner.scanQRcode(bwFrame) + } + ) } const scanMainQR = (cryptoCode, qrStillsCallback, resultCallback) => { @@ -185,7 +191,8 @@ const scanMainQR = (cryptoCode, qrStillsCallback, resultCallback) => { const device = getCameraDevice(mode) capture(device, {}, resultCallback, qrStillsCallback, async frame => { - const code = await scanner.scanQRcode(frame) + const bwFrame = await sharp(frame).greyscale().toBuffer() + const code = await scanner.scanQRcode(bwFrame) const network = 'main' if (!code) return null