Show / Hide Table of Contents

Class Mat<TElem>

Type-specific abstract matrix

Inheritance
System.Object
DisposableObject
DisposableCvObject
Mat
Mat<TElem>
Implements
ICvPtrHolder
Inherited Members
Mat.TypeMap
Mat.FromPixelData(Int32, Int32, MatType, IntPtr, Int64)
Mat.FromPixelData(Int32, Int32, MatType, Array, Int64)
Mat.FromPixelData(IEnumerable<Int32>, MatType, IntPtr, Nullable<IEnumerable<Int64>>)
Mat.FromPixelData(IEnumerable<Int32>, MatType, Array, Nullable<IEnumerable<Int64>>)
Mat.Release()
Mat.DisposeUnmanaged()
Mat.FromStream(Stream, ImreadModes)
Mat.ImDecode(Byte[], ImreadModes)
Mat.ImDecode(ReadOnlySpan<Byte>, ImreadModes)
Mat.FromImageData(Byte[], ImreadModes)
Mat.FromImageData(ReadOnlySpan<Byte>, ImreadModes)
Mat.Diag(Mat)
Mat.Zeros(Int32, Int32, MatType)
Mat.Zeros(Size, MatType)
Mat.Zeros(MatType, Int32[])
Mat.Ones(Int32, Int32, MatType)
Mat.Ones(Size, MatType)
Mat.Ones(MatType, Int32[])
Mat.Eye(Size, MatType)
Mat.Eye(Int32, Int32, MatType)
Mat.FromArray<TElem>(TElem[])
Mat.FromArray<TElem>(TElem[,])
Mat.FromArray<TElem>(IEnumerable<TElem>)
Mat.Plus()
Mat.Negate()
Mat.Add(Mat)
Mat.Add(Scalar)
Mat.Subtract(Mat)
Mat.Subtract(Scalar)
Mat.Multiply(Mat)
Mat.Multiply(Double)
Mat.Divide(Mat)
Mat.Divide(Double)
Mat.BitwiseAnd(Mat)
Mat.BitwiseAnd(Double)
Mat.BitwiseOr(Mat)
Mat.BitwiseOr(Double)
Mat.Xor(Mat)
Mat.Xor(Double)
Mat.OnesComplement()
Mat.LessThan(Mat)
Mat.LessThan(Double)
Mat.LessThanOrEqual(Mat)
Mat.LessThanOrEqual(Double)
Mat.Equals(Mat)
Mat.Equals(Double)
Mat.NotEquals(Mat)
Mat.NotEquals(Double)
Mat.GreaterThan(Mat)
Mat.GreaterThan(Double)
Mat.GreaterThanOrEqual(Mat)
Mat.GreaterThanOrEqual(Double)
Mat.Item[Range, Range]
Mat.GetUMat(AccessFlag, UMatUsageFlags)
Mat.Col(Int32)
Mat.ColRange(Int32, Int32)
Mat.ColRange(Range)
Mat.ColRange(Range)
Mat.Row(Int32)
Mat.RowRange(Int32, Int32)
Mat.RowRange(Range)
Mat.RowRange(Range)
Mat.Diag(MatDiagType)
Mat.Clone(Rect)
Mat.CopyTo(OutputArray, InputArray)
Mat.CopyTo(Mat, InputArray)
Mat.ConvertTo(OutputArray, MatType, Double, Double)
Mat.AssignTo(Mat, Nullable<MatType>)
Mat.SetTo(Scalar, Mat)
Mat.SetTo(InputArray, Mat)
Mat.Reshape(Int32, Int32)
Mat.Reshape(Int32, Int32[])
Mat.Inv(DecompTypes)
Mat.Mul(InputArray, Double)
Mat.Cross(InputArray)
Mat.Dot(InputArray)
Mat.Create(Int32, Int32, MatType)
Mat.Create(Size, MatType)
Mat.Create(MatType, Int32[])
Mat.Reserve(Int32)
Mat.ReserveBuffer(Int32)
Mat.Resize(Int32)
Mat.Resize(Int32, Scalar)
Mat.PopBack(Int32)
Mat.PushBack(Byte)
Mat.PushBack(SByte)
Mat.PushBack(UInt16)
Mat.PushBack(Int16)
Mat.PushBack(Int32)
Mat.PushBack(Single)
Mat.PushBack(Double)
Mat.PushBack(Vec2b)
Mat.PushBack(Vec3b)
Mat.PushBack(Vec4b)
Mat.PushBack(Vec6b)
Mat.PushBack(Vec2w)
Mat.PushBack(Vec3w)
Mat.PushBack(Vec4w)
Mat.PushBack(Vec6w)
Mat.PushBack(Vec2s)
Mat.PushBack(Vec3s)
Mat.PushBack(Vec4s)
Mat.PushBack(Vec6s)
Mat.PushBack(Vec2i)
Mat.PushBack(Vec3i)
Mat.PushBack(Vec4i)
Mat.PushBack(Vec6i)
Mat.PushBack(Vec2f)
Mat.PushBack(Vec3f)
Mat.PushBack(Vec4f)
Mat.PushBack(Vec6f)
Mat.PushBack(Vec2d)
Mat.PushBack(Vec3d)
Mat.PushBack(Vec4d)
Mat.PushBack(Vec6d)
Mat.PushBack(Point)
Mat.PushBack(Point2d)
Mat.PushBack(Point2f)
Mat.PushBack(Point3i)
Mat.PushBack(Point3d)
Mat.PushBack(Point3f)
Mat.PushBack(Size)
Mat.PushBack(Size2d)
Mat.PushBack(Size2f)
Mat.PushBack(Rect)
Mat.PushBack(Rect2d)
Mat.PushBack(Rect2f)
Mat.PushBack(Mat)
Mat.LocateROI(Size, Point)
Mat.AdjustROI(Int32, Int32, Int32, Int32)
Mat.SubMat(Range, Range)
Mat.IsContinuous()
Mat.IsSubmatrix()
Mat.ElemSize()
Mat.ElemSize1()
Mat.Type()
Mat.Depth()
Mat.Channels()
Mat.Step1(Int32)
Mat.Empty()
Mat.Total()
Mat.Total(Int32, Int32)
Mat.CheckVector(Int32, Int32, Boolean)
Mat.Ptr(Int32)
Mat.Ptr(Int32, Int32)
Mat.Ptr(Int32, Int32, Int32)
Mat.Ptr(Int32[])
Mat.Flags
Mat.Dims
Mat.Rows
Mat.Height
Mat.Cols
Mat.Width
Mat.Data
Mat.DataPointer
Mat.DataStart
Mat.DataEnd
Mat.DataLimit
Mat.Size()
Mat.Size(Int32)
Mat.Step()
Mat.Step(Int32)
Mat.ToString()
Mat.Dump(FormatType)
Mat.EmptyClone()
Mat.GetGenericIndexer<T>()
Mat.GetUnsafeGenericIndexer<T>()
Mat.Get<T>(Int32)
Mat.Get<T>(Int32, Int32)
Mat.Get<T>(Int32, Int32, Int32)
Mat.Get<T>(Int32[])
Mat.At<T>(Int32)
Mat.At<T>(Int32, Int32)
Mat.At<T>(Int32, Int32, Int32)
Mat.At<T>(Int32[])
Mat.Set<T>(Int32, T)
Mat.Set<T>(Int32, Int32, T)
Mat.Set<T>(Int32, Int32, Int32, T)
Mat.Set<T>(Int32[], T)
Mat.GetArray<T>(T[])
Mat.GetRectangularArray<T>(T[,])
Mat.SetArray<T>(T[])
Mat.SetRectangularArray<T>(T[,])
Mat.ToBytes(String, Int32[])
Mat.ToBytes(String, ImageEncodingParam[])
Mat.ToMemoryStream(String, ImageEncodingParam[])
Mat.WriteToStream(Stream, String, ImageEncodingParam[])
Mat.Alignment(Int32)
Mat.Cast<TMat>()
Mat.ForEachAsByte(MatForeachFunctionByte)
Mat.ForEachAsVec2b(MatForeachFunctionVec2b)
Mat.ForEachAsVec3b(MatForeachFunctionVec3b)
Mat.ForEachAsVec4b(MatForeachFunctionVec4b)
Mat.ForEachAsVec6b(MatForeachFunctionVec6b)
Mat.ForEachAsInt16(MatForeachFunctionInt16)
Mat.ForEachAsVec2s(MatForeachFunctionVec2s)
Mat.ForEachAsVec3s(MatForeachFunctionVec3s)
Mat.ForEachAsVec4s(MatForeachFunctionVec4s)
Mat.ForEachAsVec6s(MatForeachFunctionVec6s)
Mat.ForEachAsInt32(MatForeachFunctionInt32)
Mat.ForEachAsVec2i(MatForeachFunctionVec2i)
Mat.ForEachAsVec3i(MatForeachFunctionVec3i)
Mat.ForEachAsVec4i(MatForeachFunctionVec4i)
Mat.ForEachAsVec6i(MatForeachFunctionVec6i)
Mat.ForEachAsFloat(MatForeachFunctionFloat)
Mat.ForEachAsVec2f(MatForeachFunctionVec2f)
Mat.ForEachAsVec3f(MatForeachFunctionVec3f)
Mat.ForEachAsVec4f(MatForeachFunctionVec4f)
Mat.ForEachAsVec6f(MatForeachFunctionVec6f)
Mat.ForEachAsDouble(MatForeachFunctionDouble)
Mat.ForEachAsVec2d(MatForeachFunctionVec2d)
Mat.ForEachAsVec3d(MatForeachFunctionVec3d)
Mat.ForEachAsVec4d(MatForeachFunctionVec4d)
Mat.ForEachAsVec6d(MatForeachFunctionVec6d)
Mat.AsSpan<T>()
Mat.DisposeManaged()
Mat.Abs()
Mat.ConvertScaleAbs(Double, Double)
Mat.LUT(InputArray)
Mat.LUT(Byte[])
Mat.Sum()
Mat.CountNonZero()
Mat.FindNonZero()
Mat.Mean(InputArray)
Mat.MeanStdDev(OutputArray, OutputArray, InputArray)
Mat.Norm(NormTypes, InputArray)
Mat.Normalize(Double, Double, NormTypes, Int32, InputArray)
Mat.MinMaxLoc(Double, Double)
Mat.MinMaxLoc(Point, Point)
Mat.MinMaxLoc(Double, Double, Point, Point, InputArray)
Mat.MinMaxIdx(Double, Double)
Mat.MinMaxIdx(Int32[], Int32[])
Mat.MinMaxIdx(Double, Double, Int32[], Int32[], InputArray)
Mat.Reduce(ReduceDimension, ReduceTypes, Int32)
Mat.Split()
Mat.ExtractChannel(Int32)
Mat.InsertChannel(InputOutputArray, Int32)
Mat.Flip(FlipMode)
Mat.Repeat(Int32, Int32)
Mat.InRange(InputArray, InputArray)
Mat.InRange(Scalar, Scalar)
Mat.Sqrt()
Mat.Pow(Double)
Mat.Exp()
Mat.Log()
Mat.CheckRange(Boolean)
Mat.CheckRange(Boolean, Point, Double, Double)
Mat.PatchNaNs(Double)
Mat.MulTransposed(Boolean, InputArray, Double, Int32)
Mat.Transpose()
Mat.Transform(InputArray)
Mat.PerspectiveTransform(InputArray)
Mat.CompleteSymm(Boolean)
Mat.SetIdentity(Nullable<Scalar>)
Mat.Determinant()
Mat.Trace()
Mat.Sort(SortFlags)
Mat.SortIdx(SortFlags)
Mat.Dft(DftFlags, Int32)
Mat.Idft(DftFlags, Int32)
Mat.Dct(DctFlags)
Mat.Idct(DctFlags)
Mat.Randu(InputArray, InputArray)
Mat.Randu(Scalar, Scalar)
Mat.Randn(InputArray, InputArray)
Mat.Randn(Scalar, Scalar)
Mat.RandShuffle(Double)
Mat.RandShuffle(Double, RNG)
Mat.Line(Int32, Int32, Int32, Int32, Scalar, Int32, LineTypes, Int32)
Mat.Line(Point, Point, Scalar, Int32, LineTypes, Int32)
Mat.Rectangle(Point, Point, Scalar, Int32, LineTypes, Int32)
Mat.Rectangle(Rect, Scalar, Int32, LineTypes, Int32)
Mat.Circle(Int32, Int32, Int32, Scalar, Int32, LineTypes, Int32)
Mat.Circle(Point, Int32, Scalar, Int32, LineTypes, Int32)
Mat.Ellipse(Point, Size, Double, Double, Double, Scalar, Int32, LineTypes, Int32)
Mat.Ellipse(RotatedRect, Scalar, Int32, LineTypes)
Mat.DrawMarker(Point, Scalar, MarkerTypes, Int32, Int32, LineTypes)
Mat.FillConvexPoly(IEnumerable<Point>, Scalar, LineTypes, Int32)
Mat.FillPoly(IEnumerable<IEnumerable<Point>>, Scalar, LineTypes, Int32, Nullable<Point>)
Mat.Polylines(IEnumerable<IEnumerable<Point>>, Boolean, Scalar, Int32, LineTypes, Int32)
Mat.PutText(String, Point, HersheyFonts, Double, Scalar, Int32, LineTypes, Boolean)
Mat.ImEncode(String, Int32[])
Mat.ImEncode(String, ImageEncodingParam[])
Mat.ImWrite(String, Int32[])
Mat.ImWrite(String, ImageEncodingParam[])
Mat.SaveImage(String, Int32[])
Mat.SaveImage(String, ImageEncodingParam[])
Mat.CopyMakeBorder(Int32, Int32, Int32, Int32, BorderTypes, Nullable<Scalar>)
Mat.MedianBlur(Int32)
Mat.GaussianBlur(Size, Double, Double, BorderTypes)
Mat.BilateralFilter(Int32, Double, Double, BorderTypes)
Mat.BoxFilter(MatType, Size, Nullable<Point>, Boolean, BorderTypes)
Mat.Blur(Size, Nullable<Point>, BorderTypes)
Mat.Filter2D(MatType, InputArray, Nullable<Point>, Double, BorderTypes)
Mat.SepFilter2D(MatType, InputArray, InputArray, Nullable<Point>, Double, BorderTypes)
Mat.Sobel(MatType, Int32, Int32, Int32, Double, Double, BorderTypes)
Mat.Scharr(MatType, Int32, Int32, Double, Double, BorderTypes)
Mat.Laplacian(MatType, Int32, Double, Double, BorderTypes)
Mat.Canny(Double, Double, Int32, Boolean)
Mat.CornerEigenValsAndVecs(Int32, Int32, BorderTypes)
Mat.PreCornerDetect(Int32, BorderTypes)
Mat.CornerSubPix(IEnumerable<Point2f>, Size, Size, TermCriteria)
Mat.GoodFeaturesToTrack(Int32, Double, Double, InputArray, Int32, Boolean, Double)
Mat.HoughLines(Double, Double, Int32, Double, Double)
Mat.HoughLinesP(Double, Double, Int32, Double, Double)
Mat.HoughCircles(HoughModes, Double, Double, Double, Double, Int32, Int32)
Mat.Dilate(InputArray, Nullable<Point>, Int32, BorderTypes, Nullable<Scalar>)
Mat.Erode(InputArray, Nullable<Point>, Int32, BorderTypes, Nullable<Scalar>)
Mat.MorphologyEx(MorphTypes, InputArray, Nullable<Point>, Int32, BorderTypes, Nullable<Scalar>)
Mat.Resize(Size, Double, Double, InterpolationFlags)
Mat.WarpAffine(InputArray, Size, InterpolationFlags, BorderTypes, Nullable<Scalar>)
Mat.WarpPerspective(Mat, Size, InterpolationFlags, BorderTypes, Nullable<Scalar>)
Mat.Remap(InputArray, InputArray, InterpolationFlags, BorderTypes, Nullable<Scalar>)
Mat.InvertAffineTransform()
Mat.GetRectSubPix(Size, Point2f, Int32)
Mat.Accumulate(InputArray)
Mat.AccumulateSquare(InputArray)
Mat.CreateHanningWindow(Size, MatType)
Mat.Threshold(Double, Double, ThresholdTypes)
Mat.AdaptiveThreshold(Double, AdaptiveThresholdTypes, ThresholdTypes, Int32, Double)
Mat.PyrDown(Nullable<Size>, BorderTypes)
Mat.PyrUp(Nullable<Size>, BorderTypes)
Mat.BuildPyramid(Int32, BorderTypes)
Mat.Undistort(InputArray, InputArray, InputArray)
Mat.GetDefaultNewCameraMatrix(Nullable<Size>, Boolean)
Mat.UndistortPoints(InputArray, InputArray, InputArray, InputArray)
Mat.EqualizeHist()
Mat.Watershed(InputOutputArray)
Mat.PyrMeanShiftFiltering(Double, Double, Int32, Nullable<TermCriteria>)
Mat.GrabCut(InputOutputArray, Rect, InputOutputArray, InputOutputArray, Int32, GrabCutModes)
Mat.FloodFill(Point, Scalar)
Mat.FloodFill(Point, Scalar, Rect, Nullable<Scalar>, Nullable<Scalar>, FloodFillFlags)
Mat.FloodFill(InputOutputArray, Point, Scalar)
Mat.FloodFill(InputOutputArray, Point, Scalar, Rect, Nullable<Scalar>, Nullable<Scalar>, FloodFillFlags)
Mat.CvtColor(ColorConversionCodes, Int32)
Mat.Moments(Boolean)
Mat.MatchTemplate(InputArray, TemplateMatchModes, InputArray)
Mat.ConnectedComponents(OutputArray, PixelConnectivity)
Mat.ConnectedComponents(OutputArray, PixelConnectivity, MatType)
Mat.ConnectedComponents(Int32[,], PixelConnectivity)
Mat.ConnectedComponentsWithStats(OutputArray, OutputArray, OutputArray, PixelConnectivity)
Mat.ConnectedComponentsWithStats(OutputArray, OutputArray, OutputArray, PixelConnectivity, MatType)
Mat.ConnectedComponentsEx(PixelConnectivity)
Mat.FindContours(Point[][], HierarchyIndex[], RetrievalModes, ContourApproximationModes, Nullable<Point>)
Mat.FindContours(Mat[], OutputArray, RetrievalModes, ContourApproximationModes, Nullable<Point>)
Mat.FindContoursAsArray(RetrievalModes, ContourApproximationModes, Nullable<Point>)
Mat.FindContoursAsMat(RetrievalModes, ContourApproximationModes, Nullable<Point>)
Mat.DrawContours(IEnumerable<IEnumerable<Point>>, Int32, Scalar, Int32, LineTypes, Nullable<IEnumerable<HierarchyIndex>>, Int32, Nullable<Point>)
Mat.DrawContours(IEnumerable<Mat>, Int32, Scalar, Int32, LineTypes, Mat, Int32, Nullable<Point>)
Mat.ApproxPolyDP(Double, Boolean)
Mat.ArcLength(Boolean)
Mat.BoundingRect()
Mat.ContourArea(Boolean)
Mat.MinAreaRect()
Mat.MinEnclosingCircle(Point2f, Single)
Mat.ConvexHull(Boolean, Boolean)
Mat.ConvexHullPoints(Boolean)
Mat.ConvexHullFloatPoints(Boolean)
Mat.ConvexHullIndices(Boolean)
Mat.ConvexityDefects(InputArray)
Mat.ConvexityDefectsAsVec(InputArray)
Mat.IsContourConvex()
Mat.FitEllipse()
Mat.FitLine2D(DistanceTypes, Double, Double, Double)
Mat.FitLine3D(DistanceTypes, Double, Double, Double)
Mat.PointPolygonTest(Point2f, Boolean)
Mat.DistanceTransform(DistanceTypes, DistanceTransformMasks)
DisposableCvObject.ptr
DisposableCvObject.CvPtr
DisposableObject.DataHandle
DisposableObject.IsDisposed
DisposableObject.IsEnabledDispose
DisposableObject.AllocatedMemory
DisposableObject.AllocatedMemorySize
DisposableObject.Dispose()
DisposableObject.Dispose(Boolean)
DisposableObject.AllocGCHandle(Object)
DisposableObject.AllocMemory(Int32)
DisposableObject.NotifyMemoryPressure(Int64)
DisposableObject.ThrowIfDisposed()
Namespace: OpenCvSharp
Assembly: OpenCvSharp.dll
Syntax
public class Mat<TElem> : Mat, ICvPtrHolder where TElem : struct
Type Parameters
Name Description
TElem

