mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-13 05:31:37 +08:00
Added color-channel constraint for images
This commit is contained in:
@@ -74,8 +74,7 @@ export function fromSource(source, {target = "#interactive.viewport"} = {}) {
|
|||||||
const dy = 0;
|
const dy = 0;
|
||||||
const dWidth = canvasSize.width;
|
const dWidth = canvasSize.width;
|
||||||
const dHeight = canvasSize.height;
|
const dHeight = canvasSize.height;
|
||||||
|
const {colorChannels = 3} = source;
|
||||||
console.time("clipp")
|
|
||||||
|
|
||||||
clipping = clipping ? clipping(canvasSize) : {
|
clipping = clipping ? clipping(canvasSize) : {
|
||||||
x: 0,
|
x: 0,
|
||||||
@@ -98,7 +97,7 @@ export function fromSource(source, {target = "#interactive.viewport"} = {}) {
|
|||||||
clipping.height
|
clipping.height
|
||||||
).data;
|
).data;
|
||||||
var imageBuffer = nextAvailableBuffer(clipping.width * clipping.height);
|
var imageBuffer = nextAvailableBuffer(clipping.width * clipping.height);
|
||||||
computeGray(imageData, imageBuffer);
|
computeGray(imageData, imageBuffer, {singleChannel: colorChannels === 1});
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
width: clipping.width,
|
width: clipping.width,
|
||||||
height: clipping.height,
|
height: clipping.height,
|
||||||
|
|||||||
+4
-3
@@ -153,7 +153,6 @@ function adjustWithZoom(videoConstraints) {
|
|||||||
|
|
||||||
export function fromCamera(constraints) {
|
export function fromCamera(constraints) {
|
||||||
var {video: videoConstraints, zoom} = adjustWithZoom(constraints);
|
var {video: videoConstraints, zoom} = adjustWithZoom(constraints);
|
||||||
console.log(videoConstraints);
|
|
||||||
|
|
||||||
const video = getOrCreateVideo();
|
const video = getOrCreateVideo();
|
||||||
return CameraAccess.request(video, videoConstraints)
|
return CameraAccess.request(video, videoConstraints)
|
||||||
@@ -246,7 +245,7 @@ export function fromCanvas(input) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fromImage(input, constraints = {width: 800, height: 800}) {
|
export function fromImage(input, constraints = {width: 800, height: 800, channels: 3}) {
|
||||||
var $image = null;
|
var $image = null;
|
||||||
var src = null;
|
var src = null;
|
||||||
if (typeof input === 'string') {
|
if (typeof input === 'string') {
|
||||||
@@ -285,9 +284,11 @@ export function fromImage(input, constraints = {width: 800, height: 800}) {
|
|||||||
|
|
||||||
const calculatedWidth = imageAR > 1 ? constraints.width : Math.floor((imageAR) * constraints.width);
|
const calculatedWidth = imageAR > 1 ? constraints.width : Math.floor((imageAR) * constraints.width);
|
||||||
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;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "IMAGE",
|
type: "IMAGE",
|
||||||
|
colorChannels,
|
||||||
getDimensions() {
|
getDimensions() {
|
||||||
return {
|
return {
|
||||||
viewport: {
|
viewport: {
|
||||||
@@ -313,7 +314,7 @@ export function fromImage(input, constraints = {width: 800, height: 800}) {
|
|||||||
},
|
},
|
||||||
applyConstraints: function() {
|
applyConstraints: function() {
|
||||||
console.log('ImageSource.applyConstraints not implemented');
|
console.log('ImageSource.applyConstraints not implemented');
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user