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 pendingStart = null;
|
||||
var initialized = false;
|
||||
return {
|
||||
addEventListener: function addEventListener(eventType, cb) {
|
||||
scanner.subscribe(eventType, cb);
|
||||
@@ -4731,14 +4733,29 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
return this;
|
||||
},
|
||||
start: function start() {
|
||||
scanner.init(config, function (error) {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
}
|
||||
if (scanner.isRunning()) {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
if (pendingStart) {
|
||||
return pendingStart;
|
||||
}
|
||||
if (initialized) {
|
||||
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() {
|
||||
scanner.stop();
|
||||
@@ -4801,7 +4818,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
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);
|
||||
return fromConfig(config);
|
||||
return _fromConfig(config);
|
||||
}
|
||||
|
||||
function setConfig() {
|
||||
@@ -4824,8 +4841,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
return _fromSource(configuration, src, inputConfig);
|
||||
},
|
||||
fromConfig: function fromConfig(conf) {
|
||||
// check if source is given an return scanner
|
||||
return createApi(/* harmony import */__WEBPACK_IMPORTED_MODULE_0_lodash_merge___default.a.bind()({}, configuration, conf));
|
||||
return _fromConfig(/* harmony import */__WEBPACK_IMPORTED_MODULE_0_lodash_merge___default.a.bind()({}, configuration, conf));
|
||||
},
|
||||
decoder: function decoder(conf) {
|
||||
return setConfig(configuration, "decoder", conf);
|
||||
@@ -6497,6 +6513,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
}
|
||||
};
|
||||
|
||||
that.clearEventHandlers = function () {
|
||||
_eventHandlers = {};
|
||||
};
|
||||
|
||||
that.setTopRight = function (topRight) {
|
||||
_topRight.x = topRight.x;
|
||||
_topRight.y = topRight.y;
|
||||
@@ -8916,7 +8936,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
function createScanner() {
|
||||
var _inputStream,
|
||||
_framegrabber,
|
||||
_stopped,
|
||||
_stopped = true,
|
||||
_canvasContainer = {
|
||||
ctx: {
|
||||
image: null
|
||||
@@ -9355,13 +9375,16 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
start: function start() {
|
||||
_start();
|
||||
},
|
||||
isRunning: function isRunning() {
|
||||
return !_stopped;
|
||||
},
|
||||
stop: function stop() {
|
||||
_stopped = true;
|
||||
adjustWorkerPool(0);
|
||||
if (_config.inputStream.type === "LiveStream") {
|
||||
/* harmony import */__WEBPACK_IMPORTED_MODULE_5__input_camera_access__["a"].release();
|
||||
_inputStream.clearEventHandlers();
|
||||
}
|
||||
_inputStream.clearEventHandlers();
|
||||
},
|
||||
pause: function pause() {
|
||||
_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();
|
||||
console.log("decode...");
|
||||
var scanner = Quagga
|
||||
.fromConfig(this.state)
|
||||
.config(this.state)
|
||||
.fromSource(file, {size: this.state.inputStream.size});
|
||||
scanner
|
||||
.toPromise()
|
||||
|
||||
@@ -51,7 +51,9 @@
|
||||
<div id="result_strip">
|
||||
<ul class="thumbnails"></ul>
|
||||
</div>
|
||||
<div id="interactive" class="viewport"></div>
|
||||
<div id="interactive" class="viewport">
|
||||
<canvas class="drawing" />
|
||||
</div>
|
||||
<div id="debug" class="detection"></div>
|
||||
</section>
|
||||
<footer>
|
||||
|
||||
+34
-19
@@ -1,11 +1,20 @@
|
||||
$(function() {
|
||||
var App = {
|
||||
init: function() {
|
||||
this.overlay = document.querySelector('#interactive canvas.drawing');
|
||||
var config = this.config[this.state.decoder.readers[0].format] || this.config.default;
|
||||
config = $.extend(true, {}, config, this.state);
|
||||
Quagga.init(config, function() {
|
||||
App.attachListeners();
|
||||
Quagga.start();
|
||||
|
||||
this.scanner = Quagga
|
||||
.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: {
|
||||
@@ -37,7 +46,7 @@ $(function() {
|
||||
|
||||
$(".controls").on("click", "button.next", function(e) {
|
||||
e.preventDefault();
|
||||
Quagga.start();
|
||||
self.scanner.start();
|
||||
});
|
||||
|
||||
$(".controls .reader-config-group").on("change", "input, select", function(e) {
|
||||
@@ -89,7 +98,8 @@ $(function() {
|
||||
|
||||
console.log(JSON.stringify(self.state));
|
||||
App.detachListeners();
|
||||
Quagga.stop();
|
||||
this.scanner.stop();
|
||||
this.scanner.removeEventListener();
|
||||
App.init();
|
||||
},
|
||||
inputMapper: {
|
||||
@@ -121,6 +131,7 @@ $(function() {
|
||||
inputStream: {
|
||||
src: "../test/fixtures/code_128/"
|
||||
},
|
||||
numOfWorkers: 1,
|
||||
decoder : {
|
||||
readers : [{
|
||||
format: "code_128_reader",
|
||||
@@ -133,38 +144,42 @@ $(function() {
|
||||
App.init();
|
||||
window.App = App;
|
||||
|
||||
Quagga.onProcessed(function(result) {
|
||||
var drawingCtx = Quagga.canvas.ctx.overlay,
|
||||
drawingCanvas = Quagga.canvas.dom.overlay;
|
||||
function drawResult(scanner, result) {
|
||||
var processingCanvas = scanner.getCanvas(),
|
||||
canvas = App.overlay,
|
||||
ctx = canvas.getContext("2d");
|
||||
|
||||
canvas.setAttribute('width', processingCanvas.getAttribute('width'));
|
||||
canvas.setAttribute('height', processingCanvas.getAttribute('height'));
|
||||
|
||||
if (result) {
|
||||
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) {
|
||||
return box !== result.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) {
|
||||
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) {
|
||||
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) {
|
||||
var $node,
|
||||
canvas = Quagga.canvas.dom.image,
|
||||
detectedCode = result.codeResult.code;
|
||||
function addToResults(scanner, result) {
|
||||
var code = result.codeResult.code,
|
||||
$node,
|
||||
canvas = scanner.getCanvas();
|
||||
|
||||
$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("h4.code").html(detectedCode);
|
||||
$node.find("h4.code").html(code);
|
||||
$("#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 fromConfig(config) {
|
||||
function _fromConfig(config) {
|
||||
var scanner = (0, _scanner2.default)();
|
||||
var pendingStart = null;
|
||||
var initialized = false;
|
||||
return {
|
||||
addEventListener: function addEventListener(eventType, cb) {
|
||||
scanner.subscribe(eventType, cb);
|
||||
@@ -4826,14 +4828,29 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
return this;
|
||||
},
|
||||
start: function start() {
|
||||
scanner.init(config, function (error) {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
}
|
||||
if (scanner.isRunning()) {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
if (pendingStart) {
|
||||
return pendingStart;
|
||||
}
|
||||
if (initialized) {
|
||||
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() {
|
||||
scanner.stop();
|
||||
@@ -4896,7 +4913,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
var inputConfig = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
|
||||
config = (0, _config_factory.createConfigFromSource)(config, inputConfig, source);
|
||||
return fromConfig(config);
|
||||
return _fromConfig(config);
|
||||
}
|
||||
|
||||
function setConfig() {
|
||||
@@ -4919,8 +4936,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
return _fromSource(configuration, src, inputConfig);
|
||||
},
|
||||
fromConfig: function fromConfig(conf) {
|
||||
// check if source is given an return scanner
|
||||
return createApi((0, _merge4.default)({}, configuration, conf));
|
||||
return _fromConfig((0, _merge4.default)({}, configuration, conf));
|
||||
},
|
||||
decoder: function decoder(conf) {
|
||||
return setConfig(configuration, "decoder", conf);
|
||||
@@ -8947,7 +8963,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
function createScanner() {
|
||||
var _inputStream,
|
||||
_framegrabber,
|
||||
_stopped,
|
||||
_stopped = true,
|
||||
_canvasContainer = {
|
||||
ctx: {
|
||||
image: null
|
||||
@@ -9386,13 +9402,16 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
start: function start() {
|
||||
_start();
|
||||
},
|
||||
isRunning: function isRunning() {
|
||||
return !_stopped;
|
||||
},
|
||||
stop: function stop() {
|
||||
_stopped = true;
|
||||
adjustWorkerPool(0);
|
||||
if (_config.inputStream.type === "LiveStream") {
|
||||
_camera_access2.default.release();
|
||||
_inputStream.clearEventHandlers();
|
||||
}
|
||||
_inputStream.clearEventHandlers();
|
||||
},
|
||||
pause: function pause() {
|
||||
_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) {
|
||||
_topRight.x = topRight.x;
|
||||
_topRight.y = topRight.y;
|
||||
|
||||
+24
-8
@@ -10,6 +10,8 @@ import {createConfigFromSource} from './input/config_factory';
|
||||
|
||||
function fromConfig(config) {
|
||||
const scanner = createScanner();
|
||||
let pendingStart = null;
|
||||
let initialized = false;
|
||||
return {
|
||||
addEventListener(eventType, cb) {
|
||||
scanner.subscribe(eventType, cb);
|
||||
@@ -20,14 +22,29 @@ function fromConfig(config) {
|
||||
return this;
|
||||
},
|
||||
start() {
|
||||
scanner.init(config, (error) => {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
}
|
||||
if (scanner.isRunning()) {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
if (pendingStart) {
|
||||
return pendingStart;
|
||||
}
|
||||
if (initialized) {
|
||||
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() {
|
||||
scanner.stop();
|
||||
@@ -94,8 +111,7 @@ function createApi(configuration = Config) {
|
||||
return fromSource(configuration, src, inputConfig);
|
||||
},
|
||||
fromConfig(conf) {
|
||||
// check if source is given an return scanner
|
||||
return createApi(merge({}, configuration, conf));
|
||||
return fromConfig(merge({}, configuration, conf));
|
||||
},
|
||||
decoder(conf) {
|
||||
return setConfig(configuration, "decoder", conf);
|
||||
|
||||
+5
-2
@@ -17,7 +17,7 @@ const vec2 = {
|
||||
function createScanner() {
|
||||
var _inputStream,
|
||||
_framegrabber,
|
||||
_stopped,
|
||||
_stopped = true,
|
||||
_canvasContainer = {
|
||||
ctx: {
|
||||
image: null
|
||||
@@ -467,13 +467,16 @@ function createScanner() {
|
||||
start: function() {
|
||||
start();
|
||||
},
|
||||
isRunning: function() {
|
||||
return !_stopped;
|
||||
},
|
||||
stop: function() {
|
||||
_stopped = true;
|
||||
adjustWorkerPool(0);
|
||||
if (_config.inputStream.type === "LiveStream") {
|
||||
CameraAccess.release();
|
||||
_inputStream.clearEventHandlers();
|
||||
}
|
||||
_inputStream.clearEventHandlers();
|
||||
},
|
||||
pause: function() {
|
||||
_stopped = true;
|
||||
|
||||
Reference in New Issue
Block a user