本文整理汇总了C#中OpenCvSharp.Mat.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.Create方法的具体用法?C# Mat.Create怎么用?C# Mat.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenCvSharp.Mat
的用法示例。
在下文中一共展示了Mat.Create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderBlobs
/// <summary>
/// Draws all blobs to the specified image.
/// </summary>
/// <param name="img">The target image to be drawn.</param>
public void RenderBlobs(Mat img)
{
if (img == null)
throw new ArgumentNullException("img");
/*
if (img.Empty())
throw new ArgumentException("img is empty");
if (img.Type() != MatType.CV_8UC3)
throw new ArgumentException("img must be CV_8UC3");*/
if (Blobs == null || Blobs.Count == 0)
throw new OpenCvSharpException("Blobs is empty");
if (Labels == null)
throw new OpenCvSharpException("Labels is empty");
int height = Labels.GetLength(0);
int width = Labels.GetLength(1);
img.Create(new Size(width, height), MatType.CV_8UC3);
Scalar[] colors = new Scalar[Blobs.Count];
colors[0] = Scalar.All(0);
for (int i = 1; i < Blobs.Count; i++)
{
colors[i] = Scalar.RandomColor();
}
using (var imgt = new MatOfByte3(img))
{
var indexer = imgt.GetIndexer();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int labelValue = Labels[y, x];
indexer[y, x] = colors[labelValue].ToVec3b();
}
}
}
}
示例2: ConvertImage
/// <summary>
/// utility function: convert one image to another with optional vertical flip
/// </summary>
/// <param name="src"></param>
/// <param name="dst"></param>
/// <param name="flags"></param>
public static void ConvertImage(Mat src, Mat dst, ConvertImageModes flags = ConvertImageModes.None)
{
if (src == null)
throw new ArgumentNullException("src");
if (dst == null)
throw new ArgumentNullException("dst");
src.ThrowIfDisposed();
dst.ThrowIfDisposed();
dst.Create(src.Size(), MatType.CV_8UC3);
NativeMethods.imgcodecs_cvConvertImage_Mat(src.CvPtr, dst.CvPtr, (int)flags);
GC.KeepAlive(src);
GC.KeepAlive(dst);
}