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


C# Image.SetRandUniform方法代码示例

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


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

示例1: TestAcc

        public void TestAcc()
        {
            Image<Gray, Single> img1 = new Image<Gray, Single>(300, 200);
             img1.SetRandUniform(new MCvScalar(0), new MCvScalar(255));
             Image<Gray, Single> img2 = new Image<Gray, Single>(300, 200);
             img2.SetRandUniform(new MCvScalar(0), new MCvScalar(255));

             Image<Gray, Single> img3 = img1.Copy();
             img3.Acc(img2);

             Assert.IsTrue(img3.Equals(img1 + img2));
        }
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:12,代码来源:AutoTestImage.cs

示例2: TestDenseHistogram

      public void TestDenseHistogram()
      {
         Image<Gray, Byte> img = new Image<Gray, byte>(400, 400);
         img.SetRandUniform(new MCvScalar(), new MCvScalar(255));
         DenseHistogram hist = new DenseHistogram(256, new RangeF(0.0f, 255.0f));
         hist.Calculate<Byte>(new Image<Gray, byte>[] { img }, true, null);
         float[] binValues = hist.GetBinValues();
         /*
         using (MemoryStream ms = new MemoryStream())
         {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
            formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            formatter.Serialize(ms, hist);
            Byte[] bytes = ms.GetBuffer();

            using (MemoryStream ms2 = new MemoryStream(bytes))
            {
               Object o = formatter.Deserialize(ms2);
               DenseHistogram hist2 = (DenseHistogram)o;
               EmguAssert.IsTrue(hist.Equals(hist2));
            }
         }*/
      }
开发者ID:Delaley,项目名称:emgucv,代码行数:23,代码来源:AutoTestVarious.cs

示例3: PerformanceComparison

        public void PerformanceComparison()
        {
            Image<Gray, Byte> img1 = new Image<Gray, byte>(1920, 1080);
             Image<Gray, Byte> img2 = new Image<Gray, byte>(img1.Size);

             img1.SetRandUniform(new MCvScalar(0), new MCvScalar(50));
             img2.SetRandUniform(new MCvScalar(0), new MCvScalar(50));

             Stopwatch w = Stopwatch.StartNew();
             Image<Gray, Byte> sum1 = img1 + img2;
             w.Stop();
             Trace.WriteLine(String.Format("OpenCV Time:\t\t\t\t\t\t{0} ms", w.ElapsedMilliseconds));

             w.Reset(); w.Start();
             Image<Gray, Byte> sum2 = new Image<Gray, byte>(img1.Size);
             Byte[, ,] data1 = img1.Data;
             Byte[, ,] data2 = img2.Data;
             Byte[, ,] dataSum = sum2.Data;
             int rows = img1.Rows;
             int cols = img1.Cols;
             for (int i = 0; i < rows; i++)
            for (int j = 0; j < cols; j++)
               dataSum[i, j, 0] = (Byte) (data1[i, j, 0] + data2[i, j, 0]);
             w.Stop();
             Trace.WriteLine(String.Format(".NET array manipulation Time:\t\t{0} ms", w.ElapsedMilliseconds));

             Assert.IsTrue(sum2.Equals(sum1));

             w.Reset(); w.Start();
             Func<Byte, Byte, Byte> convertor = delegate(Byte b1, Byte b2) { return (Byte)(b1 + b2); };
             Image<Gray, Byte> sum3 = img1.Convert<Byte, Byte>(img2, convertor);
             w.Stop();
             Trace.WriteLine(String.Format("Generic image manipulation Time:\t{0} ms", w.ElapsedMilliseconds));

             Assert.IsTrue(sum3.Equals(sum1));
        }
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:36,代码来源:AutoTestImage.cs

示例4: TestGenericSetColor

      public void TestGenericSetColor()
      {
         Image<Bgr, Byte> img1 = new Image<Bgr, Byte>(20, 40, new Bgr());

         int flag = 0;

         Image<Bgr, Byte> img2 = img1.Convert<Byte>(
             delegate(Byte b)
             {
                return ((flag++ % 3) == 0) ? (Byte)255 : (Byte)0;
             });

         img1.SetValue(new Bgr(255, 0, 0));

         Image<Bgr, Byte> img = new Image<Bgr, byte>(800, 800);
         img.SetValue(255);
         Image<Bgr, Byte> mask = new Image<Bgr, byte>(img.Width, img.Height);
         mask.SetRandUniform(new MCvScalar(0, 0, 0), new MCvScalar(255, 255, 255)); //file the mask with random color

         Stopwatch watch = Stopwatch.StartNew();
         Image<Bgr, Byte> imgMasked = img.Convert<Byte, Byte>(mask,
            delegate(Byte byteFromImg, Byte byteFromMask)
            {
               return byteFromMask > (Byte)120 ? byteFromImg : (Byte)0;
            });
         watch.Stop();
         EmguAssert.WriteLine(String.Format("Time used: {0} milliseconds", watch.ElapsedMilliseconds));

         EmguAssert.IsTrue(img1.Equals(img2));
      }
