Table of Contents

Struct MatRowAccessor<T>

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

Provides zero-allocation, zero-P/Invoke-per-element row access to a 2D Mat. Obtain via AsRows<T>(). The data pointer, step, and dimensions are captured once at construction time, so all subsequent row indexing is pure pointer arithmetic.

public readonly ref struct MatRowAccessor<T> where T : unmanaged

Type Parameters

T

Unmanaged element type matching the matrix element type (e.g. Vec3b for CV_8UC3).

Inherited Members

Remarks

Typical usage for per-pixel iteration:

var rows = mat.AsRows<Vec3b>();
for (int r = 0; r < rows.Count; r++)
{
    Span<Vec3b> row = rows[r];
    for (int c = 0; c < row.Length; c++)
    {
        Vec3b pixel = row[c];
    }
}

This is a ref struct and therefore cannot be stored in fields, boxed, or used as a generic type argument.

Properties

Count

Number of rows in the matrix.

public int Count { get; }

Property Value

int

this[int]

Returns a Span<T> over the specified row. No P/Invoke is performed; this is pure pointer arithmetic. Bounds are checked in DEBUG builds only.

public Span<T> this[int row] { get; }

Parameters

row int

Zero-based row index.

Property Value

Span<T>