From 9b1e697609e8f9c64158ad66e0cd5b8d681c40ba Mon Sep 17 00:00:00 2001 From: Matthias Jauernig Date: Tue, 22 Mar 2016 09:51:15 +0100 Subject: [PATCH 1/3] new config variable scanDelay to add some time between two scans --- src/quagga.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/quagga.js b/src/quagga.js index ebe5d80..dd8af12 100644 --- a/src/quagga.js +++ b/src/quagga.js @@ -360,21 +360,23 @@ function workerInterface(factory) { var imageWrapper; self.onmessage = function(e) { - if (e.data.cmd === 'init') { - var config = e.data.config; - config.numOfWorkers = 0; - imageWrapper = new Quagga.ImageWrapper({ - x: e.data.size.x, - y: e.data.size.y - }, new Uint8Array(e.data.imageData)); - Quagga.init(config, ready, imageWrapper); - Quagga.onProcessed(onProcessed); - } else if (e.data.cmd === 'process') { - imageWrapper.data = new Uint8Array(e.data.imageData); - Quagga.start(); - } else if (e.data.cmd === 'setReaders') { - Quagga.setReaders(e.data.readers); - } + setTimeout(function() { + if (e.data.cmd === 'init') { + var config = e.data.config; + config.numOfWorkers = 0; + imageWrapper = new Quagga.ImageWrapper({ + x: e.data.size.x, + y: e.data.size.y + }, new Uint8Array(e.data.imageData)); + Quagga.init(config, ready, imageWrapper); + Quagga.onProcessed(onProcessed); + } else if (e.data.cmd === 'process') { + imageWrapper.data = new Uint8Array(e.data.imageData); + Quagga.start(); + } else if (e.data.cmd === 'setReaders') { + Quagga.setReaders(e.data.readers); + } + }, Quagga.getConfig().scanDelay || 0); }; function onProcessed(result) { @@ -516,5 +518,8 @@ export default { }, ImageWrapper: ImageWrapper, ImageDebug: ImageDebug, - ResultCollector: ResultCollector + ResultCollector: ResultCollector, + getConfig: function getConfig() { + return _config; + } }; From 3cf474d484a0af585ea7f0e4338deb0b6dfab052 Mon Sep 17 00:00:00 2001 From: Matthias Jauernig Date: Wed, 23 Mar 2016 21:01:00 +0100 Subject: [PATCH 2/3] scan frequency as proposed by serratus --- src/quagga.js | 62 +++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/quagga.js b/src/quagga.js index dd8af12..495e5f4 100644 --- a/src/quagga.js +++ b/src/quagga.js @@ -296,16 +296,29 @@ function update() { } } -function start() { +function startContinuousUpdate() { + var next = null, + delay = 1000 / (_config.frequency || 60); + _stopped = false; - ( function frame() { + (function frame(timestamp) { + next = next || timestamp; if (!_stopped) { - update(); - if (_onUIThread && _config.inputStream.type === "LiveStream") { - window.requestAnimFrame(frame); + if (timestamp >= next) { + next += delay; + update(); } + window.requestAnimFrame(frame); } - }()); + }(performance.now())); +} + +function start() { + if (_onUIThread && _config.inputStream.type === "LiveStream") { + startContinuousUpdate(); + } else { + update(); + } } function initWorker(cb) { @@ -360,23 +373,21 @@ function workerInterface(factory) { var imageWrapper; self.onmessage = function(e) { - setTimeout(function() { - if (e.data.cmd === 'init') { - var config = e.data.config; - config.numOfWorkers = 0; - imageWrapper = new Quagga.ImageWrapper({ - x: e.data.size.x, - y: e.data.size.y - }, new Uint8Array(e.data.imageData)); - Quagga.init(config, ready, imageWrapper); - Quagga.onProcessed(onProcessed); - } else if (e.data.cmd === 'process') { - imageWrapper.data = new Uint8Array(e.data.imageData); - Quagga.start(); - } else if (e.data.cmd === 'setReaders') { - Quagga.setReaders(e.data.readers); - } - }, Quagga.getConfig().scanDelay || 0); + if (e.data.cmd === 'init') { + var config = e.data.config; + config.numOfWorkers = 0; + imageWrapper = new Quagga.ImageWrapper({ + x: e.data.size.x, + y: e.data.size.y + }, new Uint8Array(e.data.imageData)); + Quagga.init(config, ready, imageWrapper); + Quagga.onProcessed(onProcessed); + } else if (e.data.cmd === 'process') { + imageWrapper.data = new Uint8Array(e.data.imageData); + Quagga.start(); + } else if (e.data.cmd === 'setReaders') { + Quagga.setReaders(e.data.readers); + } }; function onProcessed(result) { @@ -518,8 +529,5 @@ export default { }, ImageWrapper: ImageWrapper, ImageDebug: ImageDebug, - ResultCollector: ResultCollector, - getConfig: function getConfig() { - return _config; - } + ResultCollector: ResultCollector }; From 1116c358c0bb4b57889b9bea24dc78dec1778bcf Mon Sep 17 00:00:00 2001 From: Matthias Jauernig Date: Thu, 24 Mar 2016 21:10:23 +0100 Subject: [PATCH 3/3] bugfix of detection/localization area definition (working for px values) --- src/common/cv_utils.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/common/cv_utils.js b/src/common/cv_utils.js index 18485fd..96e7040 100644 --- a/src/common/cv_utils.js +++ b/src/common/cv_utils.js @@ -698,32 +698,32 @@ CVUtils.calculatePatchSize = function(patchSize, imgSize) { CVUtils._parseCSSDimensionValues = function(value) { var dimension = { value: parseFloat(value), - unit: value.indexOf("%") === value.length - 1 ? "%" : "%" + unit: value.indexOf("%") === value.length - 1 ? "%" : "px" }; return dimension; }; CVUtils._dimensionsConverters = { - top: function(dimension, context) { - if (dimension.unit === "%") { - return Math.floor(context.height * (dimension.value / 100)); - } + top: function top(dimension, context) { + return Math.floor((dimension.unit === "%") + ? (context.height * (dimension.value / 100)) + : dimension.value); }, - right: function(dimension, context) { - if (dimension.unit === "%") { - return Math.floor(context.width - (context.width * (dimension.value / 100))); - } + right: function right(dimension, context) { + return Math.floor((dimension.unit === "%") + ? (context.width - context.width * (dimension.value / 100)) + : (context.width - dimension.value)); }, - bottom: function(dimension, context) { - if (dimension.unit === "%") { - return Math.floor(context.height - (context.height * (dimension.value / 100))); - } + bottom: function bottom(dimension, context) { + return Math.floor((dimension.unit === "%") + ? (context.height - context.height * (dimension.value / 100)) + : (context.height - dimension.value)); }, - left: function(dimension, context) { - if (dimension.unit === "%") { - return Math.floor(context.width * (dimension.value / 100)); - } + left: function left(dimension, context) { + return Math.floor((dimension.unit === "%") + ? (context.width * (dimension.value / 100)) + : dimension.value); } };