mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Fixes #30
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
quaggaJS
|
quaggaJS
|
||||||
========
|
========
|
||||||
|
|
||||||
- [Changelog](#changelog) (2015-04-30)
|
- [Changelog](#changelog) (2015-05-09)
|
||||||
|
|
||||||
## What is QuaggaJS?
|
## What is QuaggaJS?
|
||||||
|
|
||||||
@@ -293,6 +293,10 @@ work.
|
|||||||
|
|
||||||
## <a name="changelog">Changelog</a>
|
## <a name="changelog">Changelog</a>
|
||||||
|
|
||||||
|
### 2015-05-09
|
||||||
|
- Improvements
|
||||||
|
- Odd image dimensions no longer cause problems
|
||||||
|
|
||||||
### 2015-04-30
|
### 2015-04-30
|
||||||
- Features
|
- Features
|
||||||
- Added support for [UPC-A and UPC-E][upc_wiki] barcodes
|
- Added support for [UPC-A and UPC-E][upc_wiki] barcodes
|
||||||
|
|||||||
Vendored
+97
-60
@@ -437,7 +437,7 @@ define("almond", function(){});
|
|||||||
|
|
||||||
define(
|
define(
|
||||||
'barcode_reader',[],function() {
|
'barcode_reader',[],function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function BarcodeReader() {
|
function BarcodeReader() {
|
||||||
this._row = [];
|
this._row = [];
|
||||||
@@ -631,7 +631,7 @@ define(
|
|||||||
"./barcode_reader"
|
"./barcode_reader"
|
||||||
],
|
],
|
||||||
function(BarcodeReader) {
|
function(BarcodeReader) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function Code128Reader() {
|
function Code128Reader() {
|
||||||
BarcodeReader.call(this);
|
BarcodeReader.call(this);
|
||||||
@@ -1079,7 +1079,7 @@ define(
|
|||||||
"./barcode_reader"
|
"./barcode_reader"
|
||||||
],
|
],
|
||||||
function(BarcodeReader) {
|
function(BarcodeReader) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function EANReader() {
|
function EANReader() {
|
||||||
BarcodeReader.call(this);
|
BarcodeReader.call(this);
|
||||||
@@ -1379,7 +1379,7 @@ define(
|
|||||||
/* global define */
|
/* global define */
|
||||||
|
|
||||||
define('image_loader',[],function() {
|
define('image_loader',[],function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var ImageLoader = {};
|
var ImageLoader = {};
|
||||||
ImageLoader.load = function(directory, callback, offset, size, sequence) {
|
ImageLoader.load = function(directory, callback, offset, size, sequence) {
|
||||||
@@ -1443,7 +1443,7 @@ define('image_loader',[],function() {
|
|||||||
/* global define */
|
/* global define */
|
||||||
|
|
||||||
define('input_stream',["image_loader"], function(ImageLoader) {
|
define('input_stream',["image_loader"], function(ImageLoader) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var InputStream = {};
|
var InputStream = {};
|
||||||
InputStream.createVideoStream = function(video) {
|
InputStream.createVideoStream = function(video) {
|
||||||
@@ -1571,6 +1571,8 @@ define('input_stream',["image_loader"], function(ImageLoader) {
|
|||||||
offset = 1,
|
offset = 1,
|
||||||
baseUrl = null,
|
baseUrl = null,
|
||||||
ended = false,
|
ended = false,
|
||||||
|
calculatedWidth,
|
||||||
|
calculatedHeight,
|
||||||
_eventNames = ['canrecord', 'ended'],
|
_eventNames = ['canrecord', 'ended'],
|
||||||
_eventHandlers = {};
|
_eventHandlers = {};
|
||||||
|
|
||||||
@@ -1580,6 +1582,8 @@ define('input_stream',["image_loader"], function(ImageLoader) {
|
|||||||
imgArray = imgs;
|
imgArray = imgs;
|
||||||
width = imgs[0].width;
|
width = imgs[0].width;
|
||||||
height = imgs[0].height;
|
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;
|
loaded = true;
|
||||||
frameIdx = 0;
|
frameIdx = 0;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@@ -1603,11 +1607,19 @@ define('input_stream',["image_loader"], function(ImageLoader) {
|
|||||||
that.trigger = publishEvent;
|
that.trigger = publishEvent;
|
||||||
|
|
||||||
that.getWidth = function() {
|
that.getWidth = function() {
|
||||||
return _config.size ? width/height > 1 ? _config.size : (width/height) * _config.size : width;
|
return calculatedWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.getHeight = function() {
|
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() {
|
that.getRealWidth = function() {
|
||||||
@@ -1720,7 +1732,7 @@ define("typedefs", (function (global) {
|
|||||||
/* global define */
|
/* global define */
|
||||||
|
|
||||||
define('subImage',["typedefs"], function() {
|
define('subImage',["typedefs"], function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct representing a part of another {ImageWrapper}. Shares data
|
* Construct representing a part of another {ImageWrapper}. Shares data
|
||||||
@@ -1817,7 +1829,7 @@ define('subImage',["typedefs"], function() {
|
|||||||
/* global define, vec2 */
|
/* global define, vec2 */
|
||||||
|
|
||||||
define('cluster',[],function() {
|
define('cluster',[],function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a cluster for grouping similar orientations of datapoints
|
* Creates a cluster for grouping similar orientations of datapoints
|
||||||
@@ -4162,7 +4174,7 @@ define("glMatrixAddon", ["glMatrix"], (function (global) {
|
|||||||
/* global define */
|
/* global define */
|
||||||
|
|
||||||
define('array_helper',[],function() {
|
define('array_helper',[],function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init : function(arr, val) {
|
init : function(arr, val) {
|
||||||
@@ -4249,7 +4261,7 @@ define('array_helper',[],function() {
|
|||||||
|
|
||||||
define('cv_utils',['cluster', 'glMatrixAddon', "array_helper"], function(Cluster2, glMatrixAddon, ArrayHelper) {
|
define('cv_utils',['cluster', 'glMatrixAddon', "array_helper"], function(Cluster2, glMatrixAddon, ArrayHelper) {
|
||||||
|
|
||||||
"use strict";
|
|
||||||
/*
|
/*
|
||||||
* cv_utils.js
|
* cv_utils.js
|
||||||
* Collection of CV functions and libraries
|
* Collection of CV functions and libraries
|
||||||
@@ -4825,31 +4837,59 @@ define('cv_utils',['cluster', 'glMatrixAddon', "array_helper"], function(Cluster
|
|||||||
divisorsY = this._computeDivisors(imgSize.y),
|
divisorsY = this._computeDivisors(imgSize.y),
|
||||||
wideSide = Math.max(imgSize.x, imgSize.y),
|
wideSide = Math.max(imgSize.x, imgSize.y),
|
||||||
common = this._computeIntersection(divisorsX, divisorsY),
|
common = this._computeIntersection(divisorsX, divisorsY),
|
||||||
|
nrOfPatchesList = [8, 10, 15, 20, 32, 60, 80],
|
||||||
nrOfPatchesMap = {
|
nrOfPatchesMap = {
|
||||||
"x-small": 60,
|
"x-small": 5,
|
||||||
"small": 32,
|
"small": 4,
|
||||||
"medium": 20,
|
"medium": 3,
|
||||||
"large": 15,
|
"large": 2,
|
||||||
"x-large": 10
|
"x-large": 1
|
||||||
},
|
},
|
||||||
nrOfPatches = nrOfPatchesMap[patchSize] || nrOfPatchesMap.medium,
|
nrOfPatchesIdx = nrOfPatchesMap[patchSize] || nrOfPatchesMap.medium,
|
||||||
i = 0,
|
nrOfPatches = nrOfPatchesList[nrOfPatchesIdx],
|
||||||
found = common[Math.floor(common.length/2)],
|
desiredPatchSize = Math.floor(wideSide/nrOfPatches),
|
||||||
desiredPatchSize = wideSide/nrOfPatches;
|
optimalPatchSize;
|
||||||
|
|
||||||
while(i < (common.length - 1) && common[i] < desiredPatchSize) {
|
function findPatchSizeForDivisors(divisors) {
|
||||||
i++;
|
var i = 0,
|
||||||
}
|
found = divisors[Math.floor(divisors.length/2)];
|
||||||
if (i > 0) {
|
|
||||||
if (Math.abs(common[i] - desiredPatchSize) > Math.abs(common[i-1] - desiredPatchSize)) {
|
while(i < (divisors.length - 1) && divisors[i] < desiredPatchSize) {
|
||||||
found = common[i-1];
|
i++;
|
||||||
} else {
|
|
||||||
found = common[i];
|
|
||||||
}
|
}
|
||||||
|
if (i > 0) {
|
||||||
|
if (Math.abs(divisors[i] - desiredPatchSize) > Math.abs(divisors[i-1] - desiredPatchSize)) {
|
||||||
|
found = divisors[i-1];
|
||||||
|
} else {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
return {x: found, y: found};
|
|
||||||
|
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);
|
return (CVUtils);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -4864,7 +4904,7 @@ define('image_wrapper',[
|
|||||||
],
|
],
|
||||||
function(SubImage, CVUtils, ArrayHelper) {
|
function(SubImage, CVUtils, ArrayHelper) {
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a basic image combining the data and size.
|
* 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
|
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
|
||||||
*/
|
*/
|
||||||
define('tracer',[],function() {
|
define('tracer',[],function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var Tracer = {
|
var Tracer = {
|
||||||
searchDirections : [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]],
|
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
|
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
|
||||||
*/
|
*/
|
||||||
define('rasterizer',["tracer"], function(Tracer) {
|
define('rasterizer',["tracer"], function(Tracer) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var Rasterizer = {
|
var Rasterizer = {
|
||||||
createContour2D : function() {
|
createContour2D : function() {
|
||||||
@@ -5590,7 +5630,7 @@ define('rasterizer',["tracer"], function(Tracer) {
|
|||||||
/* global define */
|
/* global define */
|
||||||
|
|
||||||
define('skeletonizer',[],function() {
|
define('skeletonizer',[],function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
/* @preserve ASM BEGIN */
|
/* @preserve ASM BEGIN */
|
||||||
function Skeletonizer(stdlib, foreign, buffer) {
|
function Skeletonizer(stdlib, foreign, buffer) {
|
||||||
@@ -5795,7 +5835,7 @@ define('skeletonizer',[],function() {
|
|||||||
/* global define */
|
/* global define */
|
||||||
|
|
||||||
define('image_debug',[],function() {
|
define('image_debug',[],function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
drawRect: function(pos, size, ctx, style){
|
drawRect: function(pos, size, ctx, style){
|
||||||
@@ -6340,7 +6380,7 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
|
|||||||
/* global define */
|
/* global define */
|
||||||
|
|
||||||
define('bresenham',[],function() {
|
define('bresenham',[],function() {
|
||||||
"use strict";
|
|
||||||
var Bresenham = {};
|
var Bresenham = {};
|
||||||
|
|
||||||
var Slope = {
|
var Slope = {
|
||||||
@@ -6546,7 +6586,7 @@ define(
|
|||||||
"./array_helper"
|
"./array_helper"
|
||||||
],
|
],
|
||||||
function(BarcodeReader, ArrayHelper) {
|
function(BarcodeReader, ArrayHelper) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function Code39Reader() {
|
function Code39Reader() {
|
||||||
BarcodeReader.call(this);
|
BarcodeReader.call(this);
|
||||||
@@ -6748,7 +6788,7 @@ define(
|
|||||||
"./barcode_reader"
|
"./barcode_reader"
|
||||||
],
|
],
|
||||||
function(BarcodeReader) {
|
function(BarcodeReader) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function CodabarReader() {
|
function CodabarReader() {
|
||||||
BarcodeReader.call(this);
|
BarcodeReader.call(this);
|
||||||
@@ -7061,7 +7101,7 @@ define(
|
|||||||
"./ean_reader"
|
"./ean_reader"
|
||||||
],
|
],
|
||||||
function(EANReader) {
|
function(EANReader) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function UPCReader() {
|
function UPCReader() {
|
||||||
EANReader.call(this);
|
EANReader.call(this);
|
||||||
@@ -7092,7 +7132,7 @@ define(
|
|||||||
"./ean_reader"
|
"./ean_reader"
|
||||||
],
|
],
|
||||||
function(EANReader) {
|
function(EANReader) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function EAN8Reader() {
|
function EAN8Reader() {
|
||||||
EANReader.call(this);
|
EANReader.call(this);
|
||||||
@@ -7137,7 +7177,7 @@ define(
|
|||||||
"./ean_reader"
|
"./ean_reader"
|
||||||
],
|
],
|
||||||
function(EANReader) {
|
function(EANReader) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function UPCEReader() {
|
function UPCEReader() {
|
||||||
EANReader.call(this);
|
EANReader.call(this);
|
||||||
@@ -7261,7 +7301,7 @@ define('barcode_decoder',[
|
|||||||
UPCReader,
|
UPCReader,
|
||||||
EAN8Reader,
|
EAN8Reader,
|
||||||
UPCEReader) {
|
UPCEReader) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var readers = {
|
var readers = {
|
||||||
code_128_reader: Code128Reader,
|
code_128_reader: Code128Reader,
|
||||||
@@ -7538,7 +7578,7 @@ define('barcode_decoder',[
|
|||||||
/* global define */
|
/* global define */
|
||||||
|
|
||||||
define('frame_grabber',["cv_utils"], function(CVUtils) {
|
define('frame_grabber',["cv_utils"], function(CVUtils) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var FrameGrabber = {};
|
var FrameGrabber = {};
|
||||||
|
|
||||||
@@ -7546,7 +7586,7 @@ define('frame_grabber',["cv_utils"], function(CVUtils) {
|
|||||||
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(_streamConfig.size, _streamConfig.size) : _video_size,
|
_size =_streamConfig.size ? CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()) : _video_size,
|
||||||
_sx = 0,
|
_sx = 0,
|
||||||
_sy = 0,
|
_sy = 0,
|
||||||
_dx = 0,
|
_dx = 0,
|
||||||
@@ -7559,17 +7599,6 @@ define('frame_grabber',["cv_utils"], function(CVUtils) {
|
|||||||
_ctx = null,
|
_ctx = null,
|
||||||
_data = 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;
|
_sWidth = _video_size.x;
|
||||||
_dWidth = _size.x;
|
_dWidth = _size.x;
|
||||||
_sHeight = _video_size.y;
|
_sHeight = _video_size.y;
|
||||||
@@ -7631,7 +7660,7 @@ define('frame_grabber',["cv_utils"], function(CVUtils) {
|
|||||||
/* global define */
|
/* global define */
|
||||||
|
|
||||||
define('html_utils',[], function() {
|
define('html_utils',[], function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function createNode(htmlStr) {
|
function createNode(htmlStr) {
|
||||||
var temp = document.createElement('div');
|
var temp = document.createElement('div');
|
||||||
@@ -7722,7 +7751,7 @@ define('config',[],function(){
|
|||||||
/* global define */
|
/* global define */
|
||||||
|
|
||||||
define('events',[],function() {
|
define('events',[],function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var _events = function() {
|
var _events = function() {
|
||||||
var events = {};
|
var events = {};
|
||||||
@@ -7813,7 +7842,7 @@ define('events',[],function() {
|
|||||||
/* global define, MediaStreamTrack */
|
/* global define, MediaStreamTrack */
|
||||||
|
|
||||||
define('camera_access',["html_utils"], function(HtmlUtils) {
|
define('camera_access',["html_utils"], function(HtmlUtils) {
|
||||||
"use strict";
|
|
||||||
var streamRef,
|
var streamRef,
|
||||||
loadedDataHandler;
|
loadedDataHandler;
|
||||||
|
|
||||||
@@ -7975,7 +8004,7 @@ function(Code128Reader,
|
|||||||
CameraAccess,
|
CameraAccess,
|
||||||
ImageDebug,
|
ImageDebug,
|
||||||
CVUtils) {
|
CVUtils) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var _inputStream,
|
var _inputStream,
|
||||||
_framegrabber,
|
_framegrabber,
|
||||||
@@ -8064,9 +8093,17 @@ function(Code128Reader,
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (_config.locate) {
|
if (_config.locate) {
|
||||||
patchSize = CVUtils.calculatePatchSize(_config.locator.patchSize, size);
|
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));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+4
-4
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "quagga",
|
"name": "quagga",
|
||||||
"version": "0.6.1",
|
"version": "0.6.2",
|
||||||
"description": "An advanced barcode-scanner written in JavaScript",
|
"description": "An advanced barcode-scanner written in JavaScript",
|
||||||
"main": "dist/quagga.js",
|
"main": "dist/quagga.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
+46
-18
@@ -579,31 +579,59 @@ define(['cluster', 'glMatrixAddon', "array_helper"], function(Cluster2, glMatrix
|
|||||||
divisorsY = this._computeDivisors(imgSize.y),
|
divisorsY = this._computeDivisors(imgSize.y),
|
||||||
wideSide = Math.max(imgSize.x, imgSize.y),
|
wideSide = Math.max(imgSize.x, imgSize.y),
|
||||||
common = this._computeIntersection(divisorsX, divisorsY),
|
common = this._computeIntersection(divisorsX, divisorsY),
|
||||||
|
nrOfPatchesList = [8, 10, 15, 20, 32, 60, 80],
|
||||||
nrOfPatchesMap = {
|
nrOfPatchesMap = {
|
||||||
"x-small": 60,
|
"x-small": 5,
|
||||||
"small": 32,
|
"small": 4,
|
||||||
"medium": 20,
|
"medium": 3,
|
||||||
"large": 15,
|
"large": 2,
|
||||||
"x-large": 10
|
"x-large": 1
|
||||||
},
|
},
|
||||||
nrOfPatches = nrOfPatchesMap[patchSize] || nrOfPatchesMap.medium,
|
nrOfPatchesIdx = nrOfPatchesMap[patchSize] || nrOfPatchesMap.medium,
|
||||||
i = 0,
|
nrOfPatches = nrOfPatchesList[nrOfPatchesIdx],
|
||||||
found = common[Math.floor(common.length/2)],
|
desiredPatchSize = Math.floor(wideSide/nrOfPatches),
|
||||||
desiredPatchSize = wideSide/nrOfPatches;
|
optimalPatchSize;
|
||||||
|
|
||||||
while(i < (common.length - 1) && common[i] < desiredPatchSize) {
|
function findPatchSizeForDivisors(divisors) {
|
||||||
i++;
|
var i = 0,
|
||||||
}
|
found = divisors[Math.floor(divisors.length/2)];
|
||||||
if (i > 0) {
|
|
||||||
if (Math.abs(common[i] - desiredPatchSize) > Math.abs(common[i-1] - desiredPatchSize)) {
|
while(i < (divisors.length - 1) && divisors[i] < desiredPatchSize) {
|
||||||
found = common[i-1];
|
i++;
|
||||||
} else {
|
|
||||||
found = common[i];
|
|
||||||
}
|
}
|
||||||
|
if (i > 0) {
|
||||||
|
if (Math.abs(divisors[i] - desiredPatchSize) > Math.abs(divisors[i-1] - desiredPatchSize)) {
|
||||||
|
found = divisors[i-1];
|
||||||
|
} else {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
return {x: found, y: found};
|
|
||||||
|
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);
|
return (CVUtils);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+1
-12
@@ -10,7 +10,7 @@ define(["cv_utils"], function(CVUtils) {
|
|||||||
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(_streamConfig.size, _streamConfig.size) : _video_size,
|
_size =_streamConfig.size ? CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()) : _video_size,
|
||||||
_sx = 0,
|
_sx = 0,
|
||||||
_sy = 0,
|
_sy = 0,
|
||||||
_dx = 0,
|
_dx = 0,
|
||||||
@@ -23,17 +23,6 @@ define(["cv_utils"], function(CVUtils) {
|
|||||||
_ctx = null,
|
_ctx = null,
|
||||||
_data = 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;
|
_sWidth = _video_size.x;
|
||||||
_dWidth = _size.x;
|
_dWidth = _size.x;
|
||||||
_sHeight = _video_size.y;
|
_sHeight = _video_size.y;
|
||||||
|
|||||||
+14
-2
@@ -130,6 +130,8 @@ define(["image_loader"], function(ImageLoader) {
|
|||||||
offset = 1,
|
offset = 1,
|
||||||
baseUrl = null,
|
baseUrl = null,
|
||||||
ended = false,
|
ended = false,
|
||||||
|
calculatedWidth,
|
||||||
|
calculatedHeight,
|
||||||
_eventNames = ['canrecord', 'ended'],
|
_eventNames = ['canrecord', 'ended'],
|
||||||
_eventHandlers = {};
|
_eventHandlers = {};
|
||||||
|
|
||||||
@@ -139,6 +141,8 @@ define(["image_loader"], function(ImageLoader) {
|
|||||||
imgArray = imgs;
|
imgArray = imgs;
|
||||||
width = imgs[0].width;
|
width = imgs[0].width;
|
||||||
height = imgs[0].height;
|
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;
|
loaded = true;
|
||||||
frameIdx = 0;
|
frameIdx = 0;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@@ -162,11 +166,19 @@ define(["image_loader"], function(ImageLoader) {
|
|||||||
that.trigger = publishEvent;
|
that.trigger = publishEvent;
|
||||||
|
|
||||||
that.getWidth = function() {
|
that.getWidth = function() {
|
||||||
return _config.size ? width/height > 1 ? _config.size : (width/height) * _config.size : width;
|
return calculatedWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.getHeight = function() {
|
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() {
|
that.getRealWidth = function() {
|
||||||
|
|||||||
+10
-2
@@ -118,9 +118,17 @@ function(Code128Reader,
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (_config.locate) {
|
if (_config.locate) {
|
||||||
patchSize = CVUtils.calculatePatchSize(_config.locator.patchSize, size);
|
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));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user