version for node working

This commit is contained in:
Christoph Oberhofer
2015-10-08 01:41:20 +02:00
parent 9295e41655
commit 6a56d7a1c2
10 changed files with 8762 additions and 963 deletions
+696 -701
View File
File diff suppressed because it is too large Load Diff
+3 -4
View File
File diff suppressed because one or more lines are too long
+89 -95
View File
@@ -1,101 +1,95 @@
/* jshint undef: true, unused: true, browser:true, devel: true */ const CVUtils = require('../src/cv_utils'),
/* global define */ Ndarray = require("ndarray"),
Interp2D = require("ndarray-linear-interpolate").d2;
define(["cv_utils"], function(CVUtils) { var FrameGrabber = {};
"use strict";
var Ndarray = require("ndarray"), FrameGrabber.create = function(inputStream) {
Interp2D = require("ndarray-linear-interpolate").d2; var _that = {},
_streamConfig = inputStream.getConfig(),
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()),
_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),
_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;
var FrameGrabber = {}; console.log("FrameGrabber", JSON.stringify({
videoSize: _grayImageArray.shape,
canvasSize: _canvasImageArray.shape,
stepSize: [_stepSizeX, _stepSizeY],
size: _targetImageArray.shape,
topRight: _topRight
}));
FrameGrabber.create = function(inputStream) { /**
var _that = {}, * Uses the given array as frame-buffer
_streamConfig = inputStream.getConfig(), */
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()), _that.attachData = function(data) {
_canvasSize = inputStream.getCanvasSize(), _data = data;
_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),
_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({
videoSize: _grayImageArray.shape,
canvasSize: _canvasImageArray.shape,
stepSize: [_stepSizeX, _stepSizeY],
size: _targetImageArray.shape,
topRight: _topRight
}));
/**
* 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 frame = inputStream.getFrame();
if (frame) {
this.scaleAndCrop(frame);
return true;
} else {
return false;
}
};
_that.scaleAndCrop = function(frame) {
var x,
y;
// 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] !== _size.x ||
_targetImageArray.shape[1] !== _size.y) {
throw new Error("Shapes do not match!");
}
// 3. crop
for (y = 0; y < _size.y; y++) {
for (x = 0; x < _size.x; x++) {
_data[y * _size.x + x] = _targetImageArray.get(x, y);
}
}
},
_that.getSize = function() {
return _size;
};
return _that;
}; };
return (FrameGrabber); /**
}); * 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 frame = inputStream.getFrame();
if (frame) {
this.scaleAndCrop(frame);
return true;
} else {
return false;
}
};
_that.scaleAndCrop = function(frame) {
var x,
y;
// 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] !== _size.x ||
_targetImageArray.shape[1] !== _size.y) {
throw new Error("Shapes do not match!");
}
// 3. crop
for (y = 0; y < _size.y; y++) {
for (x = 0; x < _size.x; x++) {
_data[y * _size.x + x] = _targetImageArray.get(x, y);
}
}
},
_that.getSize = function() {
return _size;
};
return _that;
};
module.exports = FrameGrabber;
+138 -145
View File
@@ -1,160 +1,153 @@
/* jshint undef: true, unused: true, browser:true, devel: true */ const GetPixels = require("get-pixels");
/* global define */
define(function() { var InputStream = {};
"use strict";
var GetPixels = require("get-pixels"); InputStream.createImageStream = function() {
var that = {};
var _config = null;
var InputStream = {}; var width = 0,
height = 0,
frameIdx = 0,
paused = true,
loaded = false,
frame = null,
baseUrl,
ended = false,
size,
calculatedWidth,
calculatedHeight,
_eventNames = ['canrecord', 'ended'],
_eventHandlers = {},
_topRight = {x: 0, y: 0},
_canvasSize = {x: 0, y: 0};
InputStream.createImageStream = function() { function loadImages() {
var that = {}; loaded = false;
var _config = null; GetPixels(baseUrl, function(err, pixels) {
if (err) {
console.log(err);
exit(1);
}
loaded = true;
console.log(pixels.shape);
frame = pixels;
width = pixels.shape[0];
height = pixels.shape[1];
calculatedWidth = _config.size ? width/height > 1 ? _config.size : Math.floor((width/height) * _config.size) : width;
calculatedHeight = _config.size ? width/height > 1 ? Math.floor((height/width) * _config.size) : _config.size : height;
var width = 0, _canvasSize.x = calculatedWidth;
height = 0, _canvasSize.y = calculatedHeight;
frameIdx = 0,
paused = true,
loaded = false,
frame = null,
baseUrl,
ended = false,
size,
calculatedWidth,
calculatedHeight,
_eventNames = ['canrecord', 'ended'],
_eventHandlers = {},
_topRight = {x: 0, y: 0},
_canvasSize = {x: 0, y: 0};
function loadImages() { setTimeout(function() {
loaded = false; publishEvent("canrecord", []);
GetPixels(baseUrl, function(err, pixels) { }, 0);
if (err) { });
console.log(err); }
exit(1);
}
loaded = true;
console.log(pixels.shape);
frame = pixels;
width = pixels.shape[0];
height = pixels.shape[1];
calculatedWidth = _config.size ? width/height > 1 ? _config.size : Math.floor((width/height) * _config.size) : width;
calculatedHeight = _config.size ? width/height > 1 ? Math.floor((height/width) * _config.size) : _config.size : height;
_canvasSize.x = calculatedWidth; function publishEvent(eventName, args) {
_canvasSize.y = calculatedHeight; var j,
handlers = _eventHandlers[eventName];
setTimeout(function() { if (handlers && handlers.length > 0) {
publishEvent("canrecord", []); for ( j = 0; j < handlers.length; j++) {
}, 0); handlers[j].apply(that, args);
});
}
function publishEvent(eventName, args) {
var j,
handlers = _eventHandlers[eventName];
if (handlers && handlers.length > 0) {
for ( j = 0; j < handlers.length; j++) {
handlers[j].apply(that, args);
}
} }
} }
}
that.trigger = publishEvent; that.trigger = publishEvent;
that.getWidth = function() { that.getWidth = function() {
return calculatedWidth; return calculatedWidth;
};
that.getHeight = function() {
return calculatedHeight;
};
that.setWidth = function(width) {
calculatedWidth = width;
};
that.setHeight = function(height) {
calculatedHeight = height;
};
that.getRealWidth = function() {
return width;
};
that.getRealHeight = function() {
return height;
};
that.setInputStream = function(stream) {
_config = stream;
baseUrl = _config.src;
size = 1;
loadImages();
};
that.ended = function() {
return ended;
};
that.setAttribute = function() {};
that.getConfig = function() {
return _config;
};
that.pause = function() {
paused = true;
};
that.play = function() {
paused = false;
};
that.setCurrentTime = function(time) {
frameIdx = time;
};
that.addEventListener = function(event, f) {
if (_eventNames.indexOf(event) !== -1) {
if (!_eventHandlers[event]) {
_eventHandlers[event] = [];
}
_eventHandlers[event].push(f);
}
};
that.setTopRight = function(topRight) {
_topRight.x = topRight.x;
_topRight.y = topRight.y;
};
that.getTopRight = function() {
return _topRight;
};
that.setCanvasSize = function(size) {
_canvasSize.x = size.x;
_canvasSize.y = size.y;
};
that.getCanvasSize = function() {
return _canvasSize;
};
that.getFrame = function() {
if (!loaded){
return null;
}
return frame;
};
return that;
}; };
return (InputStream); that.getHeight = function() {
}); return calculatedHeight;
};
that.setWidth = function(width) {
calculatedWidth = width;
};
that.setHeight = function(height) {
calculatedHeight = height;
};
that.getRealWidth = function() {
return width;
};
that.getRealHeight = function() {
return height;
};
that.setInputStream = function(stream) {
_config = stream;
baseUrl = _config.src;
size = 1;
loadImages();
};
that.ended = function() {
return ended;
};
that.setAttribute = function() {};
that.getConfig = function() {
return _config;
};
that.pause = function() {
paused = true;
};
that.play = function() {
paused = false;
};
that.setCurrentTime = function(time) {
frameIdx = time;
};
that.addEventListener = function(event, f) {
if (_eventNames.indexOf(event) !== -1) {
if (!_eventHandlers[event]) {
_eventHandlers[event] = [];
}
_eventHandlers[event].push(f);
}
};
that.setTopRight = function(topRight) {
_topRight.x = topRight.x;
_topRight.y = topRight.y;
};
that.getTopRight = function() {
return _topRight;
};
that.setCanvasSize = function(size) {
_canvasSize.x = size.x;
_canvasSize.y = size.y;
};
that.getCanvasSize = function() {
return _canvasSize;
};
that.getFrame = function() {
if (!loaded){
return null;
}
return frame;
};
return that;
};
module.exports = InputStream;
+7799 -12
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -3,7 +3,7 @@
"version": "0.7.0", "version": "0.7.0",
"description": "An advanced barcode-scanner written in JavaScript", "description": "An advanced barcode-scanner written in JavaScript",
"main": "lib/quagga.js", "main": "lib/quagga.js",
"browser": "dist/quagga.js", "browser": "dist/quagga.min.js",
"devDependencies": { "devDependencies": {
"async": "^1.4.2", "async": "^1.4.2",
"babel-core": "^5.8.25", "babel-core": "^5.8.25",
+1 -1
View File
@@ -58,7 +58,7 @@ function initBuffers() {
_skelImageWrapper = new ImageWrapper(_patchSize, _skelImageWrapper = new ImageWrapper(_patchSize,
new Uint8Array(skeletonImageData, _patchSize.x * _patchSize.y * 3, _patchSize.x * _patchSize.y), new Uint8Array(skeletonImageData, _patchSize.x * _patchSize.y * 3, _patchSize.x * _patchSize.y),
undefined, true); undefined, true);
_skeletonizer = skeletonizer((typeof window !== 'undefined') ? window : self, { _skeletonizer = skeletonizer((typeof window !== 'undefined') ? window : (typeof self !== 'undefined') ? self : global, {
size: _patchSize.x size: _patchSize.x
}, skeletonImageData); }, skeletonImageData);
+2 -2
View File
@@ -1,9 +1,7 @@
import TypeDefs from './typedefs'; // eslint-disable-line no-unused-vars import TypeDefs from './typedefs'; // eslint-disable-line no-unused-vars
import InputStream from './input_stream';
import ImageWrapper from './image_wrapper'; import ImageWrapper from './image_wrapper';
import BarcodeLocator from './barcode_locator'; import BarcodeLocator from './barcode_locator';
import BarcodeDecoder from './barcode_decoder'; import BarcodeDecoder from './barcode_decoder';
import FrameGrabber from './frame_grabber';
import Config from './config'; import Config from './config';
import Events from './events'; import Events from './events';
import CameraAccess from './camera_access'; import CameraAccess from './camera_access';
@@ -12,6 +10,8 @@ import {vec2} from 'gl-matrix';
import ResultCollector from './result_collector'; import ResultCollector from './result_collector';
const merge = require('lodash/object/merge'); const merge = require('lodash/object/merge');
const InputStream = require('input_stream');
const FrameGrabber = require('frame_grabber');
var _inputStream, var _inputStream,
_framegrabber, _framegrabber,
+7 -2
View File
@@ -1,5 +1,6 @@
var webpack = require('webpack'), var webpack = require('webpack'),
MyUmdPlugin = require('./plugins/umd'); MyUmdPlugin = require('./plugins/umd'),
path = require('path');
module.exports = { module.exports = {
entry: [ entry: [
@@ -14,7 +15,11 @@ module.exports = {
}] }]
}, },
resolve: { resolve: {
extensions: ['', '.js', '.jsx'] extensions: ['', '.js', '.jsx'],
alias: {
'input_stream$': path.resolve(__dirname, 'src/input_stream'),
'frame_grabber$': path.resolve(__dirname, 'src/frame_grabber')
}
}, },
output: { output: {
path: __dirname + '/dist', path: __dirname + '/dist',
+26
View File
@@ -0,0 +1,26 @@
var webpack = require('webpack'),
path = require('path');
module.exports = require('./webpack.config.js');
console.log(path.resolve(__dirname, 'lib/input_stream'));
module.exports.resolve = {
extensions: ['', '.js', '.jsx'],
alias: {
'input_stream$': path.resolve(__dirname, 'lib/input_stream'),
'frame_grabber$': path.resolve(__dirname, 'lib/frame_grabber')
}
};
module.exports.externals = [
"get-pixels",
"gl-matrix",
"lodash",
"ndarray",
"ndarray-linear-interpolate"
];
module.exports.output.libraryTarget = "commonjs2";
module.exports.plugins = [];
module.exports.output.path = __dirname + '/lib';
module.exports.output.filename = 'quagga.js';