mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Can now operate on scaled/area images
This commit is contained in:
@@ -4,7 +4,13 @@ Quagga.decodeSingle({
|
|||||||
src: "../test/fixtures/code_128/image-001.jpg",
|
src: "../test/fixtures/code_128/image-001.jpg",
|
||||||
numOfWorkers: 0,
|
numOfWorkers: 0,
|
||||||
inputStream: {
|
inputStream: {
|
||||||
size: 640
|
size: 800,
|
||||||
|
area: {
|
||||||
|
top: "10%",
|
||||||
|
right: "5%",
|
||||||
|
left: "5%",
|
||||||
|
bottom: "10%"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
if(result.codeResult) {
|
if(result.codeResult) {
|
||||||
|
|||||||
+54
-23
@@ -4,31 +4,28 @@
|
|||||||
define(["cv_utils"], function(CVUtils) {
|
define(["cv_utils"], function(CVUtils) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var Ndarray = require("ndarray"),
|
||||||
|
Interp2D = require("ndarray-linear-interpolate").d2;
|
||||||
|
|
||||||
var FrameGrabber = {};
|
var FrameGrabber = {};
|
||||||
|
|
||||||
FrameGrabber.create = function(inputStream) {
|
FrameGrabber.create = function(inputStream) {
|
||||||
var _that = {},
|
var _that = {},
|
||||||
_streamConfig = inputStream.getConfig(),
|
_streamConfig = inputStream.getConfig(),
|
||||||
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()),
|
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()),
|
||||||
_size =_streamConfig.size ? CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()) : _video_size,
|
_canvasSize = inputStream.getCanvasSize(),
|
||||||
_sx = 0,
|
_size = CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()),
|
||||||
_sy = 0,
|
topRight = inputStream.getTopRight(),
|
||||||
_dx = 0,
|
_data = new Uint8Array(_size.x * _size.y),
|
||||||
_dy = 0,
|
_grayData = new Uint8Array(_video_size.x * _video_size.y),
|
||||||
_sWidth,
|
_canvasData = new Uint8Array(_canvasSize.x * _canvasSize.y);
|
||||||
_dWidth,
|
|
||||||
_sHeight,
|
|
||||||
_dHeight,
|
|
||||||
_canvas = null,
|
|
||||||
_ctx = null,
|
|
||||||
_data = null;
|
|
||||||
|
|
||||||
_sWidth = _video_size.x;
|
console.log("FrameGrabber", JSON.stringify({
|
||||||
_dWidth = _size.x;
|
size: _size,
|
||||||
_sHeight = _video_size.y;
|
topRight: topRight,
|
||||||
_dHeight = _size.y;
|
videoSize: _video_size,
|
||||||
|
canvasSize: _canvasSize
|
||||||
_data = new Uint8Array(_size.x * _size.y);
|
}));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the given array as frame-buffer
|
* Uses the given array as frame-buffer
|
||||||
@@ -53,17 +50,51 @@ define(["cv_utils"], function(CVUtils) {
|
|||||||
frame = inputStream.getFrame();
|
frame = inputStream.getFrame();
|
||||||
|
|
||||||
if (frame) {
|
if (frame) {
|
||||||
if(doHalfSample){
|
this.scaleAndCrop(frame, _video_size, _canvasSize, topRight, _size);
|
||||||
CVUtils.grayAndHalfSampleFromCanvasData(frame.data, _size, _data);
|
|
||||||
} else {
|
|
||||||
CVUtils.computeGray(frame.data, _data);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
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() {
|
_that.getSize = function() {
|
||||||
return _size;
|
return _size;
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-1
@@ -56,6 +56,8 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"get-pixels": "^3.2.3",
|
"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() {
|
define(function() {
|
||||||
"use strict";
|
"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 */
|
/* @preserve ASM BEGIN */
|
||||||
function Skeletonizer(stdlib, foreign, buffer) {
|
function Skeletonizer(stdlib, foreign, buffer) {
|
||||||
"use asm";
|
"use asm";
|
||||||
|
|||||||
Reference in New Issue
Block a user