mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Making patch-size configurable; Added Image-Dimensions constraint
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -31,6 +31,7 @@ define(function(){
|
||||
},
|
||||
locator: {
|
||||
halfSample: true,
|
||||
patchSize: 32,
|
||||
showCanvas: false,
|
||||
showPatches: false,
|
||||
showFoundPatches: false,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user