Table of Contents

Struct MatShape

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

Represents the shape of a matrix / tensor (OpenCV 5, cv::MatShape). In addition to the per-axis sizes it carries the data Layout and, for the block layout, the actual number of Channels (C). It also distinguishes an empty shape (IsEmpty, total == 0) from a 0-dimensional scalar shape (IsScalar, dims == 0 but total == 1).

public readonly struct MatShape : IEquatable<MatShape>
Implements
Inherited Members

Constructors

MatShape(IEnumerable<int>, DataLayout, int)

Creates an N-D shape with an explicit layout and channel count.

public MatShape(IEnumerable<int> sizes, DataLayout layout, int channels = 0)

Parameters

sizes IEnumerable<int>

Per-axis sizes.

layout DataLayout

Data layout.

channels int

Number of channels (C) for the block layout; 0 otherwise.

MatShape(params int[])

Creates an N-D shape from the given per-axis sizes. Passing no sizes creates a 0-D scalar shape.

public MatShape(params int[] sizes)

Parameters

sizes int[]

Per-axis sizes.

Properties

Channels

Actual number of channels (C), meaningful for the block layout; 0 otherwise.

public int Channels { get; }

Property Value

int

Dims

The number of dimensions (axes). 0 for both empty and scalar shapes.

public int Dims { get; }

Property Value

int

Empty

An empty shape (total == 0).

public static MatShape Empty { get; }

Property Value

MatShape

IsEmpty

True if this is an empty shape (total == 0).

public bool IsEmpty { get; }

Property Value

bool

IsScalar

True if this is a 0-dimensional scalar shape (dims == 0, total == 1).

public bool IsScalar { get; }

Property Value

bool

this[int]

Gets the size of the i-th axis.

public int this[int index] { get; }

Parameters

index int

Axis index.

Property Value

int

Layout

Data layout of the shape.

public DataLayout Layout { get; }

Property Value

DataLayout

Total

The total number of elements: 0 for an empty shape, 1 for a scalar, otherwise the product of the sizes.

public long Total { get; }

Property Value

long

Methods

Equals(MatShape)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(MatShape other)

Parameters

other MatShape

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Scalar(DataLayout)

A 0-dimensional scalar shape (dims == 0, total == 1).

public static MatShape Scalar(DataLayout layout = DataLayout.UNKNOWN)

Parameters

layout DataLayout

Data layout.

Returns

MatShape

ToArray()

Returns the per-axis sizes as an array (empty array for empty or scalar shapes).

public int[] ToArray()

Returns

int[]

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Operators

operator ==(MatShape, MatShape)

Determines whether two shapes are equal (same sizes, layout and channels).

public static bool operator ==(MatShape left, MatShape right)

Parameters

left MatShape
right MatShape

Returns

bool

explicit operator int[](MatShape)

Returns the per-axis sizes.

public static explicit operator int[](MatShape shape)

Parameters

shape MatShape

Returns

int[]

implicit operator MatShape(int[]?)

Implicitly converts per-axis sizes to a MatShape. A null array becomes an empty shape.

public static implicit operator MatShape(int[]? sizes)

Parameters

sizes int[]

Returns

MatShape

operator !=(MatShape, MatShape)

Determines whether two shapes differ.

public static bool operator !=(MatShape left, MatShape right)

Parameters

left MatShape
right MatShape

Returns

bool