mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-13 05:31:37 +08:00
Fixed static images example
This commit is contained in:
Vendored
+35
-12
@@ -4719,8 +4719,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function fromConfig(config) {
|
function _fromConfig(config) {
|
||||||
var scanner = /* harmony import */__WEBPACK_IMPORTED_MODULE_3__scanner__["a"].bind()();
|
var scanner = /* harmony import */__WEBPACK_IMPORTED_MODULE_3__scanner__["a"].bind()();
|
||||||
|
var pendingStart = null;
|
||||||
|
var initialized = false;
|
||||||
return {
|
return {
|
||||||
addEventListener: function addEventListener(eventType, cb) {
|
addEventListener: function addEventListener(eventType, cb) {
|
||||||
scanner.subscribe(eventType, cb);
|
scanner.subscribe(eventType, cb);
|
||||||
@@ -4731,14 +4733,29 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
start: function start() {
|
start: function start() {
|
||||||
scanner.init(config, function (error) {
|
if (scanner.isRunning()) {
|
||||||
if (error) {
|
return Promise.resolve(true);
|
||||||
console.log(error);
|
}
|
||||||
throw error;
|
if (pendingStart) {
|
||||||
}
|
return pendingStart;
|
||||||
|
}
|
||||||
|
if (initialized) {
|
||||||
scanner.start();
|
scanner.start();
|
||||||
|
return Promise.resolve(true);
|
||||||
|
}
|
||||||
|
pendingStart = new Promise(function (resolve, reject) {
|
||||||
|
scanner.init(config, function (error) {
|
||||||
|
if (error) {
|
||||||
|
console.log(error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
initialized = true;
|
||||||
|
scanner.start();
|
||||||
|
resolve();
|
||||||
|
pendingStart = null;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return this;
|
return pendingStart;
|
||||||
},
|
},
|
||||||
stop: function stop() {
|
stop: function stop() {
|
||||||
scanner.stop();
|
scanner.stop();
|
||||||
@@ -4801,7 +4818,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
var inputConfig = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
var inputConfig = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||||
|
|
||||||
config = /* harmony import */__WEBPACK_IMPORTED_MODULE_8__input_config_factory__["a"].bind()(config, inputConfig, source);
|
config = /* harmony import */__WEBPACK_IMPORTED_MODULE_8__input_config_factory__["a"].bind()(config, inputConfig, source);
|
||||||
return fromConfig(config);
|
return _fromConfig(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setConfig() {
|
function setConfig() {
|
||||||
@@ -4824,8 +4841,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
return _fromSource(configuration, src, inputConfig);
|
return _fromSource(configuration, src, inputConfig);
|
||||||
},
|
},
|
||||||
fromConfig: function fromConfig(conf) {
|
fromConfig: function fromConfig(conf) {
|
||||||
// check if source is given an return scanner
|
return _fromConfig(/* harmony import */__WEBPACK_IMPORTED_MODULE_0_lodash_merge___default.a.bind()({}, configuration, conf));
|
||||||
return createApi(/* harmony import */__WEBPACK_IMPORTED_MODULE_0_lodash_merge___default.a.bind()({}, configuration, conf));
|
|
||||||
},
|
},
|
||||||
decoder: function decoder(conf) {
|
decoder: function decoder(conf) {
|
||||||
return setConfig(configuration, "decoder", conf);
|
return setConfig(configuration, "decoder", conf);
|
||||||
@@ -6497,6 +6513,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
that.clearEventHandlers = function () {
|
||||||
|
_eventHandlers = {};
|
||||||
|
};
|
||||||
|
|
||||||
that.setTopRight = function (topRight) {
|
that.setTopRight = function (topRight) {
|
||||||
_topRight.x = topRight.x;
|
_topRight.x = topRight.x;
|
||||||
_topRight.y = topRight.y;
|
_topRight.y = topRight.y;
|
||||||
@@ -8916,7 +8936,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
function createScanner() {
|
function createScanner() {
|
||||||
var _inputStream,
|
var _inputStream,
|
||||||
_framegrabber,
|
_framegrabber,
|
||||||
_stopped,
|
_stopped = true,
|
||||||
_canvasContainer = {
|
_canvasContainer = {
|
||||||
ctx: {
|
ctx: {
|
||||||
image: null
|
image: null
|
||||||
@@ -9355,13 +9375,16 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
start: function start() {
|
start: function start() {
|
||||||
_start();
|
_start();
|
||||||
},
|
},
|
||||||
|
isRunning: function isRunning() {
|
||||||
|
return !_stopped;
|
||||||
|
},
|
||||||
stop: function stop() {
|
stop: function stop() {
|
||||||
_stopped = true;
|
_stopped = true;
|
||||||
adjustWorkerPool(0);
|
adjustWorkerPool(0);
|
||||||
if (_config.inputStream.type === "LiveStream") {
|
if (_config.inputStream.type === "LiveStream") {
|
||||||
/* harmony import */__WEBPACK_IMPORTED_MODULE_5__input_camera_access__["a"].release();
|
/* harmony import */__WEBPACK_IMPORTED_MODULE_5__input_camera_access__["a"].release();
|
||||||
_inputStream.clearEventHandlers();
|
|
||||||
}
|
}
|
||||||
|
_inputStream.clearEventHandlers();
|
||||||
},
|
},
|
||||||
pause: function pause() {
|
pause: function pause() {
|
||||||
_stopped = true;
|
_stopped = true;
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+2
-2
File diff suppressed because one or more lines are too long
@@ -57,7 +57,7 @@ $(function() {
|
|||||||
this.detachListeners();
|
this.detachListeners();
|
||||||
console.log("decode...");
|
console.log("decode...");
|
||||||
var scanner = Quagga
|
var scanner = Quagga
|
||||||
.fromConfig(this.state)
|
.config(this.state)
|
||||||
.fromSource(file, {size: this.state.inputStream.size});
|
.fromSource(file, {size: this.state.inputStream.size});
|
||||||
scanner
|
scanner
|
||||||
.toPromise()
|
.toPromise()
|
||||||
|
|||||||
@@ -51,7 +51,9 @@
|
|||||||
<div id="result_strip">
|
<div id="result_strip">
|
||||||
<ul class="thumbnails"></ul>
|
<ul class="thumbnails"></ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="interactive" class="viewport"></div>
|
<div id="interactive" class="viewport">
|
||||||
|
<canvas class="drawing" />
|
||||||
|
</div>
|
||||||
<div id="debug" class="detection"></div>
|
<div id="debug" class="detection"></div>
|
||||||
</section>
|
</section>
|
||||||
<footer>
|
<footer>
|
||||||
|
|||||||
+34
-19
@@ -1,11 +1,20 @@
|
|||||||
$(function() {
|
$(function() {
|
||||||
var App = {
|
var App = {
|
||||||
init: function() {
|
init: function() {
|
||||||
|
this.overlay = document.querySelector('#interactive canvas.drawing');
|
||||||
var config = this.config[this.state.decoder.readers[0].format] || this.config.default;
|
var config = this.config[this.state.decoder.readers[0].format] || this.config.default;
|
||||||
config = $.extend(true, {}, config, this.state);
|
config = $.extend(true, {}, config, this.state);
|
||||||
Quagga.init(config, function() {
|
|
||||||
App.attachListeners();
|
this.scanner = Quagga
|
||||||
Quagga.start();
|
.fromConfig(config);
|
||||||
|
|
||||||
|
this.scanner
|
||||||
|
.addEventListener("processed", drawResult.bind(this, this.scanner))
|
||||||
|
.addEventListener("detected", addToResults.bind(this, this.scanner));
|
||||||
|
|
||||||
|
this.scanner.start().then(() => {
|
||||||
|
console.log("Started");
|
||||||
|
this.attachListeners();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
@@ -37,7 +46,7 @@ $(function() {
|
|||||||
|
|
||||||
$(".controls").on("click", "button.next", function(e) {
|
$(".controls").on("click", "button.next", function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
Quagga.start();
|
self.scanner.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".controls .reader-config-group").on("change", "input, select", function(e) {
|
$(".controls .reader-config-group").on("change", "input, select", function(e) {
|
||||||
@@ -89,7 +98,8 @@ $(function() {
|
|||||||
|
|
||||||
console.log(JSON.stringify(self.state));
|
console.log(JSON.stringify(self.state));
|
||||||
App.detachListeners();
|
App.detachListeners();
|
||||||
Quagga.stop();
|
this.scanner.stop();
|
||||||
|
this.scanner.removeEventListener();
|
||||||
App.init();
|
App.init();
|
||||||
},
|
},
|
||||||
inputMapper: {
|
inputMapper: {
|
||||||
@@ -121,6 +131,7 @@ $(function() {
|
|||||||
inputStream: {
|
inputStream: {
|
||||||
src: "../test/fixtures/code_128/"
|
src: "../test/fixtures/code_128/"
|
||||||
},
|
},
|
||||||
|
numOfWorkers: 1,
|
||||||
decoder : {
|
decoder : {
|
||||||
readers : [{
|
readers : [{
|
||||||
format: "code_128_reader",
|
format: "code_128_reader",
|
||||||
@@ -133,38 +144,42 @@ $(function() {
|
|||||||
App.init();
|
App.init();
|
||||||
window.App = App;
|
window.App = App;
|
||||||
|
|
||||||
Quagga.onProcessed(function(result) {
|
function drawResult(scanner, result) {
|
||||||
var drawingCtx = Quagga.canvas.ctx.overlay,
|
var processingCanvas = scanner.getCanvas(),
|
||||||
drawingCanvas = Quagga.canvas.dom.overlay;
|
canvas = App.overlay,
|
||||||
|
ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
|
canvas.setAttribute('width', processingCanvas.getAttribute('width'));
|
||||||
|
canvas.setAttribute('height', processingCanvas.getAttribute('height'));
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
if (result.boxes) {
|
if (result.boxes) {
|
||||||
drawingCtx.clearRect(0, 0, parseInt(drawingCanvas.getAttribute("width")), parseInt(drawingCanvas.getAttribute("height")));
|
ctx.clearRect(0, 0, parseInt(canvas.getAttribute("width")), parseInt(canvas.getAttribute("height")));
|
||||||
result.boxes.filter(function (box) {
|
result.boxes.filter(function (box) {
|
||||||
return box !== result.box;
|
return box !== result.box;
|
||||||
}).forEach(function (box) {
|
}).forEach(function (box) {
|
||||||
Quagga.ImageDebug.drawPath(box, {x: 0, y: 1}, drawingCtx, {color: "green", lineWidth: 2});
|
Quagga.ImageDebug.drawPath(box, {x: 0, y: 1}, ctx, {color: "green", lineWidth: 2});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.box) {
|
if (result.box) {
|
||||||
Quagga.ImageDebug.drawPath(result.box, {x: 0, y: 1}, drawingCtx, {color: "#00F", lineWidth: 2});
|
Quagga.ImageDebug.drawPath(result.box, {x: 0, y: 1}, ctx, {color: "#00F", lineWidth: 2});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.codeResult && result.codeResult.code) {
|
if (result.codeResult && result.codeResult.code) {
|
||||||
Quagga.ImageDebug.drawPath(result.line, {x: 'x', y: 'y'}, drawingCtx, {color: 'red', lineWidth: 3});
|
Quagga.ImageDebug.drawPath(result.line, {x: 'x', y: 'y'}, ctx, {color: 'red', lineWidth: 3});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
Quagga.onDetected(function(result) {
|
function addToResults(scanner, result) {
|
||||||
var $node,
|
var code = result.codeResult.code,
|
||||||
canvas = Quagga.canvas.dom.image,
|
$node,
|
||||||
detectedCode = result.codeResult.code;
|
canvas = scanner.getCanvas();
|
||||||
|
|
||||||
$node = $('<li><div class="thumbnail"><div class="imgWrapper"><img /></div><div class="caption"><h4 class="code"></h4></div></div></li>');
|
$node = $('<li><div class="thumbnail"><div class="imgWrapper"><img /></div><div class="caption"><h4 class="code"></h4></div></div></li>');
|
||||||
$node.find("img").attr("src", canvas.toDataURL());
|
$node.find("img").attr("src", canvas.toDataURL());
|
||||||
$node.find("h4.code").html(detectedCode);
|
$node.find("h4.code").html(code);
|
||||||
$("#result_strip ul.thumbnails").prepend($node);
|
$("#result_strip ul.thumbnails").prepend($node);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+31
-12
@@ -4814,8 +4814,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||||
|
|
||||||
function fromConfig(config) {
|
function _fromConfig(config) {
|
||||||
var scanner = (0, _scanner2.default)();
|
var scanner = (0, _scanner2.default)();
|
||||||
|
var pendingStart = null;
|
||||||
|
var initialized = false;
|
||||||
return {
|
return {
|
||||||
addEventListener: function addEventListener(eventType, cb) {
|
addEventListener: function addEventListener(eventType, cb) {
|
||||||
scanner.subscribe(eventType, cb);
|
scanner.subscribe(eventType, cb);
|
||||||
@@ -4826,14 +4828,29 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
start: function start() {
|
start: function start() {
|
||||||
scanner.init(config, function (error) {
|
if (scanner.isRunning()) {
|
||||||
if (error) {
|
return Promise.resolve(true);
|
||||||
console.log(error);
|
}
|
||||||
throw error;
|
if (pendingStart) {
|
||||||
}
|
return pendingStart;
|
||||||
|
}
|
||||||
|
if (initialized) {
|
||||||
scanner.start();
|
scanner.start();
|
||||||
|
return Promise.resolve(true);
|
||||||
|
}
|
||||||
|
pendingStart = new Promise(function (resolve, reject) {
|
||||||
|
scanner.init(config, function (error) {
|
||||||
|
if (error) {
|
||||||
|
console.log(error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
initialized = true;
|
||||||
|
scanner.start();
|
||||||
|
resolve();
|
||||||
|
pendingStart = null;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return this;
|
return pendingStart;
|
||||||
},
|
},
|
||||||
stop: function stop() {
|
stop: function stop() {
|
||||||
scanner.stop();
|
scanner.stop();
|
||||||
@@ -4896,7 +4913,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
var inputConfig = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
var inputConfig = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||||
|
|
||||||
config = (0, _config_factory.createConfigFromSource)(config, inputConfig, source);
|
config = (0, _config_factory.createConfigFromSource)(config, inputConfig, source);
|
||||||
return fromConfig(config);
|
return _fromConfig(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setConfig() {
|
function setConfig() {
|
||||||
@@ -4919,8 +4936,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
return _fromSource(configuration, src, inputConfig);
|
return _fromSource(configuration, src, inputConfig);
|
||||||
},
|
},
|
||||||
fromConfig: function fromConfig(conf) {
|
fromConfig: function fromConfig(conf) {
|
||||||
// check if source is given an return scanner
|
return _fromConfig((0, _merge4.default)({}, configuration, conf));
|
||||||
return createApi((0, _merge4.default)({}, configuration, conf));
|
|
||||||
},
|
},
|
||||||
decoder: function decoder(conf) {
|
decoder: function decoder(conf) {
|
||||||
return setConfig(configuration, "decoder", conf);
|
return setConfig(configuration, "decoder", conf);
|
||||||
@@ -8947,7 +8963,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
function createScanner() {
|
function createScanner() {
|
||||||
var _inputStream,
|
var _inputStream,
|
||||||
_framegrabber,
|
_framegrabber,
|
||||||
_stopped,
|
_stopped = true,
|
||||||
_canvasContainer = {
|
_canvasContainer = {
|
||||||
ctx: {
|
ctx: {
|
||||||
image: null
|
image: null
|
||||||
@@ -9386,13 +9402,16 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
start: function start() {
|
start: function start() {
|
||||||
_start();
|
_start();
|
||||||
},
|
},
|
||||||
|
isRunning: function isRunning() {
|
||||||
|
return !_stopped;
|
||||||
|
},
|
||||||
stop: function stop() {
|
stop: function stop() {
|
||||||
_stopped = true;
|
_stopped = true;
|
||||||
adjustWorkerPool(0);
|
adjustWorkerPool(0);
|
||||||
if (_config.inputStream.type === "LiveStream") {
|
if (_config.inputStream.type === "LiveStream") {
|
||||||
_camera_access2.default.release();
|
_camera_access2.default.release();
|
||||||
_inputStream.clearEventHandlers();
|
|
||||||
}
|
}
|
||||||
|
_inputStream.clearEventHandlers();
|
||||||
},
|
},
|
||||||
pause: function pause() {
|
pause: function pause() {
|
||||||
_stopped = true;
|
_stopped = true;
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -273,6 +273,10 @@ InputStream.createImageStream = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
that.clearEventHandlers = function() {
|
||||||
|
_eventHandlers = {};
|
||||||
|
};
|
||||||
|
|
||||||
that.setTopRight = function(topRight) {
|
that.setTopRight = function(topRight) {
|
||||||
_topRight.x = topRight.x;
|
_topRight.x = topRight.x;
|
||||||
_topRight.y = topRight.y;
|
_topRight.y = topRight.y;
|
||||||
|
|||||||
+24
-8
@@ -10,6 +10,8 @@ import {createConfigFromSource} from './input/config_factory';
|
|||||||
|
|
||||||
function fromConfig(config) {
|
function fromConfig(config) {
|
||||||
const scanner = createScanner();
|
const scanner = createScanner();
|
||||||
|
let pendingStart = null;
|
||||||
|
let initialized = false;
|
||||||
return {
|
return {
|
||||||
addEventListener(eventType, cb) {
|
addEventListener(eventType, cb) {
|
||||||
scanner.subscribe(eventType, cb);
|
scanner.subscribe(eventType, cb);
|
||||||
@@ -20,14 +22,29 @@ function fromConfig(config) {
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
start() {
|
start() {
|
||||||
scanner.init(config, (error) => {
|
if (scanner.isRunning()) {
|
||||||
if (error) {
|
return Promise.resolve(true);
|
||||||
console.log(error);
|
}
|
||||||
throw error;
|
if (pendingStart) {
|
||||||
}
|
return pendingStart;
|
||||||
|
}
|
||||||
|
if (initialized) {
|
||||||
scanner.start();
|
scanner.start();
|
||||||
|
return Promise.resolve(true);
|
||||||
|
}
|
||||||
|
pendingStart = new Promise((resolve, reject) => {
|
||||||
|
scanner.init(config, (error) => {
|
||||||
|
if (error) {
|
||||||
|
console.log(error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
initialized = true;
|
||||||
|
scanner.start();
|
||||||
|
resolve();
|
||||||
|
pendingStart = null;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return this;
|
return pendingStart;
|
||||||
},
|
},
|
||||||
stop() {
|
stop() {
|
||||||
scanner.stop();
|
scanner.stop();
|
||||||
@@ -94,8 +111,7 @@ function createApi(configuration = Config) {
|
|||||||
return fromSource(configuration, src, inputConfig);
|
return fromSource(configuration, src, inputConfig);
|
||||||
},
|
},
|
||||||
fromConfig(conf) {
|
fromConfig(conf) {
|
||||||
// check if source is given an return scanner
|
return fromConfig(merge({}, configuration, conf));
|
||||||
return createApi(merge({}, configuration, conf));
|
|
||||||
},
|
},
|
||||||
decoder(conf) {
|
decoder(conf) {
|
||||||
return setConfig(configuration, "decoder", conf);
|
return setConfig(configuration, "decoder", conf);
|
||||||
|
|||||||
+5
-2
@@ -17,7 +17,7 @@ const vec2 = {
|
|||||||
function createScanner() {
|
function createScanner() {
|
||||||
var _inputStream,
|
var _inputStream,
|
||||||
_framegrabber,
|
_framegrabber,
|
||||||
_stopped,
|
_stopped = true,
|
||||||
_canvasContainer = {
|
_canvasContainer = {
|
||||||
ctx: {
|
ctx: {
|
||||||
image: null
|
image: null
|
||||||
@@ -467,13 +467,16 @@ function createScanner() {
|
|||||||
start: function() {
|
start: function() {
|
||||||
start();
|
start();
|
||||||
},
|
},
|
||||||
|
isRunning: function() {
|
||||||
|
return !_stopped;
|
||||||
|
},
|
||||||
stop: function() {
|
stop: function() {
|
||||||
_stopped = true;
|
_stopped = true;
|
||||||
adjustWorkerPool(0);
|
adjustWorkerPool(0);
|
||||||
if (_config.inputStream.type === "LiveStream") {
|
if (_config.inputStream.type === "LiveStream") {
|
||||||
CameraAccess.release();
|
CameraAccess.release();
|
||||||
_inputStream.clearEventHandlers();
|
|
||||||
}
|
}
|
||||||
|
_inputStream.clearEventHandlers();
|
||||||
},
|
},
|
||||||
pause: function() {
|
pause: function() {
|
||||||
_stopped = true;
|
_stopped = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user