当前位置: 首页>>代码示例>>C#>>正文


C# CPlusPlus.Mat类代码示例

本文整理汇总了C#中OpenCvSharp.CPlusPlus.Mat的典型用法代码示例。如果您正苦于以下问题:C# Mat类的具体用法?C# Mat怎么用?C# Mat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Mat类属于OpenCvSharp.CPlusPlus命名空间,在下文中一共展示了Mat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChamferMatching

        /// <summary>
        /// 
        /// </summary>
        /// <param name="img"></param>
        /// <param name="templ"></param>
        /// <param name="results"></param>
        /// <param name="cost"></param>
        /// <param name="templScale"></param>
        /// <param name="maxMatches"></param>
        /// <param name="minMatchDistance"></param>
        /// <param name="padX"></param>
        /// <param name="padY"></param>
        /// <param name="scales"></param>
        /// <param name="minScale"></param>
        /// <param name="maxScale"></param>
        /// <param name="orientationWeight"></param>
        /// <param name="truncate"></param>
        /// <returns></returns>
        public static int ChamferMatching(
            Mat img, Mat templ,
                                  out Point[][] results, out float[] cost,
                                  double templScale=1, int maxMatches = 20,
                                  double minMatchDistance = 1.0, int padX = 3,
                                  int padY = 3, int scales = 5, double minScale = 0.6, double maxScale = 1.6,
                                  double orientationWeight = 0.5, double truncate = 20)
        {
            if (img == null)
                throw new ArgumentNullException("img");
            if (templ == null)
                throw new ArgumentNullException("templ");
            img.ThrowIfDisposed();
            templ.ThrowIfDisposed();
            
            using (var resultsVec = new VectorOfVectorPoint())
            using (var costVec = new VectorOfFloat())
            {
                int ret = NativeMethods.contrib_chamerMatching(
                    img.CvPtr, templ.CvPtr, resultsVec.CvPtr, costVec.CvPtr, 
                    templScale, maxMatches, minMatchDistance,
                    padX, padY, scales, minScale, maxScale, orientationWeight, truncate);
                GC.KeepAlive(img);
                GC.KeepAlive(templ);

                results = resultsVec.ToArray();
                cost = costVec.ToArray();

                return ret;
            }
        }
开发者ID:josephgodwinkimani,项目名称:opencvsharp,代码行数:49,代码来源:Cv2_contrib.cs

示例2: Main

        private static void Main(string[] args)
        {
            Mat src = new Mat("data/tsukuba_left.png", LoadMode.GrayScale);
            Mat dst20 = new Mat();
            Mat dst40 = new Mat();
            Mat dst44 = new Mat();

            using (CLAHE clahe = Cv2.CreateCLAHE())
            {
                clahe.ClipLimit = 20;
                clahe.Apply(src, dst20);
                clahe.ClipLimit = 40;
                clahe.Apply(src, dst40);
                clahe.TilesGridSize = new Size(4, 4);
                clahe.Apply(src, dst44);
            }

            Window.ShowImages(src, dst20, dst40, dst44);

            /*var img1 = new IplImage("data/lenna.png", LoadMode.Color);
            var img2 = new IplImage("data/match2.png", LoadMode.Color);
            Surf(img1, img2);*/

            //Mat[] mats = StitchingPreprocess(400, 400, 10);
            //Stitching(mats);
            //Track();
            //Run();
        }
开发者ID:0sv,项目名称:opencvsharp,代码行数:28,代码来源:Program.cs

示例3: KinectImage

        //セットアップ
        public KinectImage()
        #region
        {
            //キネクト
            this.kinect = KinectSensor.GetDefault();
            
            //bodyIndexFrameの処理
            this.bodyIndexFrameDes = this.kinect.BodyIndexFrameSource.FrameDescription;
            this.bodyIndexFrameReader = this.kinect.BodyIndexFrameSource.OpenReader();
            this.bodyIndexFrameReader.FrameArrived += this.BodyIndexFrame_Arrived;
            //画像情報
            this.kinectImgPackage = new ShadowPackage();
            this.imageWidth =  this.bodyIndexFrameDes.Width;  // imgW;
            this.imageHeight = this.bodyIndexFrameDes.Height; // imgH;

            this.imageBytePerPixel = (int)this.bodyIndexFrameDes.BytesPerPixel;
            this.bitmapRec = new Int32Rect(0, 0, this.imageWidth, this.imageHeight);
            this.bitmapStride = (int)(this.imageWidth * this.imageBytePerPixel);
           
            this.bodyIndexBuffer = new byte[this.imageWidth *
                                                this.imageHeight * this.imageBytePerPixel];
            this.kinectImage = new Mat(this.imageHeight, this.imageWidth, MatType.CV_8UC1);
            //キネクト開始
            this.kinect.Open();
            
        }
