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


C# Mat.SetTo方法代码示例

本文整理汇总了C#中Emgu.CV.Mat.SetTo方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.SetTo方法的具体用法?C# Mat.SetTo怎么用?C# Mat.SetTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Emgu.CV.Mat的用法示例。


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

示例1: image1_Initialized

      private void image1_Initialized(object sender, EventArgs e)
      {
         Mat image = new Mat(100, 400, DepthType.Cv8U, 3);
         image.SetTo(new Bgr(255, 255, 255).MCvScalar);
         CvInvoke.PutText(image, "Hello, world", new System.Drawing.Point(10, 50), Emgu.CV.CvEnum.FontFace.HersheyPlain, 3.0, new Bgr(255.0, 0.0, 0.0).MCvScalar);

         image1.Source = BitmapSourceConvert.ToBitmapSource(image);
      }
开发者ID:reidblomquist,项目名称:emgucv,代码行数:8,代码来源:Window1.xaml.cs

示例2: HelloWorldPage

       public HelloWorldPage()
          : base()
       {
          this.GetButton().Opacity = 0;
         Mat img = new Mat(200, 400, DepthType.Cv8U, 3); //Create a 3 channel image of 400x200
         img.SetTo(new Bgr(255, 0, 0).MCvScalar); // set it to Blue color

         //Draw "Hello, world." on the image using the specific font
         CvInvoke.PutText(
            img,
            "Hello, world",
            new System.Drawing.Point(10, 80),
            FontFace.HersheyComplex,
            1.0,
            new Bgr(0, 255, 0).MCvScalar);

         SetImage(img);
      }
开发者ID:neutmute,项目名称:emgucv,代码行数:18,代码来源:HelloWorldPage.cs

示例3: Main

      static void Main(string[] args)
      {
         String win1 = "Test Window"; //The name of the window
         CvInvoke.NamedWindow(win1); //Create the window using the specific name

         Mat img = new Mat(200, 400, DepthType.Cv8U, 3); //Create a 3 channel image of 400x200
         img.SetTo(new Bgr(255, 0, 0).MCvScalar); // set it to Blue color

         //Draw "Hello, world." on the image using the specific font
         CvInvoke.PutText(
            img, 
            "Hello, world", 
            new System.Drawing.Point(10, 80), 
            FontFace.HersheyComplex, 
            1.0, 
            new Bgr(0, 255, 0).MCvScalar);
         

         CvInvoke.Imshow(win1, img); //Show the image
         CvInvoke.WaitKey(0);  //Wait for the key pressing event
         CvInvoke.DestroyWindow(win1); //Destroy the window if key is pressed
      }
开发者ID:reidblomquist,项目名称:emgucv,代码行数:22,代码来源:Program.cs

示例4: NavigationHelper_LoadState

       /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>.
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            var item = await SampleDataSource.GetItemAsync((string)e.NavigationParameter);
            this.DefaultViewModel["Item"] = item;
           if (item.Title.Equals("Run Hello World"))
           {
              Mat img = new Mat(200, 400, DepthType.Cv8U, 3);
              img.SetTo(new MCvScalar(255, 0, 0));
              CvInvoke.PutText(img, "Hello world.", new System.Drawing.Point(10, 80), FontFace.HersheyComplex, 1.0, new MCvScalar(0, 255, 0));

              ImageView.Source = img.ToWritableBitmap();
           } else if (item.Title.Equals("Run Planar Subdivision"))
           {
              Mat img = PlanarSubdivisionExample.DrawSubdivision.Draw(400, 30);
              ImageView.Source = img.ToWritableBitmap();
           } else if (item.Title.Equals("Run Face Detection"))
           {
              Mat img = await LoadImage(@"Assets\Images\lena.jpg");

              List<Rectangle> faces = new List<Rectangle>();
              List<Rectangle> eyes = new List<Rectangle>();
              long detectionTime;
              FaceDetection.DetectFace.Detect(img, "haarcascade_frontalface_default.xml", "haarcascade_eye.xml",
                 faces, eyes, false, false, out detectionTime);

              foreach (Rectangle face in faces)
                 CvInvoke.Rectangle(img, face, new Bgr(0, 0, 255).MCvScalar, 2);
              foreach (Rectangle eye in eyes)
                 CvInvoke.Rectangle(img, eye, new Bgr(255, 0, 0).MCvScalar, 2);
              ImageView.Source = img.ToWritableBitmap();
            
           } else if (item.Title.Equals("Run Pedestrian Detection"))
           {
              Mat img = await LoadImage(@"Assets\Images\pedestrian.png");
              Mat gray = new Mat();
              CvInvoke.CvtColor(img, gray, ColorConversion.Bgr2Gray);
              long detectionTime;
              Rectangle[] pedestrians = PedestrianDetection.FindPedestrian.Find(gray, false, false, out detectionTime);
              foreach (Rectangle pedestrian in pedestrians)
              {
                 CvInvoke.Rectangle(img, pedestrian, new MCvScalar(0, 0, 255) );
              }
              ImageView.Source = img.ToWritableBitmap();
           }
        }