Element Type

Constructors

| Improve this Doc View Source

Mat()

Creates empty Mat

Declaration
public Mat()
| Improve this Doc View Source

Mat(IEnumerable<Int32>)

constructs n-dimensional matrix

Declaration
public Mat(IEnumerable<int> sizes)
Parameters
Type Name Description
IEnumerable<System.Int32> sizes

Array of integers specifying an n-dimensional array shape.

| Improve this Doc View Source

Mat(IEnumerable<Int32>, Array, Nullable<IEnumerable<Int64>>)

constructor for matrix headers pointing to user-allocated data

Declaration
public Mat(IEnumerable<int> sizes, Array data, IEnumerable<long>? steps = null)
Parameters
Type Name Description
IEnumerable<System.Int32> sizes

Array of integers specifying an n-dimensional array shape.

Array data

Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically de-allocated, so you should take care of it.

System.Nullable<IEnumerable<System.Int64>> steps

Array of ndims-1 steps in case of a multi-dimensional array (the last step is always set to the element size). If not specified, the matrix is assumed to be continuous.

| Improve this Doc View Source

Mat(IEnumerable<Int32>, Scalar)

constructs n-dimensional matrix

Declaration
public Mat(IEnumerable<int> sizes, Scalar s)
Parameters
Type Name Description
IEnumerable<System.Int32> sizes