开发者ID:mahoo168,项目名称:mahoo,代码行数:27,代码来源:KinectImage.cs

示例4: ToMat

        /// <summary>
        /// System.Drawing.BitmapからOpenCVのMatへ変換して返す.
        /// </summary>
        /// <param name="src">変換するSystem.Drawing.Bitmap</param>
        /// <returns>変換結果のMat</returns>
#else
        /// <summary>
        /// Converts System.Drawing.Bitmap to Mat
        /// </summary>
        /// <param name="src">System.Drawing.Bitmap object to be converted</param>
        /// <returns>A Mat object which is converted from System.Drawing.Bitmap</returns>
#endif
        public static Mat ToMat(this Bitmap src)
        {
            if (src == null)
                throw new ArgumentNullException("src");

            int w = src.Width;
            int h = src.Height;
            int channels;
            switch (src.PixelFormat)
            {
                case PixelFormat.Format24bppRgb:
                case PixelFormat.Format32bppRgb:
                    channels = 3; break;
                case PixelFormat.Format32bppArgb:
                case PixelFormat.Format32bppPArgb:
                    channels = 4; break;
                case PixelFormat.Format8bppIndexed:
                case PixelFormat.Format1bppIndexed:
                    channels = 1; break;
                default:
                    throw new NotImplementedException();
            }

            Mat dst = new Mat(h, w, MatType.CV_8UC(channels));
            ToMat(src, dst);
            return dst;
        }
开发者ID:MJunak,项目名称:opencvsharp,代码行数:39,代码来源:BitmapConverter_Mat.cs

示例5: StitchingPreprocess

        private static Mat[] StitchingPreprocess(int width, int height, int count)
        {
            Mat source = new Mat(@"C:\Penguins.jpg", LoadMode.Color);
            Mat result = source.Clone();

            var rand = new Random();
            var mats = new List<Mat>();
            for (int i = 0; i < count; i++)
            {
                int x1 = rand.Next(source.Cols - width);
                int y1 = rand.Next(source.Rows - height);
                int x2 = x1 + width;
                int y2 = y1 + height;

                result.Line(new Point(x1, y1), new Point(x1, y2), new Scalar(0, 0, 255));
                result.Line(new Point(x1, y2), new Point(x2, y2), new Scalar(0, 0, 255));
                result.Line(new Point(x2, y2), new Point(x2, y1), new Scalar(0, 0, 255));
                result.Line(new Point(x2, y1), new Point(x1, y1), new Scalar(0, 0, 255));

                Mat m = source[new Rect(x1, y1, width, height)];
                mats.Add(m.Clone());
                //string outFile = String.Format(@"C:\temp\stitching\{0:D3}.png", i);
                //m.SaveImage(outFile);
            }

            result.SaveImage(@"C:\temp\parts.png");
            using (new Window(result))
            {
                Cv.WaitKey();
            }

            return mats.ToArray();
        }
开发者ID:0sv,项目名称:opencvsharp,代码行数:33,代码来源:Program.cs

示例6: Canny

        /// <summary>
        /// Cannyアルゴリズムを用いて,画像のエッジを検出します.
        /// </summary>
        /// <param name="image">8ビット,シングルチャンネルの入力画像</param>
        /// <param name="edges">出力されるエッジのマップ. image  と同じサイズ,同じ型</param>
        /// <param name="threshold1">ヒステリシスが存在する処理の,1番目の閾値</param>
        /// <param name="threshold2">ヒステリシスが存在する処理の,2番目の閾値</param>
        /// <param name="apertureSize">Sobelオペレータのアパーチャサイズ [既定値はApertureSize.Size3]</param>
        /// <param name="L2gradient">画像勾配の強度を求めるために,より精度の高い L2ノルムを利用するか,L1ノルムで十分(false)かを指定します. [既定値はfalse]</param>
