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
sizesIEnumerable<int>Per-axis sizes.
layoutDataLayoutData layout.
channelsintNumber 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
sizesint[]Per-axis sizes.
Properties
Channels
Actual number of channels (C), meaningful for the block layout; 0 otherwise.
public int Channels { get; }
Property Value
Dims
The number of dimensions (axes). 0 for both empty and scalar shapes.
public int Dims { get; }
Property Value
Empty
An empty shape (total == 0).
public static MatShape Empty { get; }
Property Value
IsEmpty
True if this is an empty shape (total == 0).
public bool IsEmpty { get; }
Property Value
IsScalar
True if this is a 0-dimensional scalar shape (dims == 0, total == 1).
public bool IsScalar { get; }
Property Value
this[int]
Gets the size of the i-th axis.
public int this[int index] { get; }
Parameters
indexintAxis index.
Property Value
Layout
Data layout of the shape.
public DataLayout Layout { get; }
Property Value
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
Methods
Equals(MatShape)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(MatShape other)
Parameters
otherMatShapeAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
layoutDataLayoutData layout.
Returns
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
Returns
explicit operator int[](MatShape)
Returns the per-axis sizes.
public static explicit operator int[](MatShape shape)
Parameters
shapeMatShape
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
sizesint[]
Returns
operator !=(MatShape, MatShape)
Determines whether two shapes differ.
public static bool operator !=(MatShape left, MatShape right)