Array of integers specifying an n-dimensional array shape.

OpenCvSharp.Scalar s

An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .

| Improve this Doc View Source

Mat(Mat)

Initializes by Mat object

Declaration
public Mat(Mat mat)
Parameters
Type Name Description
Mat mat

Managed Mat object

| Improve this Doc View Source

Mat(Mat<TElem>, Range, Nullable<Range>)

creates a matrix header for a part of the bigger matrix

Declaration
public Mat(Mat<TElem> m, Range rowRange, Range? colRange = null)
Parameters
Type Name Description
Mat<TElem> m

Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its sub-array is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the sub-array, use Mat::clone() .

OpenCvSharp.Range rowRange

Range of the m rows to take. As usual, the range start is inclusive and the range end is exclusive. Use Range.All to take all the rows.

System.Nullable<OpenCvSharp.Range> colRange

Range of the m columns to take. Use Range.All to take all the columns.

| Improve this Doc View Source

Mat(Mat<TElem>, Range[])

creates a matrix header for a part of the bigger matrix

Declaration
protected Mat(Mat<TElem> m, params Range[] ranges)
Parameters
Type Name Description
Mat<TElem> m

Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its sub-array is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the sub-array, use Mat.Clone() .

OpenCvSharp.Range[] ranges

Array of selected ranges of m along each dimensionality.