开发者ID:neutmute,项目名称:emgucv,代码行数:30,代码来源:AutoTestImage.cs

示例5: TestConversion

      public void TestConversion()
      {
         Image<Bgr, Single> img1 = new Image<Bgr, Single>(100, 100);
         img1.SetRandUniform(new MCvScalar(), new MCvScalar(255.0, 255.0, 255.0));

         Image<Xyz, Single> img2 = img1.Convert<Xyz, Single>();

         Image<Gray, Byte> img3 = img1.Convert<Gray, Byte>();

      }
开发者ID:neutmute,项目名称:emgucv,代码行数:10,代码来源:AutoTestImage.cs

示例6: TestConvertDepth

      public void TestConvertDepth()
      {
         Image<Gray, Byte> img1 = new Image<Gray, byte>(100, 100, new Gray(10.0));
         img1.SetRandUniform(new MCvScalar(0, 0, 0), new MCvScalar(255, 255, 255));
         Image<Gray, Single> img2 = img1.ConvertScale<Single>(2.0, 0.0);
         Image<Gray, Byte> img3 = img2.ConvertScale<Byte>(0.5, 0.0);
         EmguAssert.IsTrue(img3.Equals(img1));

         Image<Gray, Double> img4 = img1.Convert<Gray, Double>();
         Image<Gray, Byte> img5 = img4.Convert<Gray, Byte>();
         EmguAssert.IsTrue(img5.Equals(img1));
      }
开发者ID:neutmute,项目名称:emgucv,代码行数:12,代码来源:AutoTestImage.cs

示例7: TestGraySingleImage

 public void TestGraySingleImage()
 {
    Image<Gray, Single> img = new Image<Gray, float>(320, 480);
    img.SetRandUniform(new MCvScalar(), new MCvScalar(255));
    Image<Gray, Byte> mask = img.Cmp(100, CvEnum.CmpType.GreaterEqual);
    int[] count = mask.CountNonzero();
    int c = count[0];
 }
开发者ID:Delaley,项目名称:emgucv,代码行数:8,代码来源:AutoTestVarious.cs

示例8: TestMoment

 public void TestMoment()
 {
    Image<Gray, byte> image = new Image<Gray, byte>(100, 200);
    image.SetRandUniform(new MCvScalar(), new MCvScalar(255));
    image.ThresholdToZero(new Gray(120));
    MCvMoments moment = image.GetMoments(true);
    double[] huMoment = moment.GetHuMoment();
 }
开发者ID:neutmute,项目名称:emgucv,代码行数:8,代码来源:AutoTestImage.cs

示例9: TestSplitMerge

      public void TestSplitMerge()
      {
         Image<Bgr, Byte> img1 = new Image<Bgr, byte>(301, 234);
         img1.SetRandUniform(new MCvScalar(), new MCvScalar(255, 255, 255));
         Image<Gray, Byte>[] channels = img1.Split();

         Image<Bgr, Byte> img2 = new Image<Bgr, byte>(channels);
         EmguAssert.IsTrue(img1.Equals(img2));
      }
开发者ID:neutmute,项目名称:emgucv,代码行数:9,代码来源:AutoTestImage.cs

示例10: TestImageSaveHelper

      private static void TestImageSaveHelper(String extension, System.Drawing.Imaging.ImageFormat format, double epsilon)
      {
         String fileName = GetTempFileName() + extension;
         try
         {
            using (Image<Bgr, Byte> tmp = new Image<Bgr, byte>(601, 479))
            {
               tmp.SetRandUniform(new MCvScalar(), new MCvScalar(255, 255, 255));

               tmp.Save(fileName);

               using (Image i = Image.FromFile(fileName))
               {
                  /*
                  if (System.Drawing.Imaging.ImageFormat.Jpeg.Equals(i.RawFormat))
                     Trace.WriteLine("jpeg");
                  else if (System.Drawing.Imaging.ImageFormat.Gif.Equals(i.RawFormat))
                     Trace.WriteLine("gif");
                  else if (System.Drawing.Imaging.ImageFormat.Png.Equals(i.RawFormat))
                     Trace.WriteLine("png");
                  else if (System.Drawing.Imaging.ImageFormat.Bmp.Equals(i.RawFormat))
                     Trace.WriteLine("bmp");
                  */
                  Assert.IsTrue(i.RawFormat.Equals(format));
               }
               if (epsilon == 0.0)
                  Assert.IsTrue(tmp.Equals(new Image<Bgr, Byte>(fileName)));
               else
               {
                  /*
                  using (Image<Bgr, Byte> delta = new Image<Bgr, Byte>(tmp.Size))
                  using (Image<Gray, Byte> mask = new Image<Gray, byte>(tmp.Size))
                  {
                     CvInvoke.cvAbsDiff(tmp, new Image<Bgr, Byte>(fileName), delta);
                     for (int i = 0; i < delta.NumberOfChannels; i++)
                     {
                        CvInvoke.cvCmpS(delta[i], epsilon, mask, Emgu.CV.CvEnum.CMP_TYPE.CV_CMP_GE);
                        int count = CvInvoke.cvCountNonZero(mask);
                        Assert.AreEqual(0, count);
                     }
                  }*/
               }
            }
         }
         catch (Exception e)
         {
            throw e;
         }
         finally
         {
            File.Delete(fileName);
         }

      }