开发者ID:reidblomquist,项目名称:emgucv,代码行数:57,代码来源:ItemPage.xaml.cs

示例5: Bayer

        private void Bayer()
        {
            var width = 800;
            var height = 600;
            var header = 1024;
            Mat img = new Mat(height, width, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
            byte[] data = new byte[height * width];
            using (Stream input = new FileStream("Schlittentest.raw", FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                input.Read(data, 0, header); //Skip header
                input.Read(data, 0, height * width);
            }
            img.SetTo(data);
            Mat rgb = new Mat();
            CvInvoke.CvtColor(img, rgb, Emgu.CV.CvEnum.ColorConversion.BayerBg2Rgb);

            //Setup an own rgb image
            Mat mine = new Mat(height, width, Emgu.CV.CvEnum.DepthType.Cv8U, 3);
            byte[] myDat = new byte[3 * height * width];
            Func<int, byte> get = (loc) => data[Math.Max(0, Math.Min(data.Length - 1, loc))];
            Func<int, byte> myget = (loc) => myDat[Math.Max(0, Math.Min(myDat.Length - 1, loc))];
            Func<int, int[], byte> all = (loc, permutations) => (byte) permutations.Average(p => get(loc + p));
            Func<int, byte> green = (loc) => all(loc, new int[] { -width, -1, +1, width });
            Func<int, byte> redBlue = (loc) => all(loc, new int[] { -width - 1, width + 1, -width + 1, width - 1 });
            for (int v = 0; v < height; ++v)
            {
                var row = v * width;
                var rowEven = v % 2 == 0;
                for (int u = 0; u < width; ++u)
                {
                    var loc = row + u;
                    var colEven = u % 2 == 0;
                    myDat[3 * loc]     = colEven && rowEven ? data[loc] :
                        (!colEven && !rowEven ? redBlue(loc) : (byte)0);
                    myDat[3 * loc + 1] = colEven == rowEven ? green(loc) : data[loc];
                    myDat[3 * loc + 2] = !colEven && !rowEven ? data[loc] :
                        (colEven && rowEven ? redBlue(loc) : (byte)0);

                    //if (colEven && rowEven)
                    //{
                    //    myDat[3 * loc] = 0;
                    //    myDat[3 * loc + 1] = 0;
                    //    myDat[3 * loc + 2] = get(loc);
                    //}
                    //else if (!colEven && !rowEven)
                    //{
                    //    myDat[3 * loc] = get(loc);
                    //    myDat[3 * loc + 1] = 0;
                    //    myDat[3 * loc + 2] = 0;
                    //}
                    //else if (colEven && !rowEven)
                    //{
                    //    myDat[3 * loc] = 0;
                    //    myDat[3 * loc + 1] = get(loc);
                    //    myDat[3 * loc + 2] = 0;
                    //}
                    //else
                    //{
                    //    myDat[3 * loc] = 0;
                    //    myDat[3 * loc + 1] = get(loc);
                    //    myDat[3 * loc + 2] = 0;
                    //}

                    //"Perfect" Bayer
                    //if (colEven && rowEven)
                    //{
                    //    myDat[3 * loc] = get(loc);
                    //    myDat[3 * loc + 1] = (byte)((get(loc + 1) + get(loc + width)) / 2);
                    //    myDat[3 * loc + 2] = get(loc + width + 1);
                    //}
                    //else if (!colEven && !rowEven)
                    //{
                    //    myDat[3 * loc] = get(loc - width - 1);
                    //    myDat[3 * loc + 1] = (byte)((get(loc - 1) + get(loc - width)) / 2);
                    //    myDat[3 * loc + 2] = get(loc);
                    //}
                    //else if (colEven && !rowEven)
                    //{
                    //    myDat[3 * loc] = get(loc - width);
                    //    myDat[3 * loc + 1] = (byte)((get(loc) + get(loc - width + 1)) / 2);
                    //    myDat[3 * loc + 2] = get(loc + 1);
                    //}
                    //else
                    //{
                    //    myDat[3 * loc] = get(loc - 1);
                    //    myDat[3 * loc + 1] = (byte)((get(loc) + get(loc + width - 1)) / 2);
                    //    myDat[3 * loc + 2] = get(loc + width);
                    //}
                }
            }
            for (int v = 0; v < height; ++v)
            {
                var row = v * width;
                var rowEven = v % 2 == 0;
                for (int u = 0; u < width; ++u)
                {
                    var loc = row + u;
                    var colEven = u % 2 == 0;
                    if (colEven != rowEven)
                    {
//.........这里部分代码省略.........
开发者ID:TheJP,项目名称:bver,代码行数:101,代码来源:Form.cs

示例6: View3DGlControl_Load

      private void View3DGlControl_Load(object sender, EventArgs e)
      {
         _glLoaded = true;

         GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
         SetupViewport();

         #region Create texture for the 3D Point clouds
         int repeat = (int)OpenTK.Graphics.OpenGL.All.Repeat;
         int linear = (int)OpenTK.Graphics.OpenGL.All.Linear;
         GL.Enable(EnableCap.CullFace);
         GL.Enable(EnableCap.Texture2D);
         _textures = new int[1];
         GL.GenTextures(1, _textures);
         GL.BindTexture(TextureTarget.Texture2D, _textures[0]);
         GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, ref repeat);
         GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, ref repeat);
         GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, ref linear);
         GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, ref linear);
         GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)OpenTK.Graphics.OpenGL.All.Decal);
         GL.ShadeModel(ShadingModel.Smooth);
         GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
         GL.BindTexture(TextureTarget.Texture2D, 1);

         Size size = _left.Size;
         int maxDim = Math.Max(size.Width, size.Height);
         using (Mat squareImg = new Mat(maxDim, maxDim, DepthType.Cv8U, 3))
         {
            squareImg.SetTo(new MCvScalar());
            Rectangle roi = new Rectangle(maxDim / 2 - size.Width / 2, maxDim / 2 - size.Height / 2, size.Width, size.Height);
            Mat roiImg = new Mat(squareImg, roi);
            _left.CopyTo(roiImg);

            if (_texture == null)
               _texture = new Mat();
            CvInvoke.Resize(squareImg, _texture, new Size(256, 256), 0, 0, Emgu.CV.CvEnum.Inter.Cubic);
           
            CvInvoke.Flip(_texture, _texture, Emgu.CV.CvEnum.FlipType.Vertical);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb8, _texture.Width, _texture.Height, 0, PixelFormat.Bgr, PixelType.UnsignedByte, _texture.DataPointer);
         }
         #endregion
         
      }