| Improve this Doc View Source

Mat(Mat<TElem>, Rect)

creates a matrix header for a part of the bigger matrix

Declaration
public Mat(Mat<TElem> m, Rect roi)
Parameters
Type Name Description
Mat<TElem> m

Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its sub-array is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the sub-array, use Mat.Clone() .

OpenCvSharp.Rect roi

Region of interest.

| Improve this Doc View Source

Mat(Size)

constructs 2D matrix of the specified size and type

Declaration
public Mat(Size size)
Parameters
Type Name Description
OpenCvSharp.Size size

2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order.

| Improve this Doc View Source

Mat(Size, Scalar)

constructs 2D matrix and fills it with the specified Scalar value.

Declaration
public Mat(Size size, Scalar s)
Parameters
Type Name Description
OpenCvSharp.Size size

2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order.

OpenCvSharp.Scalar s

An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .

| Improve this Doc View Source

Mat(Int32, Int32)

constructs 2D matrix of the specified size and type

Declaration
public Mat(int rows, int cols)
Parameters
Type Name Description
System.Int32 rows

Number of rows in a 2D array.

System.Int32 cols

Number of columns in a 2D array.

| Improve this Doc View Source

Mat(Int32, Int32, Array, Int64)

constructor for matrix headers pointing to user-allocated data