#else
        /// <summary>
        /// Finds edges in an image using Canny algorithm.
        /// </summary>
        /// <param name="image">Single-channel 8-bit input image</param>
        /// <param name="edges">The output edge map. It will have the same size and the same type as image</param>
        /// <param name="threshold1">The first threshold for the hysteresis procedure</param>
        /// <param name="threshold2">The second threshold for the hysteresis procedure</param>
        /// <param name="apertureSize">Aperture size for the Sobel operator [By default this is ApertureSize.Size3]</param>
        /// <param name="L2gradient">Indicates, whether the more accurate L2 norm should be used to compute the image gradient magnitude (true), or a faster default L1 norm is enough (false). [By default this is false]</param>
#endif
        public static void Canny(Mat image, Mat edges, double threshold1, double threshold2, ApertureSize apertureSize = ApertureSize.Size3, bool L2gradient = false)
        {
            if (image == null)
                throw new ArgumentNullException("image");
            if (edges == null)
                throw new ArgumentNullException("edges");
            CppInvoke.cv_Canny(image.CvPtr, edges.CvPtr, threshold1, threshold2, apertureSize, L2gradient);
        }
开发者ID:qxp1011,项目名称:opencvsharp,代码行数:28,代码来源:CvCpp.cs

示例7: Filter

 public Mat Filter(Mat src)
 {
     var dst = new Mat();
     using (var k = GetMat())
     {
         Cv2.Filter2D(src, dst, MatType.CV_8U, k);
         return dst;
     }
 }
开发者ID:0V,项目名称:AuxSpatialFilter,代码行数:9,代码来源:SpatialFilterKernel.cs

示例8: Index

        /// <summary>
        /// 与えられたデータセットの最近傍探索インデックスを作成します.
        /// </summary>
        /// <param name="features">インデックス作成対象となる特徴(点)が格納された, CV_32F 型の行列.この行列のサイズは matrix is num _ features x feature _ dimensionality となります</param>
        /// <param name="params">params – インデックスパラメータを含む構造体.作成されるインデックスの種類は,このパラメータの種類に依存します</param>
#else
        /// <summary>
        /// Constructs a nearest neighbor search index for a given dataset.
        /// </summary>
        /// <param name="features">features – Matrix of type CV _ 32F containing the features(points) to index. The size of the matrix is num _ features x feature _ dimensionality.</param>
        /// <param name="params">Structure containing the index parameters. The type of index that will be constructed depends on the type of this parameter. </param>
#endif
        public Index(Mat features, IndexParams @params)
        {
            if (features == null)
                throw new ArgumentNullException("features");
            if (@params == null)
                throw new ArgumentNullException("params");

            ptr = NativeMethods.flann_Index_construct(features.CvPtr, @params.CvPtr);
            if (ptr == IntPtr.Zero)
                throw new OpenCvSharpException("Failed to create Index");
        }
开发者ID:jorik041,项目名称:opencvsharp,代码行数:23,代码来源:Index.cs

示例9: FilterAsync

 public Task<Mat> FilterAsync(Mat src)
 {
     return Task.Run(() =>
     {
         var dst = new Mat();
         using (var k = GetMat())
         {
             Cv2.Filter2D(src, dst, MatType.CV_8U, k);
             return dst;
         }
     });
 }
开发者ID:0V,项目名称:AuxSpatialFilter,代码行数:12,代码来源:SpatialFilterKernel.cs

示例10: Run

        private static void Run()
        {
            var dm = DescriptorMatcher.Create("BruteForce");
            dm.Clear();

            Console.WriteLine(Cv2.GetCudaEnabledDeviceCount());

            string[] algoNames = Algorithm.GetList();
            Console.WriteLine(String.Join("\n", algoNames));

            SIFT al1 = Algorithm.Create<SIFT>("Feature2D.SIFT");
            string[] ppp = al1.GetParams();
            Console.WriteLine(ppp);
            var t = al1.ParamType("contrastThreshold");
            double d = al1.GetDouble("contrastThreshold");
            t.ToString();
            d.ToString();

            var src = new Mat("img/lenna.png");
            var rand = new Random();
            var memory = new List<long>(100);

            var a1 = new Mat(src, Rect.FromLTRB(0, 0, 30, 40));
            var a2 = new Mat(src, Rect.FromLTRB(0, 0, 30, 40));
            var a3 = new Mat(src, Rect.FromLTRB(0, 0, 30, 40));
            a3.ToString();

            for (long i = 0;; i++)
            {
                SIFT a = Algorithm.Create<SIFT>("Feature2D.SIFT");
                a.ToString();

                for (int j = 0; j < 200; j++)
                {
                    int c1 = rand.Next(100, 400);
                    int c2 = rand.Next(100, 400);
                    Mat temp = src.Row[c1];
                    src.Row[c1] = src.Row[c2];
                    src.Row[c2] = temp;
                }

                memory.Add(MyProcess.WorkingSet64);
                if (memory.Count >= 100)
                {
                    double average = memory.Average();
                    Console.WriteLine("{0:F3}MB", average / 1024.0 / 1024.0);
                    memory.Clear();
                    GC.Collect();
                }
            }

        }
