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