|
|
@ -15,17 +15,23 @@ define(["cv_utils"], function(CVUtils) {
|
|
|
|
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()),
|
|
|
|
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()),
|
|
|
|
_canvasSize = inputStream.getCanvasSize(),
|
|
|
|
_canvasSize = inputStream.getCanvasSize(),
|
|
|
|
_size = CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()),
|
|
|
|
_size = CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()),
|
|
|
|
topRight = inputStream.getTopRight(),
|
|
|
|
_topRight = inputStream.getTopRight(),
|
|
|
|
_data = new Uint8Array(_size.x * _size.y),
|
|
|
|
_data = new Uint8Array(_size.x * _size.y),
|
|
|
|
_grayData = new Uint8Array(_video_size.x * _video_size.y),
|
|
|
|
_grayData = new Uint8Array(_video_size.x * _video_size.y),
|
|
|
|
_canvasData = new Uint8Array(_canvasSize.x * _canvasSize.y);
|
|
|
|
_canvasData = new Uint8Array(_canvasSize.x * _canvasSize.y),
|
|
|
|
|
|
|
|
_grayImageArray = Ndarray(_grayData, [_video_size.y, _video_size.x]).transpose(1, 0),
|
|
|
|
|
|
|
|
_canvasImageArray = Ndarray(_canvasData, [_canvasSize.y, _canvasSize.x]).transpose(1, 0),
|
|
|
|
|
|
|
|
_targetImageArray = _canvasImageArray.hi(_topRight.x + _size.x, _topRight.y + _size.y).lo(_topRight.x, _topRight.y),
|
|
|
|
|
|
|
|
_stepSizeX = _video_size.x/_canvasSize.x,
|
|
|
|
|
|
|
|
_stepSizeY = _video_size.y/_canvasSize.y;
|
|
|
|
|
|
|
|
|
|
|
|
console.log("FrameGrabber", JSON.stringify({
|
|
|
|
console.log("FrameGrabber", JSON.stringify({
|
|
|
|
size: _size,
|
|
|
|
videoSize: _grayImageArray.shape,
|
|
|
|
topRight: topRight,
|
|
|
|
canvasSize: _canvasImageArray.shape,
|
|
|
|
videoSize: _video_size,
|
|
|
|
stepSize: [_stepSizeX, _stepSizeY],
|
|
|
|
canvasSize: _canvasSize
|
|
|
|
size: _targetImageArray.shape,
|
|
|
|
}));
|
|
|
|
topRight: _topRight
|
|
|
|
|
|
|
|
}, null, 2));
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Uses the given array as frame-buffer
|
|
|
|
* Uses the given array as frame-buffer
|
|
|
@ -46,51 +52,40 @@ define(["cv_utils"], function(CVUtils) {
|
|
|
|
* The image-data is converted to gray-scale and then half-sampled if configured.
|
|
|
|
* The image-data is converted to gray-scale and then half-sampled if configured.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
_that.grab = function() {
|
|
|
|
_that.grab = function() {
|
|
|
|
var doHalfSample = _streamConfig.halfSample,
|
|
|
|
var frame = inputStream.getFrame();
|
|
|
|
frame = inputStream.getFrame();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (frame) {
|
|
|
|
if (frame) {
|
|
|
|
this.scaleAndCrop(frame, _video_size, _canvasSize, topRight, _size);
|
|
|
|
this.scaleAndCrop(frame);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_that.scaleAndCrop = function(frame, frameSize, canvasSize, topRight, targetSize) {
|
|
|
|
_that.scaleAndCrop = function(frame) {
|
|
|
|
var grayImageArray = Ndarray(_grayData, [frameSize.y, frameSize.x]).transpose(1, 0),
|
|
|
|
var x,
|
|
|
|
canvasImageArray = Ndarray(_canvasData, [canvasSize.y, canvasSize.x]).transpose(1, 0),
|
|
|
|
|
|
|
|
targetImageArray = canvasImageArray.hi(topRight.x + targetSize.x, topRight.y + targetSize.y).lo(topRight.x, topRight.y),
|
|
|
|
|
|
|
|
stepSizeX = frameSize.x/canvasSize.x,
|
|
|
|
|
|
|
|
stepSizeY = frameSize.y/canvasSize.y,
|
|
|
|
|
|
|
|
x,
|
|
|
|
|
|
|
|
y;
|
|
|
|
y;
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Input-size: ", grayImageArray.shape);
|
|
|
|
|
|
|
|
console.log("Canvas-size: ", canvasImageArray.shape);
|
|
|
|
|
|
|
|
console.log("Target-size: ", targetImageArray.shape);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Step-size: ", [stepSizeX, stepSizeY]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1. compute full-sized gray image
|
|
|
|
// 1. compute full-sized gray image
|
|
|
|
CVUtils.computeGray(frame.data, _grayData);
|
|
|
|
CVUtils.computeGray(frame.data, _grayData);
|
|
|
|
|
|
|
|
|
|
|
|
// 2. interpolate
|
|
|
|
// 2. interpolate
|
|
|
|
for (y = 0; y < canvasSize.y; y++) {
|
|
|
|
for (y = 0; y < _canvasSize.y; y++) {
|
|
|
|
for (x = 0; x < canvasSize.x; x++) {
|
|
|
|
for (x = 0; x < _canvasSize.x; x++) {
|
|
|
|
canvasImageArray.set(x, y, (Interp2D(grayImageArray, x*stepSizeX, y*stepSizeY)) | 0);
|
|
|
|
_canvasImageArray.set(x, y, (Interp2D(_grayImageArray, x * _stepSizeX, y * _stepSizeY)) | 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// targetImageArray must be equal to targetSize
|
|
|
|
// targetImageArray must be equal to targetSize
|
|
|
|
if (targetImageArray.shape[0] !== targetSize.x ||
|
|
|
|
if (_targetImageArray.shape[0] !== _size.x ||
|
|
|
|
targetImageArray.shape[1] !== targetSize.y) {
|
|
|
|
_targetImageArray.shape[1] !== _size.y) {
|
|
|
|
throw new Error("Shapes do not match!");
|
|
|
|
throw new Error("Shapes do not match!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 3. crop
|
|
|
|
// 3. crop
|
|
|
|
for (y = 0; y < targetSize.y; y++) {
|
|
|
|
for (y = 0; y < _size.y; y++) {
|
|
|
|
for (x = 0; x < targetSize.x; x++) {
|
|
|
|
for (x = 0; x < _size.x; x++) {
|
|
|
|
_data[y*targetSize.x + x] = targetImageArray.get(x, y);
|
|
|
|
_data[y * _size.x + x] = _targetImageArray.get(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|