video working

feature/109
Christoph Oberhofer 9 years ago committed by Christoph Oberhofer
parent f8bc6a705c
commit f1a963f4a0

@ -2,6 +2,10 @@ console.log(typeof Quagga);
// creates a new instance!
var code128Scanner = Quagga
.decoder({readers: ['code_128_reader']})
.locator({patchSize: 'medium'});
var eanScanner = Quagga
.decoder({readers: ['ean_reader']})
.locator({patchSize: 'medium'});
@ -10,7 +14,7 @@ var i2of5Scanner = Quagga
.decoder({readers: ['i2of5_reader']})
.locator({patchSize: 'small', halfSample: false});
eanScanner
/*eanScanner
.fromImage('../test/fixtures/ean/image-001.jpg', {size: 640})
.toPromise().then((result) => {
console.log(result.codeResult.code);
@ -25,7 +29,7 @@ i2of5Scanner
}).catch(() => {
console.log("ITF not found!");
});
*/
/* imageReader.addEventListener('processed', (result) => {
console.log(result);
@ -42,18 +46,14 @@ i2of5Scanner
console.log(result.codeResult.code);
});*/
/*var videoScanner = myReader.fromVideo({
constraints: {
width: 640,
height: 480,
facingMode: "environment"
}
});
videoScanner.addEventListener('detected', (result) => {
console.log(result);
});
videoScanner.then((result) => {
console.log(result);
}); */
code128Scanner
.fromVideo({
constraints: {
width: 1280,
height: 720,
facingMode: "environment"
}
})
.addEventListener('detected', (result) => {
console.log(result);
});

@ -48,42 +48,52 @@ function fromImage(config, imageSrc, inputConfig={}) {
};
}
/*function fromVideo(config, src) {
function fromVideo(config, source, inputConfig = {}) {
// remember last instance
// check if anything but the imagesrc has changed
//
let sourceConfig = {
type : "LiveStream",
type: "LiveStream",
constraints: {
width: 640,
height: 480,
facingMode: "environment"
}
};
if (source instanceof Stream) {
/*if (source instanceof MediaStream) {
// stream
} else if (source instanceof Element) {
} else*/ if (source instanceof Element) {
// video element
} else if (typeof source === 'string') {
// video source
} else if (typeof source === 'object') {
// additional constraints
} else if (typeof source === 'object'
&& (typeof source.constraints !== 'undefined'
|| typeof source.area !== 'undefined')) {
console.log("inputConfig");
inputConfig = source;
} else if (!source) {
// LiveStream
}
config = merge({inputStream: sourceConfig}, config);
config = merge({}, config, {inputStream: sourceConfig}, {inputStream: inputConfig});
console.log(config);
const scanner = createScanner();
return {
addEventListener: (eventType, cb) => {
this.init(config, () => {
start();
addEventListener(eventType, cb) {
scanner.init(config, (error) => {
if (error) {
console.log(error);
return;
}
scanner.start();
});
Events.subscribe(eventType, cb);
scanner.subscribe(eventType, cb);
},
removeEventListener: (cb) => {
Events.unsubscribe(eventType, cb);
removeEventListener(eventType, cb) {
scanner.unsubscribe(eventType, cb);
}
}
} */
};
}
let defaultScanner = createScanner();
@ -97,6 +107,9 @@ function createApi(configuration = Config) {
fromImage(src, conf) {
return fromImage(configuration, src, conf);
},
fromVideo(src, inputConfig) {
return fromVideo(configuration, src, inputConfig);
},
decoder(conf) {
return setConfig(configuration, "decoder", conf);
},

@ -498,6 +498,12 @@ function createScanner() {
pause: function() {
_stopped = true;
},
subscribe(eventName, callback) {
_events.subscribe(eventName, callback);
},
unsubscribe(eventName, callback) {
_events.unsubscribe(eventName, callback);
},
onDetected: function(callback) {
_events.subscribe("detected", callback);
},

Loading…
Cancel
Save