Declaration
protected Mat(int rows, int cols, Array data, long step = 0L)
Parameters
Type Name Description
System.Int32 rows

Number of rows in a 2D array.

System.Int32 cols

Number of columns in a 2D array.

Array data

Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically de-allocated, so you should take care of it.

System.Int64 step

Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize() .

| Improve this Doc View Source

Mat(Int32, Int32, Scalar)

constructs 2D matrix and fills it with the specified Scalar value.

Declaration
public Mat(int rows, int cols, Scalar s)
Parameters
Type Name Description
System.Int32 rows

Number of rows in a 2D array.

System.Int32 cols

Number of columns in a 2D array.

OpenCvSharp.Scalar s

An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .

Properties

| Improve this Doc View Source

Item[Range, Range]

Extracts a rectangular submatrix.

Declaration
public Mat<TElem> this[Range rowRange, Range colRange] { get; set; }
Parameters
Type Name Description
OpenCvSharp.Range rowRange

Start and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range.All().

OpenCvSharp.Range colRange

Start and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range.All().

Property Value
Type Description
Mat<TElem>
| Improve this Doc View Source

Item[Range[]]

Extracts a rectangular submatrix.

Declaration
public Mat<TElem> this[params Range[] ranges] { get; set; }
Parameters
Type Name Description
OpenCvSharp.Range[] ranges