开发者ID:neutmute,项目名称:emgucv,代码行数:54,代码来源:AutoTestImage.cs

示例11: TestGetSubRect

 public void TestGetSubRect()
 {
    Image<Bgr, Single> image = new Image<Bgr, float>(200, 100);
    image.SetRandUniform(new MCvScalar(), new MCvScalar(255, 255, 255, 255));
    Rectangle roi = new Rectangle(10, 20, 30, 40);
    Image<Bgr, Single> roi1 = image.Copy(roi);
    Image<Bgr, Single> roi2 = image.GetSubRect(roi);
    EmguAssert.IsTrue(roi1.Equals(roi2));
 }
开发者ID:neutmute,项目名称:emgucv,代码行数:9,代码来源:AutoTestImage.cs

示例12: TestResize

 public void TestResize()
 {
    Image<Gray, Byte> image = new Image<Gray, byte>(123, 321);
    image.SetRandUniform(new MCvScalar(), new MCvScalar(255));
    image.Resize(512, 512, CvEnum.Inter.Cubic);
 }
开发者ID:neutmute,项目名称:emgucv,代码行数:6,代码来源:AutoTestImage.cs

示例13: TestGpuMatRange

 public void TestGpuMatRange()
 {
    if (CudaInvoke.HasCuda)
    {
       Image<Gray, Byte> img1 = new Image<Gray, byte>(1200, 640);
       img1.SetRandUniform(new MCvScalar(0, 0, 0), new MCvScalar(255, 255, 255));
       using (GpuMat gpuImg1 = new GpuMat(img1))
       using (GpuMat mat = new GpuMat(gpuImg1, new MCvSlice(0, 1), MCvSlice.WholeSeq))
       {
          Size s = mat.Size;
       }
    }
 }
开发者ID:Warren-GH,项目名称:emgucv,代码行数:13,代码来源:AutoTestCuda.cs

示例14: TestCudaPyr

      public void TestCudaPyr()
      {
         if (!CudaInvoke.HasCuda)
            return;
         Image<Gray, Byte> img = new Image<Gray, byte>(640, 480);
         img.SetRandUniform(new MCvScalar(), new MCvScalar(255, 255, 255));
         Image<Gray, Byte> down = img.PyrDown();
         Image<Gray, Byte> up = down.PyrUp();

         CudaImage<Gray, Byte> gImg = new CudaImage<Gray, byte>(img);
         CudaImage<Gray, Byte> gDown = new CudaImage<Gray, byte>(img.Size.Width >> 1, img.Size.Height >> 1);
         CudaImage<Gray, Byte> gUp = new CudaImage<Gray, byte>(img.Size);
         CudaInvoke.PyrDown(gImg, gDown, null);
         CudaInvoke.PyrUp(gDown, gUp, null);

         CvInvoke.AbsDiff(down, gDown.ToImage(), down);
         CvInvoke.AbsDiff(up, gUp.ToImage(), up);
         double[] minVals, maxVals;
         Point[] minLocs, maxLocs;
         down.MinMax(out minVals, out maxVals, out minLocs, out maxLocs);
         double maxVal = 0.0;
         for (int i = 0; i < maxVals.Length; i++)
         {
            if (maxVals[i] > maxVal)
               maxVal = maxVals[i];
         }
         Trace.WriteLine(String.Format("Max diff: {0}", maxVal));
         Assert.LessOrEqual(maxVal, 1.0);

         up.MinMax(out minVals, out maxVals, out minLocs, out maxLocs);
         maxVal = 0.0;
         for (int i = 0; i < maxVals.Length; i++)
         {
            if (maxVals[i] > maxVal)
               maxVal = maxVals[i];
         }
         Trace.WriteLine(String.Format("Max diff: {0}", maxVal));
         Assert.LessOrEqual(maxVal, 1.0);
      }
开发者ID:Warren-GH,项目名称:emgucv,代码行数:39,代码来源:AutoTestCuda.cs

示例15: TestCudaSURFKeypointDetection

      public void TestCudaSURFKeypointDetection()
      {
         if (CudaInvoke.HasCuda)
         {
            Image<Gray, byte> image = new Image<Gray, byte>(200, 100);
            image.SetRandUniform(new MCvScalar(), new MCvScalar(255));
            GpuMat gpuMat = new GpuMat(image);

            EmguAssert.IsTrue(gpuMat.ToMat().Equals(image.Mat));

            CudaSURF cudaSurf = new CudaSURF(100.0f, 2, 4, false, 0.01f, false);
            GpuMat cudaKpts = cudaSurf.DetectKeyPointsRaw(gpuMat, null);
            VectorOfKeyPoint kpts = new VectorOfKeyPoint();
            cudaSurf.DownloadKeypoints(cudaKpts, kpts);
         }
      }
开发者ID:Warren-GH,项目名称:emgucv,代码行数:16,代码来源:AutoTestCuda.cs


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