mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Creating config programatically
This commit is contained in:
committed by
Christoph Oberhofer
parent
f3f656f3e7
commit
b733c2b7fd
@@ -1,10 +1,11 @@
|
||||
const vec2 = {
|
||||
clone: require('gl-vec2/clone'),
|
||||
dot: require('gl-vec2/dot')
|
||||
}
|
||||
/**
|
||||
* Creates a cluster for grouping similar orientations of datapoints
|
||||
*/
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a cluster for grouping similar orientations of datapoints
|
||||
*/
|
||||
export default {
|
||||
create: function(point, threshold) {
|
||||
var points = [],
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import Cluster2 from './cluster';
|
||||
import ArrayHelper from './array_helper';
|
||||
const vec2 = {
|
||||
clone: require('gl-vec2/clone'),
|
||||
clone: require('gl-vec2/clone')
|
||||
};
|
||||
const vec3 = {
|
||||
clone: require('gl-vec3/clone'),
|
||||
clone: require('gl-vec3/clone')
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import ImageWrapper from '../common/image_wrapper';
|
||||
|
||||
var Bresenham = {};
|
||||
|
||||
var Slope = {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {merge, pick} from 'lodash';
|
||||
|
||||
var streamRef,
|
||||
loadedDataHandler;
|
||||
var streamRef;
|
||||
|
||||
function waitForVideo(video) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
+84
-59
@@ -6,22 +6,28 @@ import Events from './common/events';
|
||||
import ImageDebug from './common/image_debug';
|
||||
import ResultCollector from './analytics/result_collector';
|
||||
import Config from './config/config';
|
||||
import {merge} from 'lodash';
|
||||
import {merge, pick, omitBy, isEmpty, omit} from 'lodash';
|
||||
|
||||
|
||||
function fromImage(config, imageSrc, imageConfig) {
|
||||
config = merge({
|
||||
inputStream: {
|
||||
type: "ImageStream",
|
||||
sequence: false,
|
||||
size: 800,
|
||||
src: imageSrc
|
||||
config =
|
||||
merge({
|
||||
inputStream: {
|
||||
type: "ImageStream",
|
||||
sequence: false,
|
||||
size: 800,
|
||||
src: imageSrc
|
||||
},
|
||||
numOfWorkers: (ENV.development && config.debug) ? 0 : 1,
|
||||
locator: {
|
||||
halfSample: false
|
||||
}
|
||||
},
|
||||
numOfWorkers: (ENV.development && config.debug) ? 0 : 1,
|
||||
locator: {
|
||||
halfSample: false
|
||||
}
|
||||
}, config, {inputStream: imageConfig});
|
||||
omit(config, 'inputStream'),
|
||||
{inputStream: omitBy(pick(config.inputStream, ['size', 'src']), isEmpty)},
|
||||
{inputStream: imageConfig});
|
||||
|
||||
console.log(config);
|
||||
const scanner = createScanner(config);
|
||||
return {
|
||||
addEventListener: (eventType, cb) => {
|
||||
@@ -38,11 +44,15 @@ function fromImage(config, imageSrc, imageConfig) {
|
||||
},
|
||||
toPromise() {
|
||||
return new Promise((resolve, reject) => {
|
||||
scanner.addEventListener('processed', (result) => {
|
||||
if (result.codeResult && result.codeResult.code) {
|
||||
return resolve(result);
|
||||
}
|
||||
return reject(result);
|
||||
scanner.init(config, () => {
|
||||
Events.once('processed', (result) => {
|
||||
scanner.stop();
|
||||
if (result.codeResult && result.codeResult.code) {
|
||||
return resolve(result);
|
||||
}
|
||||
return reject(result);
|
||||
});
|
||||
scanner.start();
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -87,45 +97,60 @@ function fromImage(config, imageSrc, imageConfig) {
|
||||
} */
|
||||
|
||||
let defaultScanner = createScanner();
|
||||
export default {
|
||||
withConfig: function(config) {
|
||||
return {
|
||||
fromImage: fromImage.bind(this, config)
|
||||
//fromVideo: fromVideo.bind(this, config)
|
||||
};
|
||||
},
|
||||
init: function(config, cb, imageWrapper) {
|
||||
defaultScanner.init(config, cb, imageWrapper);
|
||||
},
|
||||
start: function() {
|
||||
defaultScanner.start();
|
||||
},
|
||||
stop: function() {
|
||||
defaultScanner.stop();
|
||||
},
|
||||
pause: function() {
|
||||
defaultScanner.pause();
|
||||
},
|
||||
onDetected: function(callback) {
|
||||
defaultScanner.onDetected(callback);
|
||||
},
|
||||
offDetected: function(callback) {
|
||||
defaultScanner.offDetected(callback);
|
||||
},
|
||||
onProcessed: function(callback) {
|
||||
defaultScanner.onProcessed(callback);
|
||||
},
|
||||
offProcessed: function(callback) {
|
||||
defaultScanner.offProcessed(callback);
|
||||
},
|
||||
registerResultCollector: function(resultCollector) {
|
||||
defaultScanner.registerResultCollector(resultCollector);
|
||||
},
|
||||
decodeSingle: function(config, resultCallback) {
|
||||
defaultScanner.decodeSingle(config, resultCallback);
|
||||
},
|
||||
ImageWrapper: ImageWrapper,
|
||||
ImageDebug: ImageDebug,
|
||||
ResultCollector: ResultCollector,
|
||||
canvas: defaultScanner.canvas
|
||||
};
|
||||
|
||||
function setConfig(configuration = {}, key, config = {}) {
|
||||
var mergedConfig = merge({}, configuration, {[key]: config});
|
||||
return createApi(mergedConfig);
|
||||
}
|
||||
|
||||
function createApi(configuration = Config) {
|
||||
return {
|
||||
fromImage(src, conf) {
|
||||
return fromImage(configuration, src, conf);
|
||||
},
|
||||
decoder(conf) {
|
||||
return setConfig(configuration, "decoder", conf);
|
||||
},
|
||||
locator(conf) {
|
||||
return setConfig(configuration, "locator", conf);
|
||||
},
|
||||
config(conf) {
|
||||
return createApi(merge({}, configuration, conf));
|
||||
},
|
||||
init: function(config, cb, imageWrapper) {
|
||||
defaultScanner.init(config, cb, imageWrapper);
|
||||
},
|
||||
start: function() {
|
||||
defaultScanner.start();
|
||||
},
|
||||
stop: function() {
|
||||
defaultScanner.stop();
|
||||
},
|
||||
pause: function() {
|
||||
defaultScanner.pause();
|
||||
},
|
||||
onDetected: function(callback) {
|
||||
defaultScanner.onDetected(callback);
|
||||
},
|
||||
offDetected: function(callback) {
|
||||
defaultScanner.offDetected(callback);
|
||||
},
|
||||
onProcessed: function(callback) {
|
||||
defaultScanner.onProcessed(callback);
|
||||
},
|
||||
offProcessed: function(callback) {
|
||||
defaultScanner.offProcessed(callback);
|
||||
},
|
||||
registerResultCollector: function(resultCollector) {
|
||||
defaultScanner.registerResultCollector(resultCollector);
|
||||
},
|
||||
decodeSingle: function(config, resultCallback) {
|
||||
defaultScanner.decodeSingle(config, resultCallback);
|
||||
},
|
||||
ImageWrapper: ImageWrapper,
|
||||
ImageDebug: ImageDebug,
|
||||
ResultCollector: ResultCollector,
|
||||
canvas: defaultScanner.canvas
|
||||
};
|
||||
}
|
||||
export default createApi();
|
||||
|
||||
@@ -515,18 +515,6 @@ function createScanner() {
|
||||
}
|
||||
},
|
||||
decodeSingle: function(config, resultCallback) {
|
||||
config = merge({
|
||||
inputStream: {
|
||||
type: "ImageStream",
|
||||
sequence: false,
|
||||
size: 800,
|
||||
src: config.src
|
||||
},
|
||||
numOfWorkers: (ENV.development && config.debug) ? 0 : 1,
|
||||
locator: {
|
||||
halfSample: false
|
||||
}
|
||||
}, config);
|
||||
this.init(config, () => {
|
||||
Events.once("processed", (result) => {
|
||||
this.stop();
|
||||
|
||||
Reference in New Issue
Block a user