开发者ID:reidblomquist,项目名称:emgucv,代码行数:43,代码来源:Simple3DReconstruction.cs

示例7: transformColor

        //Transform images according to transform matrix
        // From Line 130-239
        public static ReturnColorImg transformColor(Mat img1, Mat mask1, Mat img2, Mat mask2,
           Mat dst, Mat dst_mask,
                      Point centroid1, Point centroid2, double angle, Point tweak1, Point tweak2, bool mode = true)
        {
            Mat E = img2.Clone();
            Mat E_mask = mask2.Clone();//Don't ruin original images

            double intersections = 0;
            double x = centroid2.X;
            double y = centroid2.Y;
            double _x, _y, _y2;
            double y2;

            LineSegment2D centerLine = new LineSegment2D(new Point((int)x, (int)y), new Point(img2.Width - (int)x, img2.Height - (int)y));
            //Rectangle r=new Rectangle((int)x,(int)y,2*(img2.Width-(int)x),2*(img2.Height-(int)y));

            Mat ri = new Mat(2 * (img2.Width - (int)x), 2 * (img2.Height - (int)y),DepthType.Cv8U, 3);
            ri.SetTo(new MCvScalar(255, 255, 255));
            Point oldc = new Point((int)x, (int)y);
            bool success = false; // if the tweaking is not successful, return false
            // inverse y axis
            // y2 = -y;
            // rotation of centeroid

            x -= img2.Width / 2;
            y -= img2.Height / 2;//shift origin to (w/2,h/2)
            _x = x * Math.Cos(angle / (180 / Math.PI)) - y * Math.Sin(angle / (180 / Math.PI));//rotate by theta
            _y = x * Math.Sin(angle / (180 / Math.PI)) + y * Math.Cos(angle / (180 / Math.PI));

            _x += img2.Width / 2;
            _y += img2.Height / 2;//back to origin

            //_x = x+img2.Width/2;
            //_y = y+img2.Height/2;

            // inverse y axis
            //_y = -_y2;

            centroid2.X = (int)_x;
            centroid2.Y = (int)_y;
            Point shift = new Point();
            shift.X = centroid1.X - centroid2.X;
            shift.Y = centroid1.Y - centroid2.Y;
            MatImage m1 = new MatImage(E);
            m1.Rotate(angle, new Bgr(255, 255, 255));
            E = m1.Out();

            MatImage m2 = new MatImage(E_mask);
            m1.Rotate(angle, new Bgr(255, 255, 255));
            E_mask = m2.Out();

            //Find optimal size of canvas to hold both images and appropriate transformations
            Point t1, t2;//transformation 1 and 2
            t1 = new Point();
            t2 = new Point();
            int optimal_h = 0, optimal_w = 0;//of canvas(IplImage* dst)
            switch (quadrant(shift))
            {
                case 1:
                    t1.X = 0;
                    t1.Y = 0;
                    t2 = shift;
                    optimal_h = Math.Max(img1.Height, img2.Height + shift.Y);
                    optimal_w = Math.Max(img1.Width, img2.Width + shift.X);
                    break;
                case 2:
                    t1.X = -shift.X;
                    t1.Y = 0;
                    t2.X = 0;
                    t2.Y = shift.Y;
                    optimal_h = Math.Max(img1.Height, img2.Height + shift.Y);
                    optimal_w = Math.Max(img2.Width, img1.Width - shift.X);
                    break;
                case 3:
                    t1.X = -shift.X;
                    t1.Y = -shift.Y;
                    t2.X = 0;
                    t2.Y = 0;
                    optimal_h = Math.Max(img1.Height - shift.Y, img2.Height);
                    optimal_w = Math.Max(img1.Width - shift.X, img2.Width);
                    break;
                case 4:
                    t1.X = 0;
                    t1.Y = -shift.Y;
                    t2.X = shift.X;
                    t2.Y = 0;
                    optimal_h = Math.Max(img1.Height - shift.Y, img2.Height);
                    optimal_w = Math.Max(img2.Width + shift.X, img1.Width);
                    break;
            }

            // add tweak factor
            t1.X += tweak1.X;
            t1.Y += tweak1.Y;
            t2.X += tweak2.X;
            t2.Y += tweak2.Y;

            //optimal_h = 1000;
//.........这里部分代码省略.........
开发者ID:gw-sd-2016,项目名称:TornRepair,代码行数:101,代码来源:Transformation.cs


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