mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Added tests for image-size calculation
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user