Skip to content

MatShape

Core and matricesclassOpenCV 5.0.0
import { MatShape } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSConstructor or factory
CLASSMatShape
RETURN TYPEOwned native handle
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Native object: release it with using or delete(). Factories can return null; check before calling methods.

An owned OpenCV 5 tensor shape with up to ten dimensions and layout metadata. Construct from an IntVector, or use scalar() for a zero-dimensional tensor. Dispose the shape after use.

Constructors and members

static new

Create an owned MatShape object. Release native handles with using or delete().

new(shape: IntVector): MatShape;
2 available overloads
new(): MatShape;
new(shape: IntVector): MatShape;
shape

shape argument (IntVector).

Returns

The MatShape result.

static scalar

Create an owned zero-dimensional shape containing one element.

scalar(): MatShape;
Returns

The MatShape result.

clone

Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.

clone(): this;
Returns

The this result.

dims

Number of tensor dimensions. Zero denotes a scalar; a negative value denotes an empty shape.

readonly dims: number;

layout

Numeric DATA_LAYOUT constant describing the dimension order.

readonly layout: number;

C

Actual channel count when the shape uses a padded block layout.

readonly C: number;

size

Return the number of dimension extents. Use empty() to distinguish an empty shape from a scalar.

size(): number;
Returns

The number result.

total

Return the product of dimension extents including block padding. Scalars contain one element; empty shapes contain zero.

total(): number;
Returns

The number result.

vec

Copy the dimension extents into an owned IntVector. Dispose the returned vector.

vec(): IntVector;
Returns

The IntVector result. Release returned native handles with using or delete(), including handles nested in results.

str

Format the native shape and layout as a diagnostic string.

str(): string;
Returns

The string result.

empty

Return whether this shape has zero elements.

empty(): boolean;
Returns

The boolean result.

isScalar

Return whether the shape has zero dimensions and represents a scalar.

isScalar(): boolean;
Returns

The boolean result.

clear

Reset this shape to the empty state.

clear(): void;

channels

Return the channel extent according to the stored data layout.

channels(): number;
Returns

The number result.

hasSymbols

Return whether any negative extent represents a symbolic dimension.

hasSymbols(): boolean;
Returns

The boolean result.

expand

Compute the broadcast result of this shape and another shape. Return an owned shape, or throw when dimensions are incompatible.

expand(another: MatShape): MatShape;
another

another argument (MatShape).

Returns

The MatShape result.

erase

Remove the dimension at the supplied zero-based index. Throws when the index is outside the current dimensions.

erase(index: number): void;
index

index argument (number).

toLayout

Convert dimension ordering to the requested numeric DATA_LAYOUT constant. The optional second argument supplies the block channel size. Return an owned shape.

toLayout(newLayout: number, C0: number): MatShape;
2 available overloads
toLayout(newLayout: number): MatShape;
toLayout(newLayout: number, C0: number): MatShape;
newLayout

new layout argument (number).

C0

c0 argument (number).

Returns

The MatShape result.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.