Adding Code39VINReader

pull/35/head
Lindsey Simon 10 years ago
parent fc04683054
commit d362791f61

86
dist/quagga.js vendored

@ -6589,7 +6589,9 @@ define(
return counter;
};
Code39Reader.prototype._decode = function() {
Code39Reader.prototype._decodeToResult = function() {
var self = this,
counters = [0,0,0,0,0,0,0,0,0],
result = [],
@ -6599,6 +6601,7 @@ define(
pattern,
nextStart;
if (!start) {
return null;
}
@ -6621,8 +6624,6 @@ define(
} while(decodedChar !== '*');
result.pop();
return {
code : result.join(""),
start : start.start,
@ -6632,6 +6633,10 @@ define(
};
};
Code39Reader.prototype._decode = function() {
return this._decodeToResult();
};
Code39Reader.prototype._patternToChar = function(pattern) {
var i,
self = this;
@ -6740,6 +6745,67 @@ define(
return (Code39Reader);
}
);
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define(
'code_39_vin_reader',[
"./code_39_reader"
],
function(Code39Reader) {
"use strict";
function Code39VINReader() {
Code39Reader.call(this);
}
var patterns = {
IOQ: /[IOQ]/g,
AZ09: /[A-Z0-9]{17}/
};
Code39VINReader.prototype = Object.create(Code39Reader.prototype);
Code39VINReader.prototype.constructor = Code39VINReader;
// Cribbed from:
// https://github.com/zxing/zxing/blob/master/core/src/main/java/com/google/zxing/client/result/VINResultParser.java
Code39VINReader.prototype._decode = function() {
var result = this._decodeToResult();
if (!result) {
return null;
}
var code = result.code;
if (!code) {
return;
}
code = code.replace(patterns.IOQ, '');
if (!code.match(patterns.AZ09)) {
console.log('Failed AZ09 pattern code:', code);
return null;
}
if (!this._checkChecksum(code)) {
return null;
}
result.code = code;
return result;
};
Code39VINReader.prototype._checkChecksum = function(code) {
// TODO
return !!code;
};
return (Code39VINReader);
}
);
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
@ -7247,6 +7313,7 @@ define('barcode_decoder',[
'code_128_reader',
'ean_reader',
'code_39_reader',
'code_39_vin_reader',
'codabar_reader',
'upc_reader',
'ean_8_reader',
@ -7257,6 +7324,7 @@ define('barcode_decoder',[
Code128Reader,
EANReader,
Code39Reader,
Code39VINReader,
CodabarReader,
UPCReader,
EAN8Reader,
@ -7268,6 +7336,7 @@ define('barcode_decoder',[
ean_reader: EANReader,
ean_8_reader: EAN8Reader,
code_39_reader: Code39Reader,
code_39_vin_reader: Code39VINReader,
codabar_reader: CodabarReader,
upc_reader: UPCReader,
upc_e_reader: UPCEReader
@ -7534,6 +7603,7 @@ define('barcode_decoder',[
return (BarcodeDecoder);
});
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
@ -7678,6 +7748,8 @@ define('config',[],function(){
constraints: {
width: 640,
height: 480,
minAspectRatio: 1,
maxAspectRatio: 1,
facing: "environment" // or user
}
},
@ -7718,6 +7790,7 @@ define('config',[],function(){
return config;
});
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
@ -7885,6 +7958,8 @@ define('camera_access',["html_utils"], function(HtmlUtils) {
videoConstraints = HtmlUtils.mergeObjects({
width: 640,
height: 480,
minAspectRatio: 1,
maxAspectRatio: 1,
facing: "environment"
}, config);
@ -7900,7 +7975,9 @@ define('camera_access',["html_utils"], function(HtmlUtils) {
constraints.video = {
mandatory: {
minWidth: videoConstraints.width,
minHeight: videoConstraints.height
minHeight: videoConstraints.height,
minAspectRatio: videoConstraints.minAspectRatio,
maxAspectRatio: videoConstraints.maxAspectRatio
},
optional: [{
sourceId: videoSourceId
@ -7944,6 +8021,7 @@ define('camera_access',["html_utils"], function(HtmlUtils) {
}
};
});
/* jshint undef: true, unused: true, browser:true, devel: true, evil: true */
/* global define, vec2 */

@ -37,6 +37,7 @@
<select name="decoder_readers;input-stream_src">
<option value="code_128" selected="selected">Code 128</option>
<option value="code_39">Code 39</option>
<option value="code_39_vin">Code 39 VIN</option>
<option value="ean">EAN</option>
<option value="ean_8">EAN-8</option>
<option value="upc">UPC</option>

@ -84,18 +84,27 @@ $(function() {
state: {
inputStream: { name: "Test",
type: "ImageStream",
src: "../test/fixtures/code_128/",
src: "../test/fixtures/code_39_vin/",
length: 10
},
decoder : {
readers : ["code_128_reader"]
readers : ["code_39_vin_reader"],
drawScanline: true,
},
numOfWorkers: 4,
locator: {
halfSample: false,
showSkeleton: true,
showFoundPatches: true
}
}
};
App.init();
window.App = App;
Quagga.onProcessed(function(result) {
console.log('Quagga.onProcessed', result);
var drawingCtx = Quagga.canvas.ctx.overlay,
drawingCanvas = Quagga.canvas.dom.overlay;

@ -4,7 +4,7 @@
"description": "An advanced barcode-scanner written in JavaScript",
"main": "dist/quagga.js",
"devDependencies": {
"grunt": "~0.4.6",
"grunt": "~0.4.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.5.0",

@ -7,6 +7,7 @@ define([
'code_128_reader',
'ean_reader',
'code_39_reader',
'code_39_vin_reader',
'codabar_reader',
'upc_reader',
'ean_8_reader',
@ -17,6 +18,7 @@ define([
Code128Reader,
EANReader,
Code39Reader,
Code39VINReader,
CodabarReader,
UPCReader,
EAN8Reader,
@ -28,6 +30,7 @@ define([
ean_reader: EANReader,
ean_8_reader: EAN8Reader,
code_39_reader: Code39Reader,
code_39_vin_reader: Code39VINReader,
codabar_reader: CodabarReader,
upc_reader: UPCReader,
upc_e_reader: UPCEReader

@ -74,6 +74,8 @@ define(["html_utils"], function(HtmlUtils) {
videoConstraints = HtmlUtils.mergeObjects({
width: 640,
height: 480,
minAspectRatio: 1,
maxAspectRatio: 1,
facing: "environment"
}, config);
@ -89,7 +91,9 @@ define(["html_utils"], function(HtmlUtils) {
constraints.video = {
mandatory: {
minWidth: videoConstraints.width,
minHeight: videoConstraints.height
minHeight: videoConstraints.height,
minAspectRatio: videoConstraints.minAspectRatio,
maxAspectRatio: videoConstraints.maxAspectRatio
},
optional: [{
sourceId: videoSourceId

@ -0,0 +1,59 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define(
[
"./code_39_reader"
],
function(Code39Reader) {
"use strict";
function Code39VINReader() {
Code39Reader.call(this);
}
var patterns = {
IOQ: /[IOQ]/g,
AZ09: /[A-Z0-9]{17}/
};
Code39VINReader.prototype = Object.create(Code39Reader.prototype);
Code39VINReader.prototype.constructor = Code39VINReader;
// Cribbed from:
// https://github.com/zxing/zxing/blob/master/core/src/main/java/com/google/zxing/client/result/VINResultParser.java
Code39VINReader.prototype._decode = function() {
var result = Code39Reader.prototype._decode.apply(this);
if (!result) {
return null;
}
var code = result.code;
if (!code) {
return;
}
code = code.replace(patterns.IOQ, '');
if (!code.match(patterns.AZ09)) {
console.log('Failed AZ09 pattern code:', code);
return null;
}
if (!this._checkChecksum(code)) {
return null;
}
result.code = code;
return result;
};
Code39VINReader.prototype._checkChecksum = function(code) {
// TODO
return !!code;
};
return (Code39VINReader);
}
);

@ -9,6 +9,8 @@ define(function(){
constraints: {
width: 640,
height: 480,
minAspectRatio: 1,
maxAspectRatio: 1,
facing: "environment" // or user
}
},

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 KiB

Loading…
Cancel
Save