Added tests for image-size calculation

This commit is contained in:
Christoph Oberhofer
2015-06-07 19:01:44 +02:00
parent 89da5cc4e7
commit 7bb34b546b
5 changed files with 111 additions and 37 deletions
+25
View File
@@ -486,6 +486,7 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
initBuffers();
initCanvas();
},
locate : function() {
var patchesFound,
topLabels = [],
@@ -516,6 +517,30 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
boxes = findBoxes(topLabels, maxLabel);
return boxes;
},
checkImageConstraints: function(inputStream, config) {
var patchSize,
width = inputStream.getWidth(),
height = inputStream.getHeight(),
halfSample = config.halfSample ? 0.5 : 1,
size = {
x: Math.floor(width * halfSample),
y: Math.floor(height * halfSample)
};
patchSize = CVUtils.calculatePatchSize(config.patchSize, size);
inputStream.setWidth(Math.floor(Math.floor(size.x/patchSize.x)*(1/halfSample)*patchSize.x));
inputStream.setHeight(Math.floor(Math.floor(size.y/patchSize.y)*(1/halfSample)*patchSize.y));
console.log("Patch-Size: " + JSON.stringify(patchSize));
if ((inputStream.getWidth() % patchSize.x) === 0 && (inputStream.getHeight() % patchSize.y) === 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.x);
}
};
});
-1
View File
@@ -647,7 +647,6 @@ define(['cluster', 'glMatrixAddon', "array_helper"], function(Cluster2, glMatrix
optimalPatchSize = findPatchSizeForDivisors(common);
if (!optimalPatchSize) {
optimalPatchSize = findPatchSizeForDivisors(this._computeDivisors(wideSide));
throw new AdjustToSizeError("", optimalPatchSize);
}
return optimalPatchSize;
};
+5 -36
View File
@@ -14,8 +14,7 @@ define([
"config",
"events",
"camera_access",
"image_debug",
"cv_utils"],
"image_debug"],
function(Code128Reader,
EANReader,
InputStream,
@@ -27,8 +26,7 @@ function(Code128Reader,
_config,
Events,
CameraAccess,
ImageDebug,
CVUtils) {
ImageDebug) {
"use strict";
var _inputStream,
@@ -107,39 +105,10 @@ function(Code128Reader,
_inputStream.addEventListener("canrecord", canRecord.bind(undefined, cb));
}
function checkImageConstraints() {
var patchSize,
width = _inputStream.getWidth(),
height = _inputStream.getHeight(),
halfSample = _config.locator.halfSample ? 0.5 : 1,
size = {
x: Math.floor(width * halfSample),
y: Math.floor(height * halfSample)
};
if (_config.locate) {
try {
console.log(size);
patchSize = CVUtils.calculatePatchSize(_config.locator.patchSize, size);
} catch (error) {
if (error instanceof CVUtils.AdjustToSizeError) {
_inputStream.setWidth(Math.floor(Math.floor(size.x/error.patchSize.x)*(1/halfSample)*error.patchSize.x));
_inputStream.setHeight(Math.floor(Math.floor(size.y/error.patchSize.y)*(1/halfSample)*error.patchSize.y));
patchSize = error.patchSize;
}
}
console.log("Patch-Size: " + JSON.stringify(patchSize));
if ((_inputStream.getWidth() % patchSize.x) === 0 && (_inputStream.getHeight() % patchSize.y) === 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.x);
}
function canRecord(cb) {
checkImageConstraints();
if (_config.locate) {
BarcodeLocator.checkImageConstraints(_inputStream, _config.locator);
}
initCanvas();
_framegrabber = FrameGrabber.create(_inputStream, _canvasContainer.dom.image);
initConfig();