pull/35/head
Christoph Oberhofer 10 years ago
parent 0e0cfcea00
commit 76e61bc4c4

@ -1,7 +1,7 @@
quaggaJS
========
- [Changelog](#changelog) (2015-04-30)
- [Changelog](#changelog) (2015-05-09)
## What is QuaggaJS?
@ -293,6 +293,10 @@ work.
## <a name="changelog">Changelog</a>
### 2015-05-09
- Improvements
- Odd image dimensions no longer cause problems
### 2015-04-30
- Features
- Added support for [UPC-A and UPC-E][upc_wiki] barcodes

145
dist/quagga.js vendored

@ -437,7 +437,7 @@ define("almond", function(){});
define(
'barcode_reader',[],function() {
"use strict";
function BarcodeReader() {
this._row = [];
@ -631,7 +631,7 @@ define(
"./barcode_reader"
],
function(BarcodeReader) {
"use strict";
function Code128Reader() {
BarcodeReader.call(this);
@ -1079,7 +1079,7 @@ define(
"./barcode_reader"
],
function(BarcodeReader) {
"use strict";
function EANReader() {
BarcodeReader.call(this);
@ -1379,7 +1379,7 @@ define(
/* global define */
define('image_loader',[],function() {
"use strict";
var ImageLoader = {};
ImageLoader.load = function(directory, callback, offset, size, sequence) {
@ -1443,7 +1443,7 @@ define('image_loader',[],function() {
/* global define */
define('input_stream',["image_loader"], function(ImageLoader) {
"use strict";
var InputStream = {};
InputStream.createVideoStream = function(video) {
@ -1571,6 +1571,8 @@ define('input_stream',["image_loader"], function(ImageLoader) {
offset = 1,
baseUrl = null,
ended = false,
calculatedWidth,
calculatedHeight,
_eventNames = ['canrecord', 'ended'],
_eventHandlers = {};
@ -1580,6 +1582,8 @@ define('input_stream',["image_loader"], function(ImageLoader) {
imgArray = imgs;
width = imgs[0].width;
height = imgs[0].height;
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;
loaded = true;
frameIdx = 0;
setTimeout(function() {
@ -1603,11 +1607,19 @@ define('input_stream',["image_loader"], function(ImageLoader) {
that.trigger = publishEvent;
that.getWidth = function() {
return _config.size ? width/height > 1 ? _config.size : (width/height) * _config.size : width;
return calculatedWidth;
};
that.getHeight = function() {
return _config.size ? width/height > 1 ? (height/width) * _config.size : _config.size : height;
return calculatedHeight;
};
that.setWidth = function(width) {
calculatedWidth = width;
};
that.setHeight = function(height) {
calculatedHeight = height;
};
that.getRealWidth = function() {
@ -1720,7 +1732,7 @@ define("typedefs", (function (global) {
/* global define */
define('subImage',["typedefs"], function() {
"use strict";
/**
* Construct representing a part of another {ImageWrapper}. Shares data
@ -1817,7 +1829,7 @@ define('subImage',["typedefs"], function() {
/* global define, vec2 */
define('cluster',[],function() {
"use strict";
/**
* Creates a cluster for grouping similar orientations of datapoints
@ -4162,7 +4174,7 @@ define("glMatrixAddon", ["glMatrix"], (function (global) {
/* global define */
define('array_helper',[],function() {
"use strict";
return {
init : function(arr, val) {
@ -4249,7 +4261,7 @@ define('array_helper',[],function() {
define('cv_utils',['cluster', 'glMatrixAddon', "array_helper"], function(Cluster2, glMatrixAddon, ArrayHelper) {
"use strict";
/*
* cv_utils.js
* Collection of CV functions and libraries
@ -4825,31 +4837,59 @@ define('cv_utils',['cluster', 'glMatrixAddon', "array_helper"], function(Cluster
divisorsY = this._computeDivisors(imgSize.y),
wideSide = Math.max(imgSize.x, imgSize.y),
common = this._computeIntersection(divisorsX, divisorsY),
nrOfPatchesList = [8, 10, 15, 20, 32, 60, 80],
nrOfPatchesMap = {
"x-small": 60,
"small": 32,
"medium": 20,
"large": 15,
"x-large": 10
"x-small": 5,
"small": 4,
"medium": 3,
"large": 2,
"x-large": 1
},
nrOfPatches = nrOfPatchesMap[patchSize] || nrOfPatchesMap.medium,
i = 0,
found = common[Math.floor(common.length/2)],
desiredPatchSize = wideSide/nrOfPatches;
nrOfPatchesIdx = nrOfPatchesMap[patchSize] || nrOfPatchesMap.medium,
nrOfPatches = nrOfPatchesList[nrOfPatchesIdx],
desiredPatchSize = Math.floor(wideSide/nrOfPatches),
optimalPatchSize;
function findPatchSizeForDivisors(divisors) {
var i = 0,
found = divisors[Math.floor(divisors.length/2)];
while(i < (common.length - 1) && common[i] < desiredPatchSize) {
while(i < (divisors.length - 1) && divisors[i] < desiredPatchSize) {
i++;
}
if (i > 0) {
if (Math.abs(common[i] - desiredPatchSize) > Math.abs(common[i-1] - desiredPatchSize)) {
found = common[i-1];
if (Math.abs(divisors[i] - desiredPatchSize) > Math.abs(divisors[i-1] - desiredPatchSize)) {
found = divisors[i-1];
} else {
found = common[i];
found = divisors[i];
}
}
if (desiredPatchSize / found < nrOfPatchesList[nrOfPatchesIdx+1] / nrOfPatchesList[nrOfPatchesIdx] &&
desiredPatchSize / found > nrOfPatchesList[nrOfPatchesIdx-1]/nrOfPatchesList[nrOfPatchesIdx] ) {
return {x: found, y: found};
}
return null;
}
optimalPatchSize = findPatchSizeForDivisors(common);
if (!optimalPatchSize) {
optimalPatchSize = findPatchSizeForDivisors(this._computeDivisors(wideSide));
throw new AdjustToSizeError("", optimalPatchSize);
}
return optimalPatchSize;
};
function AdjustToSizeError(message, desiredPatchSize) {
this.name = 'AdjustToSizeError';
this.message = message || 'AdjustToSizeError';
this.patchSize = desiredPatchSize;
}
AdjustToSizeError.prototype = Object.create(RangeError.prototype);
AdjustToSizeError.prototype.constructor = AdjustToSizeError;
CVUtils.AdjustToSizeError = AdjustToSizeError;
return (CVUtils);
});
@ -4864,7 +4904,7 @@ define('image_wrapper',[
],
function(SubImage, CVUtils, ArrayHelper) {
'use strict';
/**
* Represents a basic image combining the data and size.
@ -5285,7 +5325,7 @@ define('image_wrapper',[
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
*/
define('tracer',[],function() {
"use strict";
var Tracer = {
searchDirections : [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]],
@ -5394,7 +5434,7 @@ define('tracer',[],function() {
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
*/
define('rasterizer',["tracer"], function(Tracer) {
"use strict";
var Rasterizer = {
createContour2D : function() {
@ -5590,7 +5630,7 @@ define('rasterizer',["tracer"], function(Tracer) {
/* global define */
define('skeletonizer',[],function() {
"use strict";
/* @preserve ASM BEGIN */
function Skeletonizer(stdlib, foreign, buffer) {
@ -5795,7 +5835,7 @@ define('skeletonizer',[],function() {
/* global define */
define('image_debug',[],function() {
"use strict";
return {
drawRect: function(pos, size, ctx, style){
@ -6340,7 +6380,7 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
/* global define */
define('bresenham',[],function() {
"use strict";
var Bresenham = {};
var Slope = {
@ -6546,7 +6586,7 @@ define(
"./array_helper"
],
function(BarcodeReader, ArrayHelper) {
"use strict";
function Code39Reader() {
BarcodeReader.call(this);
@ -6748,7 +6788,7 @@ define(
"./barcode_reader"
],
function(BarcodeReader) {
"use strict";
function CodabarReader() {
BarcodeReader.call(this);
@ -7061,7 +7101,7 @@ define(
"./ean_reader"
],
function(EANReader) {
"use strict";
function UPCReader() {
EANReader.call(this);
@ -7092,7 +7132,7 @@ define(
"./ean_reader"
],
function(EANReader) {
"use strict";
function EAN8Reader() {
EANReader.call(this);
@ -7137,7 +7177,7 @@ define(
"./ean_reader"
],
function(EANReader) {
"use strict";
function UPCEReader() {
EANReader.call(this);
@ -7261,7 +7301,7 @@ define('barcode_decoder',[
UPCReader,
EAN8Reader,
UPCEReader) {
"use strict";
var readers = {
code_128_reader: Code128Reader,
@ -7538,7 +7578,7 @@ define('barcode_decoder',[
/* global define */
define('frame_grabber',["cv_utils"], function(CVUtils) {
"use strict";
var FrameGrabber = {};
@ -7546,7 +7586,7 @@ define('frame_grabber',["cv_utils"], function(CVUtils) {
var _that = {},
_streamConfig = inputStream.getConfig(),
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()),
_size =_streamConfig.size ? CVUtils.imageRef(_streamConfig.size, _streamConfig.size) : _video_size,
_size =_streamConfig.size ? CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()) : _video_size,
_sx = 0,
_sy = 0,
_dx = 0,
@ -7559,17 +7599,6 @@ define('frame_grabber',["cv_utils"], function(CVUtils) {
_ctx = null,
_data = null;
// Check if size is given
if (_streamConfig.size) {
if (_video_size.x/_video_size.y > 1) {
_size.x = _streamConfig.size;
_size.y = (_video_size.y/_video_size.x)*_streamConfig.size;
} else {
_size.y = _streamConfig.size;
_size.x = (_video_size.x/_video_size.y)*_streamConfig.size;
}
}
_sWidth = _video_size.x;
_dWidth = _size.x;
_sHeight = _video_size.y;
@ -7631,7 +7660,7 @@ define('frame_grabber',["cv_utils"], function(CVUtils) {
/* global define */
define('html_utils',[], function() {
"use strict";
function createNode(htmlStr) {
var temp = document.createElement('div');
@ -7722,7 +7751,7 @@ define('config',[],function(){
/* global define */
define('events',[],function() {
"use strict";
var _events = function() {
var events = {};
@ -7813,7 +7842,7 @@ define('events',[],function() {
/* global define, MediaStreamTrack */
define('camera_access',["html_utils"], function(HtmlUtils) {
"use strict";
var streamRef,
loadedDataHandler;
@ -7975,7 +8004,7 @@ function(Code128Reader,
CameraAccess,
ImageDebug,
CVUtils) {
"use strict";
var _inputStream,
_framegrabber,
@ -8064,9 +8093,17 @@ function(Code128Reader,
};
if (_config.locate) {
try {
patchSize = CVUtils.calculatePatchSize(_config.locator.patchSize, size);
} catch (error) {
if (error instanceof CVUtils.AdjustToSizeError) {
_inputStream.setWidth(Math.floor(width/error.patchSize.x)*error.patchSize.x);
_inputStream.setHeight(Math.floor(height/error.patchSize.y)*error.patchSize.y);
patchSize = error.patchSize;
}
}
console.log("Patch-Size: " + JSON.stringify(patchSize));
if ((width % patchSize.x) === 0 && (height % patchSize.y) === 0) {
if ((_inputStream.getWidth() % patchSize.x) === 0 && (_inputStream.getHeight() % patchSize.y) === 0) {
return true;
}
}

File diff suppressed because one or more lines are too long

@ -1,6 +1,6 @@
{
"name": "quagga",
"version": "0.6.1",
"version": "0.6.2",
"description": "An advanced barcode-scanner written in JavaScript",
"main": "dist/quagga.js",
"devDependencies": {

@ -579,31 +579,59 @@ define(['cluster', 'glMatrixAddon', "array_helper"], function(Cluster2, glMatrix
divisorsY = this._computeDivisors(imgSize.y),
wideSide = Math.max(imgSize.x, imgSize.y),
common = this._computeIntersection(divisorsX, divisorsY),
nrOfPatchesList = [8, 10, 15, 20, 32, 60, 80],
nrOfPatchesMap = {
"x-small": 60,
"small": 32,
"medium": 20,
"large": 15,
"x-large": 10
"x-small": 5,
"small": 4,
"medium": 3,
"large": 2,
"x-large": 1
},
nrOfPatches = nrOfPatchesMap[patchSize] || nrOfPatchesMap.medium,
i = 0,
found = common[Math.floor(common.length/2)],
desiredPatchSize = wideSide/nrOfPatches;
nrOfPatchesIdx = nrOfPatchesMap[patchSize] || nrOfPatchesMap.medium,
nrOfPatches = nrOfPatchesList[nrOfPatchesIdx],
desiredPatchSize = Math.floor(wideSide/nrOfPatches),
optimalPatchSize;
while(i < (common.length - 1) && common[i] < desiredPatchSize) {
function findPatchSizeForDivisors(divisors) {
var i = 0,
found = divisors[Math.floor(divisors.length/2)];
while(i < (divisors.length - 1) && divisors[i] < desiredPatchSize) {
i++;
}
if (i > 0) {
if (Math.abs(common[i] - desiredPatchSize) > Math.abs(common[i-1] - desiredPatchSize)) {
found = common[i-1];
if (Math.abs(divisors[i] - desiredPatchSize) > Math.abs(divisors[i-1] - desiredPatchSize)) {
found = divisors[i-1];
} else {
found = common[i];
found = divisors[i];
}
}
if (desiredPatchSize / found < nrOfPatchesList[nrOfPatchesIdx+1] / nrOfPatchesList[nrOfPatchesIdx] &&
desiredPatchSize / found > nrOfPatchesList[nrOfPatchesIdx-1]/nrOfPatchesList[nrOfPatchesIdx] ) {
return {x: found, y: found};
}
return null;
}
optimalPatchSize = findPatchSizeForDivisors(common);
if (!optimalPatchSize) {
optimalPatchSize = findPatchSizeForDivisors(this._computeDivisors(wideSide));
throw new AdjustToSizeError("", optimalPatchSize);
}
return optimalPatchSize;
};
function AdjustToSizeError(message, desiredPatchSize) {
this.name = 'AdjustToSizeError';
this.message = message || 'AdjustToSizeError';
this.patchSize = desiredPatchSize;
}
AdjustToSizeError.prototype = Object.create(RangeError.prototype);
AdjustToSizeError.prototype.constructor = AdjustToSizeError;
CVUtils.AdjustToSizeError = AdjustToSizeError;
return (CVUtils);
});

@ -10,7 +10,7 @@ define(["cv_utils"], function(CVUtils) {
var _that = {},
_streamConfig = inputStream.getConfig(),
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()),
_size =_streamConfig.size ? CVUtils.imageRef(_streamConfig.size, _streamConfig.size) : _video_size,
_size =_streamConfig.size ? CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()) : _video_size,
_sx = 0,
_sy = 0,
_dx = 0,
@ -23,17 +23,6 @@ define(["cv_utils"], function(CVUtils) {
_ctx = null,
_data = null;
// Check if size is given
if (_streamConfig.size) {
if (_video_size.x/_video_size.y > 1) {
_size.x = _streamConfig.size;
_size.y = (_video_size.y/_video_size.x)*_streamConfig.size;
} else {
_size.y = _streamConfig.size;
_size.x = (_video_size.x/_video_size.y)*_streamConfig.size;
}
}
_sWidth = _video_size.x;
_dWidth = _size.x;
_sHeight = _video_size.y;

@ -130,6 +130,8 @@ define(["image_loader"], function(ImageLoader) {
offset = 1,
baseUrl = null,
ended = false,
calculatedWidth,
calculatedHeight,
_eventNames = ['canrecord', 'ended'],
_eventHandlers = {};
@ -139,6 +141,8 @@ define(["image_loader"], function(ImageLoader) {
imgArray = imgs;
width = imgs[0].width;
height = imgs[0].height;
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;
loaded = true;
frameIdx = 0;
setTimeout(function() {
@ -162,11 +166,19 @@ define(["image_loader"], function(ImageLoader) {
that.trigger = publishEvent;
that.getWidth = function() {
return _config.size ? width/height > 1 ? _config.size : (width/height) * _config.size : width;
return calculatedWidth;
};
that.getHeight = function() {
return _config.size ? width/height > 1 ? (height/width) * _config.size : _config.size : height;
return calculatedHeight;
};
that.setWidth = function(width) {
calculatedWidth = width;
};
that.setHeight = function(height) {
calculatedHeight = height;
};
that.getRealWidth = function() {

@ -118,9 +118,17 @@ function(Code128Reader,
};
if (_config.locate) {
try {
patchSize = CVUtils.calculatePatchSize(_config.locator.patchSize, size);
} catch (error) {
if (error instanceof CVUtils.AdjustToSizeError) {
_inputStream.setWidth(Math.floor(width/error.patchSize.x)*error.patchSize.x);
_inputStream.setHeight(Math.floor(height/error.patchSize.y)*error.patchSize.y);
patchSize = error.patchSize;
}
}
console.log("Patch-Size: " + JSON.stringify(patchSize));
if ((width % patchSize.x) === 0 && (height % patchSize.y) === 0) {
if ((_inputStream.getWidth() % patchSize.x) === 0 && (_inputStream.getHeight() % patchSize.y) === 0) {
return true;
}
}

Loading…
Cancel
Save