當前位置: 首頁>>代碼示例>>C#>>正文


C# Mat.Create方法代碼示例

本文整理匯總了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();
                    }
                }
            }
        }
開發者ID:CodeSang,項目名稱:opencvsharp,代碼行數:42,代碼來源:ConnectedComponent.cs

示例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);
        }
開發者ID:CodeSang,項目名稱:opencvsharp,代碼行數:21,代碼來源:Cv2_imgcodecs.cs


注:本文中的OpenCvSharp.Mat.Create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。