Array of selected ranges along each array dimension.

Property Value
Type Description
Mat<TElem>
| Improve this Doc View Source

Item[Rect]

Extracts a rectangular submatrix.

Declaration
public Mat<TElem> this[Rect roi] { get; set; }
Parameters
Type Name Description
OpenCvSharp.Rect roi

Extracted submatrix specified as a rectangle.

Property Value
Type Description
Mat<TElem>
| Improve this Doc View Source

Item[Int32, Int32, Int32, Int32]

Extracts a rectangular submatrix.

Declaration
public Mat<TElem> this[int rowStart, int rowEnd, int colStart, int colEnd] { get; set; }
Parameters
Type Name Description
System.Int32 rowStart

Start row of the extracted submatrix. The upper boundary is not included.

System.Int32 rowEnd

End row of the extracted submatrix. The upper boundary is not included.

System.Int32 colStart

Start column of the extracted submatrix. The upper boundary is not included.

System.Int32 colEnd

End column of the extracted submatrix. The upper boundary is not included.

Property Value
Type Description
Mat<TElem>

Methods

| Improve this Doc View Source

Clone()

Creates a full copy of the matrix.

Declaration
public Mat<TElem> Clone()
Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

FromNativePointer(IntPtr)

Creates from native cv::Mat* pointer