开发者ID:kaorun55,项目名称:opencvsharp,代码行数:52,代码来源:Program.cs

示例11: MatExpr

 /// <summary>
 /// 
 /// </summary>
 /// <param name="mat"></param>
 internal MatExpr(Mat mat)
 {
     if(mat == null)
         throw new ArgumentNullException("mat");
     try
     {
         this.ptr = NativeMethods.core_MatExpr_new(mat.CvPtr);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
开发者ID:healtech,项目名称:opencvsharp,代码行数:17,代码来源:MatExpr.cs

示例12: ConvertMaps

        public static void ConvertMaps(Mat map1, Mat map2, Mat dstmap1, Mat dstmap2, MatrixType dstmap1type, bool nninterpolation = false)
        {
            if (map1 == null)
                throw new ArgumentNullException("map1");
            if (map2 == null)
                throw new ArgumentNullException("map2");
            if (dstmap1 == null)
                throw new ArgumentNullException("dstmap1");
            if (dstmap2 == null)
                throw new ArgumentNullException("dstmap2");

            CppInvoke.cv_convertMaps(map1.CvPtr, map2.CvPtr, dstmap1.CvPtr, dstmap2.CvPtr, dstmap1type, nninterpolation);
        }
开发者ID:neoxeo,项目名称:opencvsharp,代码行数:13,代码来源:CvCpp.cs

示例13: ToMat

        /// <summary>
        /// WriteableBitmapをMatに変換する
        /// </summary>
        /// <param name="src">変換するWriteableBitmap</param>
        /// <returns>OpenCvSharpで扱えるMat</returns>
#else
        /// <summary>
        /// Converts WriteableBitmap to Mat
        /// </summary>
        /// <param name="src">Input WriteableBitmap</param>
        /// <returns>IplImage</returns>
#endif
        public static Mat ToMat(this WriteableBitmap src)
        {
            if (src == null)
            {
                throw new ArgumentNullException("src");
            }

            int w = src.PixelWidth;
            int h = src.PixelHeight;            
            MatType type = GetOptimumType(src.Format);
            Mat dst = new Mat(h, w, type);
            ToMat(src, dst);
            return dst;
        }
开发者ID:0sv,项目名称:opencvsharp,代码行数:26,代码来源:WriteableBitmapConverter2.cs

示例14: Filter

 public static ImageData Filter(string fileName, SpatialFilterKernel kernel)
 {
     try
     {
         var src = new Mat(fileName);
         var bmp = kernel.FilterWriteableBitmap(src);
         var images = new ImageData();
         images.SourceImage = src.ToWriteableBitmap();
         images.ResultImage = bmp;
         return images;
     }
     finally
     {
     }
 }
开发者ID:0V,项目名称:AuxSpatialFilter,代码行数:15,代码来源:ImageManager.cs

示例15: ImShow

 /// <summary>
 /// Displays the image in the specified window
 /// </summary>
 /// <param name="winname">Name of the window.</param>
 /// <param name="mat">Image to be shown.</param>
 public static void ImShow(string winname, Mat mat)
 {
     if (string.IsNullOrEmpty(winname))
         throw new ArgumentNullException("winname");
     if (mat == null)
         throw new ArgumentNullException("mat");
     try
     {
         NativeMethods.highgui_imshow(winname, mat.CvPtr);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
开发者ID:jorik041,项目名称:opencvsharp,代码行数:20,代码来源:Cv2_highgui.cs


注:本文中的OpenCvSharp.CPlusPlus.Mat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。