diff --git a/src/barcode_locator.js b/src/barcode_locator.js index 7c13663..31dc639 100644 --- a/src/barcode_locator.js +++ b/src/barcode_locator.js @@ -40,8 +40,8 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I } _patchSize = { - x : 16 * ( _config.halfSample ? 1 : 2), - y : 16 * ( _config.halfSample ? 1 : 2) + x : _config.patchSize * ( _config.halfSample ? 0.5 : 1), + y : _config.patchSize * ( _config.halfSample ? 0.5 : 1) }; _numPatches.x = _currentImageWrapper.size.x / _patchSize.x | 0; diff --git a/src/config.js b/src/config.js index 99daa04..1c5f41e 100644 --- a/src/config.js +++ b/src/config.js @@ -31,6 +31,7 @@ define(function(){ }, locator: { halfSample: true, + patchSize: 32, showCanvas: false, showPatches: false, showFoundPatches: false, diff --git a/src/quagga.js b/src/quagga.js index 849f3ba..6d9319b 100644 --- a/src/quagga.js +++ b/src/quagga.js @@ -82,7 +82,24 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba _inputStream.addEventListener("canrecord", canRecord.bind(undefined, cb)); } + function checkImageConstraints() { + var patchSize, + width = _inputStream.getWidth(), + height = _inputStream.getHeight(); + + if (_config.locate) { + patchSize = _config.locator.patchSize * ( _config.locator.halfSample ? 0.5 : 1); + if ((width % patchSize) === 0 && (height % patchSize) === 0) { + return true; + } + } + throw new Error("Image dimensions do not comply with the current settings: Width (" + + width + " )and height (" + height + + ") must a multiple of " + patchSize); + } + function canRecord(cb) { + checkImageConstraints(); initCanvas(); _framegrabber = FrameGrabber.create(_inputStream, _canvasContainer.dom.image); initConfig(); @@ -384,6 +401,10 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba size: 800 }; config.numOfWorkers = 1; + config.locator = { + halfSample: false, + patchSize: 25 + }; this.init(config, function() { Events.once("detected", function(result) { _stopped = true;