Declaration
public static Mat<TElem> FromNativePointer(IntPtr ptr)
Parameters
Type Name Description
IntPtr ptr
Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

FromPixelData(IEnumerable<Int32>, IntPtr, Nullable<IEnumerable<Int64>>)

constructor for matrix headers pointing to user-allocated data

Declaration
public static Mat<TElem> FromPixelData(IEnumerable<int> sizes, IntPtr data, IEnumerable<long>? steps = null)
Parameters
Type Name Description
IEnumerable<System.Int32> sizes

Array of integers specifying an n-dimensional array shape.

IntPtr data

Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically de-allocated, so you should take care of it.

System.Nullable<IEnumerable<System.Int64>> steps

Array of ndims-1 steps in case of a multi-dimensional array (the last step is always set to the element size). If not specified, the matrix is assumed to be continuous.

Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

FromPixelData(Int32, Int32, Array, Int64)

constructor for matrix headers pointing to user-allocated data

Declaration
public static Mat<TElem> FromPixelData(int rows, int cols, Array data, long step = 0L)
Parameters
Type Name Description
System.Int32 rows

Number of rows in a 2D array.

System.Int32 cols

Number of columns in a 2D array.

Array data

Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically de-allocated, so you should take care of it.

System.Int64 step

Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize() .

Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

FromPixelData(Int32, Int32, IntPtr, Int64)

constructor for matrix headers pointing to user-allocated data

