mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-13 05:31:37 +08:00
Added scope to Soure to determine if it was created by quagga or not
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
import {clone} from 'lodash';
|
import {clone} from 'lodash';
|
||||||
import {determineOrientation, PORTRAIT} from '../common/device';
|
import {determineOrientation} from '../common/device';
|
||||||
import CameraAccess from './camera_access';
|
import CameraAccess from './camera_access';
|
||||||
import {getViewport} from '../common/utils';
|
import {getViewport} from '../common/utils';
|
||||||
|
import {generateSourceInterface} from './SourceInterface';
|
||||||
|
import {Scope} from './input/SourceScope';
|
||||||
|
|
||||||
const ConstraintPresets = [
|
const ConstraintPresets = [
|
||||||
{
|
{
|
||||||
@@ -151,14 +153,14 @@ function adjustWithZoom(videoConstraints) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fromCamera(constraints, {target} = {}) {
|
export function fromCamera(constraints, {target, scope = Scope.EXTERNAL} = {}) {
|
||||||
let {video: videoConstraints, zoom} = adjustWithZoom(constraints);
|
let {video: videoConstraints, zoom} = adjustWithZoom(constraints);
|
||||||
|
|
||||||
const video = getOrCreateVideo(target);
|
const video = getOrCreateVideo(target);
|
||||||
return CameraAccess.request(video, videoConstraints)
|
return CameraAccess.request(video, videoConstraints)
|
||||||
.then((mediastream) => {
|
.then((mediastream) => {
|
||||||
let track = mediastream.getVideoTracks()[0];
|
let track = mediastream.getVideoTracks()[0];
|
||||||
return {
|
return Object.assign(generateSourceInterface(), {
|
||||||
type: "CAMERA",
|
type: "CAMERA",
|
||||||
getDimensions() {
|
getDimensions() {
|
||||||
const viewport = {
|
const viewport = {
|
||||||
@@ -182,13 +184,13 @@ export function fromCamera(constraints, {target} = {}) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getConstraints: function() {
|
getConstraints() {
|
||||||
return videoConstraints;
|
return videoConstraints;
|
||||||
},
|
},
|
||||||
getDrawable: function() {
|
getDrawable() {
|
||||||
return video;
|
return video;
|
||||||
},
|
},
|
||||||
applyConstraints: function(newConstraints) {
|
applyConstraints(newConstraints) {
|
||||||
track.stop();
|
track.stop();
|
||||||
constraints = newConstraints;
|
constraints = newConstraints;
|
||||||
const adjustment = adjustWithZoom(constraints);
|
const adjustment = adjustWithZoom(constraints);
|
||||||
@@ -200,9 +202,15 @@ export function fromCamera(constraints, {target} = {}) {
|
|||||||
track = mediastream.getVideoTracks()[0];
|
track = mediastream.getVideoTracks()[0];
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getLabel: function() {
|
getLabel() {
|
||||||
return track.label;
|
return track.label;
|
||||||
|
},
|
||||||
|
stop() {
|
||||||
|
track.stop();
|
||||||
|
},
|
||||||
|
getScope() {
|
||||||
|
return scope;
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {findTagsInObjectURL} from './exif_helper';
|
import {findTagsInObjectURL} from './exif_helper';
|
||||||
|
import {generateSourceInterface} from './SourceInterface';
|
||||||
|
|
||||||
export function fromImage(input, constraints = {width: 800, height: 800, channels: 3}) {
|
export function fromImage(input, constraints = {width: 800, height: 800, channels: 3}) {
|
||||||
var $image = null;
|
var $image = null;
|
||||||
@@ -49,7 +50,7 @@ export function fromImage(input, constraints = {width: 800, height: 800, channel
|
|||||||
const calculatedHeight = imageAR > 1 ? Math.floor((1 / imageAR) * constraints.width) : constraints.width;
|
const calculatedHeight = imageAR > 1 ? Math.floor((1 / imageAR) * constraints.width) : constraints.width;
|
||||||
const colorChannels = constraints.channels || 3;
|
const colorChannels = constraints.channels || 3;
|
||||||
|
|
||||||
return {
|
return Object.assign(generateSourceInterface(), {
|
||||||
type: "IMAGE",
|
type: "IMAGE",
|
||||||
colorChannels,
|
colorChannels,
|
||||||
tags,
|
tags,
|
||||||
@@ -76,9 +77,6 @@ export function fromImage(input, constraints = {width: 800, height: 800, channel
|
|||||||
getConstraints: function() {
|
getConstraints: function() {
|
||||||
return constraints;
|
return constraints;
|
||||||
},
|
},
|
||||||
applyConstraints: function() {
|
});
|
||||||
console.log('ImageSource.applyConstraints not implemented');
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export * from './ImageSource';
|
export * from './ImageSource';
|
||||||
export * from './CameraSource';
|
export * from './CameraSource';
|
||||||
|
export * from './SourceScope';
|
||||||
|
|
||||||
export function fromCanvas(input) {
|
export function fromCanvas(input) {
|
||||||
var $canvas = null;
|
var $canvas = null;
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
const viewport = {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const canvas = {
|
||||||
|
height: 0,
|
||||||
|
width: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
export function generateSourceInterface() {
|
||||||
|
return {
|
||||||
|
type: "INTERFACE",
|
||||||
|
getDimensions() {
|
||||||
|
return {
|
||||||
|
viewport,
|
||||||
|
canvas,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
getConstraints() {},
|
||||||
|
getDrawable() {},
|
||||||
|
applyConstraints() {},
|
||||||
|
getLabel() {},
|
||||||
|
stop() {},
|
||||||
|
getScope() {},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export const Scope = {
|
||||||
|
INTERNAL: "INTERNAL",
|
||||||
|
EXTERNAL: 'EXTERNAL',
|
||||||
|
};
|
||||||
+4
-1
@@ -143,7 +143,10 @@ function createApi() {
|
|||||||
fromCamera(options) {
|
fromCamera(options) {
|
||||||
const config = merge({}, Config, options);
|
const config = merge({}, Config, options);
|
||||||
return Source
|
return Source
|
||||||
.fromCamera(config.constraints, {target: config.target})
|
.fromCamera(config.constraints, {
|
||||||
|
target: config.target,
|
||||||
|
scope: Source.Scope.INTERNAL,
|
||||||
|
})
|
||||||
.then(fromSource.bind(null, config));
|
.then(fromSource.bind(null, config));
|
||||||
},
|
},
|
||||||
fromSource(src, inputConfig) {
|
fromSource(src, inputConfig) {
|
||||||
|
|||||||
+3
-3
@@ -6,8 +6,8 @@ import BarcodeDecoder from './decoder/barcode_decoder';
|
|||||||
import createEventedElement from './common/events';
|
import createEventedElement from './common/events';
|
||||||
import {release, aquire, releaseAll} from './common/buffers';
|
import {release, aquire, releaseAll} from './common/buffers';
|
||||||
import Config from './config/config';
|
import Config from './config/config';
|
||||||
import CameraAccess from './input/camera_access';
|
|
||||||
import {getViewport} from './common/utils';
|
import {getViewport} from './common/utils';
|
||||||
|
import {Scope} from './input/SourceScope';
|
||||||
|
|
||||||
const vec2 = {
|
const vec2 = {
|
||||||
clone: require('gl-vec2/clone')
|
clone: require('gl-vec2/clone')
|
||||||
@@ -438,8 +438,8 @@ function createScanner(pixelCapturer) {
|
|||||||
_stopped = true;
|
_stopped = true;
|
||||||
adjustWorkerPool(0);
|
adjustWorkerPool(0);
|
||||||
releaseAll();
|
releaseAll();
|
||||||
if (source.type === "CAMERA") {
|
if (source.getScope() === Scope.INTERNAL) {
|
||||||
CameraAccess.release();
|
source.stop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
applyConfig(newConfig) {
|
applyConfig(newConfig) {
|
||||||
|
|||||||
Reference in New Issue
Block a user