|
|
@ -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: {
|
|
|
|
numOfWorkers: (ENV.development && config.debug) ? 0 : 1,
|
|
|
|
halfSample: false
|
|
|
|
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);
|
|
|
|
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();
|
|
|
|