You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.0 KiB
JavaScript
76 lines
2.0 KiB
JavaScript
![]()
10 years ago
|
/* jshint undef: true, unused: true, browser:true, devel: true */
|
||
|
/* global define */
|
||
|
|
||
|
define(["cv_utils"], function(CVUtils) {
|
||
|
"use strict";
|
||
|
|
||
|
var FrameGrabber = {};
|
||
|
|
||
|
FrameGrabber.create = function(inputStream) {
|
||
|
var _that = {},
|
||
|
_streamConfig = inputStream.getConfig(),
|
||
|
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()),
|
||
|
_size =_streamConfig.size ? CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()) : _video_size,
|
||
|
_sx = 0,
|
||
|
_sy = 0,
|
||
|
_dx = 0,
|
||
|
_dy = 0,
|
||
|
_sWidth,
|
||
|
_dWidth,
|
||
|
_sHeight,
|
||
|
_dHeight,
|
||
|
_canvas = null,
|
||
|
_ctx = null,
|
||
|
_data = null;
|
||
|
|
||
|
_sWidth = _video_size.x;
|
||
|
_dWidth = _size.x;
|
||
|
_sHeight = _video_size.y;
|
||
|
_dHeight = _size.y;
|
||
|
|
||
|
_data = new Uint8Array(_size.x * _size.y);
|
||
|
|
||
|
/**
|
||
|
* Uses the given array as frame-buffer
|
||
|
*/
|
||
|
_that.attachData = function(data) {
|
||
|
_data = data;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Returns the used frame-buffer
|
||
|
*/
|
||
|
_that.getData = function() {
|
||
|
return _data;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Fetches a frame from the input-stream and puts into the frame-buffer.
|
||
|
* The image-data is converted to gray-scale and then half-sampled if configured.
|
||
|
*/
|
||
|
_that.grab = function() {
|
||
|
var doHalfSample = _streamConfig.halfSample,
|
||
|
frame = inputStream.getFrame();
|
||
|
|
||
|
if (frame) {
|
||
|
if(doHalfSample){
|
||
|
CVUtils.grayAndHalfSampleFromCanvasData(frame.data, _size, _data);
|
||
|
} else {
|
||
|
CVUtils.computeGray(frame.data, _data);
|
||
|
}
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
_that.getSize = function() {
|
||
|
return _size;
|
||
|
};
|
||
|
|
||
|
return _that;
|
||
|
};
|
||
|
|
||
|
return (FrameGrabber);
|
||
|
});
|