mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Improved EAN Reading; Added extended configuration to live examples
This commit is contained in:
Vendored
+2
-2
@@ -1274,7 +1274,7 @@ define(
|
|||||||
|
|
||||||
EANReader.prototype._findEnd = function(offset, isWhite) {
|
EANReader.prototype._findEnd = function(offset, isWhite) {
|
||||||
var self = this,
|
var self = this,
|
||||||
endInfo = self._findPattern(self.STOP_PATTERN, offset, isWhite);
|
endInfo = self._findPattern(self.STOP_PATTERN, offset, isWhite, false);
|
||||||
|
|
||||||
return self._verifyTrailingWhitespace(endInfo);
|
return self._verifyTrailingWhitespace(endInfo);
|
||||||
};
|
};
|
||||||
@@ -1303,7 +1303,7 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
code = self._findPattern(self.MIDDLE_PATTERN, code.end, true);
|
code = self._findPattern(self.MIDDLE_PATTERN, code.end, true, false);
|
||||||
if (code === null) {
|
if (code === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
@@ -3,9 +3,6 @@ $(function() {
|
|||||||
init: function() {
|
init: function() {
|
||||||
App.attachListeners();
|
App.attachListeners();
|
||||||
},
|
},
|
||||||
config: {
|
|
||||||
reader: "upc"
|
|
||||||
},
|
|
||||||
attachListeners: function() {
|
attachListeners: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|||||||
+54
-18
@@ -26,24 +26,60 @@
|
|||||||
and <strong>EAN</strong> to test different scenarios.
|
and <strong>EAN</strong> to test different scenarios.
|
||||||
It works best if your camera has built-in auto-focus.
|
It works best if your camera has built-in auto-focus.
|
||||||
</p>
|
</p>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<button class="stop">Stop</button>
|
<fieldset class="input-group">
|
||||||
<fieldset class="reader-group">
|
<button class="stop">Stop</button>
|
||||||
<label>EAN-8</label>
|
</fieldset>
|
||||||
<input type="radio" name="reader" value="ean_8" checked />
|
<fieldset class="reader-config-group">
|
||||||
<label>UPC</label>
|
<label>
|
||||||
<input type="radio" name="reader" value="upc" />
|
<span>Barcode-Type</span>
|
||||||
<label>Code39</label>
|
<select name="decoder_readers">
|
||||||
<input type="radio" name="reader" value="codabar" />
|
<option value="code_128">Code 128</option>
|
||||||
<label>Code128</label>
|
<option value="code_39">Code 39</option>
|
||||||
<input type="radio" name="reader" value="code_128" />
|
<option value="ean" selected="selected">EAN</option>
|
||||||
<label>EAN</label>
|
<option value="ean_8">EAN-8</option>
|
||||||
<input type="radio" name="reader" value="ean" />
|
<option value="upc">UPC</option>
|
||||||
<label>Code39</label>
|
<option value="upc_e">UPC-E</option>
|
||||||
<input type="radio" name="reader" value="code_39" />
|
<option value="codabar">Codabar</option>
|
||||||
</fieldset>
|
</select>
|
||||||
<br clear="all" />
|
</label>
|
||||||
</div>
|
<label>
|
||||||
|
<span>Resolution (long side)</span>
|
||||||
|
<select name="input-stream_constraints">
|
||||||
|
<option value="320x240">320px</option>
|
||||||
|
<option selected="selected" value="640x480">640px</option>
|
||||||
|
<option value="800x600">800px</option>
|
||||||
|
<option value="1280x720">1280px</option>
|
||||||
|
<option value="1600x960">1600px</option>
|
||||||
|
<option value="1920x1080">1920px</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>Patch-Size</span>
|
||||||
|
<select name="locator_patch-size">
|
||||||
|
<option value="x-small">x-small</option>
|
||||||
|
<option value="small">small</option>
|
||||||
|
<option selected="selected" value="medium">medium</option>
|
||||||
|
<option value="large">large</option>
|
||||||
|
<option value="x-large">x-large</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>Half-Sample</span>
|
||||||
|
<input type="checkbox" checked="checked" name="locator_half-sample" />
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>Workers</span>
|
||||||
|
<select name="numOfWorkers">
|
||||||
|
<option value="0">0</option>
|
||||||
|
<option value="1">1</option>
|
||||||
|
<option value="2">2</option>
|
||||||
|
<option selected="selected" value="4">4</option>
|
||||||
|
<option value="8">8</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
<div id="result_strip">
|
<div id="result_strip">
|
||||||
<ul class="thumbnails"></ul>
|
<ul class="thumbnails"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+86
-16
@@ -1,33 +1,103 @@
|
|||||||
$(function() {
|
$(function() {
|
||||||
var App = {
|
var App = {
|
||||||
init : function() {
|
init : function() {
|
||||||
Quagga.init({
|
Quagga.init(this.state, function() {
|
||||||
inputStream : {
|
|
||||||
name : "Live",
|
|
||||||
type : "LiveStream"
|
|
||||||
},
|
|
||||||
decoder : {
|
|
||||||
readers : ["ean_8_reader"]
|
|
||||||
}
|
|
||||||
}, function() {
|
|
||||||
App.attachListeners();
|
App.attachListeners();
|
||||||
Quagga.start();
|
Quagga.start();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
attachListeners : function() {
|
attachListeners: function() {
|
||||||
$(".controls .reader-group").on("change", "input", function(e) {
|
var self = this;
|
||||||
e.preventDefault();
|
|
||||||
Quagga.setReaders([e.target.value + "_reader"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".controls").on("click", "button.stop", function(e) {
|
$(".controls").on("click", "button.stop", function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
Quagga.stop();
|
Quagga.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".controls .reader-config-group").on("change", "input, select", function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var $target = $(e.target),
|
||||||
|
value = $target.attr("type") === "checkbox" ? $target.prop("checked") : $target.val(),
|
||||||
|
name = $target.attr("name"),
|
||||||
|
state = self._convertNameToState(name);
|
||||||
|
|
||||||
|
console.log("Value of "+ state + " changed to " + value);
|
||||||
|
self.setState(state, value);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
detachListeners : function() {
|
_accessByPath: function(obj, path, val) {
|
||||||
$(".controls .reader-group").off("change", "input");
|
var parts = path.split('.'),
|
||||||
|
depth = parts.length,
|
||||||
|
setter = (typeof val !== "undefined") ? true : false;
|
||||||
|
|
||||||
|
return parts.reduce(function(o, key, i) {
|
||||||
|
if (setter && (i + 1) === depth) {
|
||||||
|
o[key] = val;
|
||||||
|
}
|
||||||
|
return key in o ? o[key] : {};
|
||||||
|
}, obj);
|
||||||
|
},
|
||||||
|
_convertNameToState: function(name) {
|
||||||
|
return name.replace("_", ".").split("-").reduce(function(result, value) {
|
||||||
|
return result + value.charAt(0).toUpperCase() + value.substring(1);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
detachListeners: function() {
|
||||||
$(".controls").off("click", "button.stop");
|
$(".controls").off("click", "button.stop");
|
||||||
|
$(".controls .reader-config-group").off("change", "input, select");
|
||||||
|
},
|
||||||
|
setState: function(path, value) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
if (typeof self._accessByPath(self.inputMapper, path) === "function") {
|
||||||
|
value = self._accessByPath(self.inputMapper, path)(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
self._accessByPath(self.state, path, value);
|
||||||
|
|
||||||
|
console.log(JSON.stringify(self.state));
|
||||||
|
App.detachListeners();
|
||||||
|
Quagga.stop();
|
||||||
|
App.init();
|
||||||
|
},
|
||||||
|
inputMapper: {
|
||||||
|
inputStream: {
|
||||||
|
constraints: function(value){
|
||||||
|
var values = value.split('x');
|
||||||
|
return {
|
||||||
|
width: parseInt(values[0]),
|
||||||
|
height: parseInt(values[1]),
|
||||||
|
facing: "environment"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
numOfWorkers: function(value) {
|
||||||
|
return parseInt(value);
|
||||||
|
},
|
||||||
|
decoder: {
|
||||||
|
readers: function(value) {
|
||||||
|
return [value + "_reader"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
state: {
|
||||||
|
inputStream: {
|
||||||
|
type : "LiveStream",
|
||||||
|
constraints: {
|
||||||
|
width: 640,
|
||||||
|
height: 480,
|
||||||
|
facing: "environment" // or user
|
||||||
|
}
|
||||||
|
},
|
||||||
|
locator: {
|
||||||
|
patchSize: "medium",
|
||||||
|
halfSample: true
|
||||||
|
},
|
||||||
|
numOfWorkers: 4,
|
||||||
|
decoder: {
|
||||||
|
readers : ["ean_reader"]
|
||||||
|
},
|
||||||
|
locate: true
|
||||||
},
|
},
|
||||||
lastResult : null
|
lastResult : null
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-2
@@ -201,7 +201,7 @@ define(
|
|||||||
|
|
||||||
EANReader.prototype._findEnd = function(offset, isWhite) {
|
EANReader.prototype._findEnd = function(offset, isWhite) {
|
||||||
var self = this,
|
var self = this,
|
||||||
endInfo = self._findPattern(self.STOP_PATTERN, offset, isWhite);
|
endInfo = self._findPattern(self.STOP_PATTERN, offset, isWhite, false);
|
||||||
|
|
||||||
return self._verifyTrailingWhitespace(endInfo);
|
return self._verifyTrailingWhitespace(endInfo);
|
||||||
};
|
};
|
||||||
@@ -230,7 +230,7 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
code = self._findPattern(self.MIDDLE_PATTERN, code.end, true);
|
code = self._findPattern(self.MIDDLE_PATTERN, code.end, true, false);
|
||||||
if (code === null) {
|
if (code === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user