mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
video working
This commit is contained in:
committed by
Christoph Oberhofer
parent
f8bc6a705c
commit
f1a963f4a0
+12
-12
@@ -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({
|
||||
code128Scanner
|
||||
.fromVideo({
|
||||
constraints: {
|
||||
width: 640,
|
||||
height: 480,
|
||||
width: 1280,
|
||||
height: 720,
|
||||
facingMode: "environment"
|
||||
}
|
||||
});
|
||||
|
||||
videoScanner.addEventListener('detected', (result) => {
|
||||
})
|
||||
.addEventListener('detected', (result) => {
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
videoScanner.then((result) => {
|
||||
console.log(result);
|
||||
}); */
|
||||
|
||||
+26
-13
@@ -48,7 +48,7 @@ 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
|
||||
//
|
||||
@@ -60,30 +60,40 @@ function fromImage(config, imageSrc, inputConfig={}) {
|
||||
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);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user