Can now operate on scaled/area images

pull/65/head
Christoph Oberhofer 10 years ago
parent e65df1d131
commit abe1458c58

@ -4,7 +4,13 @@ Quagga.decodeSingle({
src: "../test/fixtures/code_128/image-001.jpg",
numOfWorkers: 0,
inputStream: {
size: 640
size: 800,
area: {
top: "10%",
right: "5%",
left: "5%",
bottom: "10%"
}
}
}, function(result) {
if(result.codeResult) {

@ -4,31 +4,28 @@
define(["cv_utils"], function(CVUtils) {
"use strict";
var Ndarray = require("ndarray"),
Interp2D = require("ndarray-linear-interpolate").d2;
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);
_canvasSize = inputStream.getCanvasSize(),
_size = CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()),
topRight = inputStream.getTopRight(),
_data = new Uint8Array(_size.x * _size.y),
_grayData = new Uint8Array(_video_size.x * _video_size.y),
_canvasData = new Uint8Array(_canvasSize.x * _canvasSize.y);
console.log("FrameGrabber", JSON.stringify({
size: _size,
topRight: topRight,
videoSize: _video_size,
canvasSize: _canvasSize
}));
/**
* Uses the given array as frame-buffer
@ -53,17 +50,51 @@ define(["cv_utils"], function(CVUtils) {
frame = inputStream.getFrame();
if (frame) {
if(doHalfSample){
CVUtils.grayAndHalfSampleFromCanvasData(frame.data, _size, _data);
} else {
CVUtils.computeGray(frame.data, _data);
}
this.scaleAndCrop(frame, _video_size, _canvasSize, topRight, _size);
return true;
} else {
return false;
}
};
_that.scaleAndCrop = function(frame, frameSize, canvasSize, topRight, targetSize) {
var grayImageArray = Ndarray(_grayData, [frameSize.y, frameSize.x]).transpose(1, 0),
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;
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
CVUtils.computeGray(frame.data, _grayData);
// 2. interpolate
for (y = 0; y < canvasSize.y; y++) {
for (x = 0; x < canvasSize.x; x++) {
canvasImageArray.set(x, y, (Interp2D(grayImageArray, x*stepSizeX, y*stepSizeY)) | 0);
}
}
// targetImageArray must be equal to targetSize
if (targetImageArray.shape[0] !== targetSize.x ||
targetImageArray.shape[1] !== targetSize.y) {
throw new Error("Shapes do not match!");
}
// 3. crop
for (y = 0; y < targetSize.y; y++) {
for (x = 0; x < targetSize.x; x++) {
_data[y*targetSize.x + x] = targetImageArray.get(x, y);
}
}
},
_that.getSize = function() {
return _size;
};

@ -56,6 +56,8 @@
"license": "MIT",
"dependencies": {
"get-pixels": "^3.2.3",
"gl-matrix": "^2.3.1"
"gl-matrix": "^2.3.1",
"ndarray": "^1.0.18",
"ndarray-linear-interpolate": "^1.0.0"
}
}

@ -4,16 +4,6 @@
define(function() {
"use strict";
Math.imul = Math.imul || function(a, b) {
var ah = (a >>> 16) & 0xffff;
var al = a & 0xffff;
var bh = (b >>> 16) & 0xffff;
var bl = b & 0xffff;
// the shift by 0 fixes the sign on the high part
// the final |0 converts the unsigned value into a signed value
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0);
};
/* @preserve ASM BEGIN */
function Skeletonizer(stdlib, foreign, buffer) {
"use asm";

Loading…
Cancel
Save