Declaration
public static Mat<TElem> FromPixelData(int rows, int cols, IntPtr data, long step = 0L)
Parameters
Type Name Description
System.Int32 rows

Number of rows in a 2D array.

System.Int32 cols

Number of columns in a 2D array.

IntPtr data

Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically de-allocated, so you should take care of it.

System.Int64 step

Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize() .

Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

GetEnumerator()

Gets read-only enumerator

Declaration
public IEnumerator<TElem> GetEnumerator()
Returns
Type Description
IEnumerator<TElem>
| Improve this Doc View Source

GetIndexer()

Gets a type-specific indexer. The indexer has getters/setters to access each matrix element.

Declaration
public MatIndexer<TElem> GetIndexer()
Returns
Type Description
MatIndexer<TElem>
| Improve this Doc View Source

Reshape(Int32)

Changes the shape of channels of a 2D matrix without copying the data.

Declaration
public Mat<TElem> Reshape(int rows)
Parameters
Type Name Description
System.Int32 rows

New number of rows. If the parameter is 0, the number of rows remains the same.

Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

Reshape(Int32[])

Changes the shape of a 2D matrix without copying the data.

Declaration
public Mat<TElem> Reshape(params int[] newDims)
Parameters
Type Name Description
System.Int32[] newDims

New number of rows. If the parameter is 0, the number of rows remains the same.

Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

SubMat(Range, Range)

Extracts a rectangular submatrix.

Declaration
public Mat<TElem> SubMat(Range rowRange, Range colRange)
Parameters
Type Name Description
OpenCvSharp.Range rowRange

Start and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range.All().

OpenCvSharp.Range colRange

Start and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range.All().

Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

SubMat(Range[])

Extracts a rectangular submatrix.

Declaration
public Mat<TElem> SubMat(params Range[] ranges)
Parameters
Type Name Description
OpenCvSharp.Range[] ranges

Array of selected ranges along each array dimension.

Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

SubMat(Rect)

Extracts a rectangular submatrix.

Declaration
public Mat<TElem> SubMat(Rect roi)
Parameters
Type Name Description
OpenCvSharp.Rect roi

Extracted submatrix specified as a rectangle.

Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

SubMat(Int32, Int32, Int32, Int32)

Extracts a rectangular submatrix.

Declaration
public Mat<TElem> SubMat(int rowStart, int rowEnd, int colStart, int colEnd)
Parameters
Type Name Description
System.Int32 rowStart

Start row of the extracted submatrix. The upper boundary is not included.

System.Int32 rowEnd

End row of the extracted submatrix. The upper boundary is not included.

System.Int32 colStart

Start column of the extracted submatrix. The upper boundary is not included.

System.Int32 colEnd

End column of the extracted submatrix. The upper boundary is not included.

Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

T()

Transposes a matrix.

Declaration
public Mat<TElem> T()
Returns
Type Description
Mat<TElem>
| Improve this Doc View Source

ToArray()

Convert this mat to managed array

Declaration
public TElem[] ToArray()
Returns
Type Description
TElem[]
| Improve this Doc View Source

ToRectangularArray()

Convert this mat to managed rectangular array

Declaration
public TElem[, ] ToRectangularArray()
Returns
Type Description
TElem[,]
| Improve this Doc View Source

Wrap(Mat)

Declaration
protected Mat<TElem> Wrap(Mat mat)
Parameters
Type Name Description
Mat mat
Returns
Type Description
Mat<TElem>

Implements

ICvPtrHolder

Extension Methods

CvExtensions.HoughLinesProbabilisticEx(Mat, Double, Double, Int32, Double, Double, Double, Double)
BitmapSourceConverter.ToBitmapSource(Mat)
BitmapSourceConverter.ToBitmapSource(Mat, Int32, Int32, PixelFormat, BitmapPalette)
BitmapSourceConverter.CopyFrom(Mat, BitmapSource)
WriteableBitmapConverter.ToWriteableBitmap(Mat, Double, Double, PixelFormat, BitmapPalette)
WriteableBitmapConverter.ToWriteableBitmap(Mat, PixelFormat)
WriteableBitmapConverter.ToWriteableBitmap(Mat)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX