This commit is contained in:
Christoph Oberhofer
2015-05-09 16:05:18 +02:00
parent 0e0cfcea00
commit 76e61bc4c4
8 changed files with 178 additions and 100 deletions
+46 -18
View File
@@ -579,31 +579,59 @@ define(['cluster', 'glMatrixAddon', "array_helper"], function(Cluster2, glMatrix
divisorsY = this._computeDivisors(imgSize.y),
wideSide = Math.max(imgSize.x, imgSize.y),
common = this._computeIntersection(divisorsX, divisorsY),
nrOfPatchesList = [8, 10, 15, 20, 32, 60, 80],
nrOfPatchesMap = {
"x-small": 60,
"small": 32,
"medium": 20,
"large": 15,
"x-large": 10
"x-small": 5,
"small": 4,
"medium": 3,
"large": 2,
"x-large": 1
},
nrOfPatches = nrOfPatchesMap[patchSize] || nrOfPatchesMap.medium,
i = 0,
found = common[Math.floor(common.length/2)],
desiredPatchSize = wideSide/nrOfPatches;
nrOfPatchesIdx = nrOfPatchesMap[patchSize] || nrOfPatchesMap.medium,
nrOfPatches = nrOfPatchesList[nrOfPatchesIdx],
desiredPatchSize = Math.floor(wideSide/nrOfPatches),
optimalPatchSize;
while(i < (common.length - 1) && common[i] < desiredPatchSize) {
i++;
}
if (i > 0) {
if (Math.abs(common[i] - desiredPatchSize) > Math.abs(common[i-1] - desiredPatchSize)) {
found = common[i-1];
} else {
found = common[i];
function findPatchSizeForDivisors(divisors) {
var i = 0,
found = divisors[Math.floor(divisors.length/2)];
while(i < (divisors.length - 1) && divisors[i] < desiredPatchSize) {
i++;
}
if (i > 0) {
if (Math.abs(divisors[i] - desiredPatchSize) > Math.abs(divisors[i-1] - desiredPatchSize)) {
found = divisors[i-1];
} else {
found = divisors[i];
}
}
if (desiredPatchSize / found < nrOfPatchesList[nrOfPatchesIdx+1] / nrOfPatchesList[nrOfPatchesIdx] &&
desiredPatchSize / found > nrOfPatchesList[nrOfPatchesIdx-1]/nrOfPatchesList[nrOfPatchesIdx] ) {
return {x: found, y: found};
}
return null;
}
return {x: found, y: found};
optimalPatchSize = findPatchSizeForDivisors(common);
if (!optimalPatchSize) {
optimalPatchSize = findPatchSizeForDivisors(this._computeDivisors(wideSide));
throw new AdjustToSizeError("", optimalPatchSize);
}
return optimalPatchSize;
};
function AdjustToSizeError(message, desiredPatchSize) {
this.name = 'AdjustToSizeError';
this.message = message || 'AdjustToSizeError';
this.patchSize = desiredPatchSize;
}
AdjustToSizeError.prototype = Object.create(RangeError.prototype);
AdjustToSizeError.prototype.constructor = AdjustToSizeError;
CVUtils.AdjustToSizeError = AdjustToSizeError;
return (CVUtils);
});
+1 -12
View File
@@ -10,7 +10,7 @@ define(["cv_utils"], function(CVUtils) {
var _that = {},
_streamConfig = inputStream.getConfig(),
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()),
_size =_streamConfig.size ? CVUtils.imageRef(_streamConfig.size, _streamConfig.size) : _video_size,
_size =_streamConfig.size ? CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()) : _video_size,
_sx = 0,
_sy = 0,
_dx = 0,
@@ -23,17 +23,6 @@ define(["cv_utils"], function(CVUtils) {
_ctx = null,
_data = null;
// Check if size is given
if (_streamConfig.size) {
if (_video_size.x/_video_size.y > 1) {
_size.x = _streamConfig.size;
_size.y = (_video_size.y/_video_size.x)*_streamConfig.size;
} else {
_size.y = _streamConfig.size;
_size.x = (_video_size.x/_video_size.y)*_streamConfig.size;
}
}
_sWidth = _video_size.x;
_dWidth = _size.x;
_sHeight = _video_size.y;
+14 -2
View File
@@ -130,6 +130,8 @@ define(["image_loader"], function(ImageLoader) {
offset = 1,
baseUrl = null,
ended = false,
calculatedWidth,
calculatedHeight,
_eventNames = ['canrecord', 'ended'],
_eventHandlers = {};
@@ -139,6 +141,8 @@ define(["image_loader"], function(ImageLoader) {
imgArray = imgs;
width = imgs[0].width;
height = imgs[0].height;
calculatedWidth = _config.size ? width/height > 1 ? _config.size : Math.floor((width/height) * _config.size) : width;
calculatedHeight = _config.size ? width/height > 1 ? Math.floor((height/width) * _config.size) : _config.size : height;
loaded = true;
frameIdx = 0;
setTimeout(function() {
@@ -162,11 +166,19 @@ define(["image_loader"], function(ImageLoader) {
that.trigger = publishEvent;
that.getWidth = function() {
return _config.size ? width/height > 1 ? _config.size : (width/height) * _config.size : width;
return calculatedWidth;
};
that.getHeight = function() {
return _config.size ? width/height > 1 ? (height/width) * _config.size : _config.size : height;
return calculatedHeight;
};
that.setWidth = function(width) {
calculatedWidth = width;
};
that.setHeight = function(height) {
calculatedHeight = height;
};
that.getRealWidth = function() {
+10 -2
View File
@@ -118,9 +118,17 @@ function(Code128Reader,
};
if (_config.locate) {
patchSize = CVUtils.calculatePatchSize(_config.locator.patchSize, size);
try {
patchSize = CVUtils.calculatePatchSize(_config.locator.patchSize, size);
} catch (error) {
if (error instanceof CVUtils.AdjustToSizeError) {
_inputStream.setWidth(Math.floor(width/error.patchSize.x)*error.patchSize.x);
_inputStream.setHeight(Math.floor(height/error.patchSize.y)*error.patchSize.y);
patchSize = error.patchSize;
}
}
console.log("Patch-Size: " + JSON.stringify(patchSize));
if ((width % patchSize.x) === 0 && (height % patchSize.y) === 0) {
if ((_inputStream.getWidth() % patchSize.x) === 0 && (_inputStream.getHeight() % patchSize.y) === 0) {
return true;
}
}