Table of Contents

Method AsRows

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

AsRows<T>()

Returns a MatRowAccessor<T> that provides efficient row-by-row access with no P/Invoke per row or per element. The data pointer, step, and dimensions are captured once; all indexing is pure pointer arithmetic.

public MatRowAccessor<T> AsRows<T>() where T : unmanaged

Returns

MatRowAccessor<T>

A MatRowAccessor<T> over this matrix.

Type Parameters

T

Element type. Must match the matrix element type (e.g. Vec3b for CV_8UC3).

Remarks

Parallel usage: Because MatRowAccessor<T> is a ref struct it cannot be captured by a lambda closure. Call this method inside each Parallel.For iteration to obtain a per-thread local accessor:

Parallel.For(0, mat.Rows, y =>
{
    Span<float> row = mat.AsRows<float>()[y];
    for (int x = 0; x < row.Length; x++)
        row[x] = ComputeValue(y, x);
});

Exceptions

InvalidOperationException

Thrown when the matrix is not 2-dimensional.