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


C# IImage.Split方法代码示例

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


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

示例1: GenerateHistograms

        /// <summary>
        /// Generate histograms for the image. One histogram is generated for each color channel.
        /// You will need to call the Refresh function to do the painting afterward.
        /// </summary>
        /// <param name="image">The image to generate histogram from</param>
        /// <param name="numberOfBins">The number of bins for each histogram</param>
        public void GenerateHistograms(IImage image, int numberOfBins)
        {
            IImage[] channels = image.Split();
             Type imageType = Toolbox.GetBaseType(image.GetType(), "Image`2");
             IColor typeOfColor = Activator.CreateInstance(imageType.GetGenericArguments()[0]) as IColor;
             String[] channelNames = Reflection.ReflectColorType.GetNamesOfChannels(typeOfColor);
             Color[] colors = Reflection.ReflectColorType.GetDisplayColorOfChannels(typeOfColor);

             float minVal, maxVal;
             #region Get the maximum and minimum color intensity values
             Type typeOfDepth = imageType.GetGenericArguments()[1];
             if (typeOfDepth == typeof(Byte))
             {
            minVal = 0.0f;
            maxVal = 256.0f;
             }
             else
             {
            #region obtain the maximum and minimum color value
            double[] minValues, maxValues;
            Point[] minLocations, maxLocations;
            image.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);

            double min = minValues[0], max = maxValues[0];
            for (int i = 1; i < minValues.Length; i++)
            {
               if (minValues[i] < min) min = minValues[i];
               if (maxValues[i] > max) max = maxValues[i];
            }
            #endregion

            minVal = (float)min;
            maxVal = (float)max;
             }
             #endregion

             for (int i = 0; i < channels.Length; i++)
            using (DenseHistogram hist = new DenseHistogram(numberOfBins, new RangeF(minVal, maxVal)))
            {
               hist.Calculate(new IImage[1] { channels[i] }, true, null);
               AddHistogram(channelNames[i], colors[i], hist);
            }
        }
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:49,代码来源:HistogramBox.cs

示例2: cvGetTextSize

      /*
      /// <summary>
      /// Calculates the binding rectangle for the given text string when a specified font is used
      /// </summary>
      /// <param name="textString">Input string</param>
      /// <param name="font">The font structure</param>
      /// <param name="textSize">Resultant size of the text string. Height of the text does not include the height of character parts that are below the baseline</param>
      /// <param name="baseline">y-coordinate of the baseline relatively to the bottom-most text point</param>
      [DllImport(OpencvCoreLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
      public static extern void cvGetTextSize(
         [MarshalAs(CvInvoke.StringMarshalType)] 
         String textString, 
         ref MCvFont font, 
         ref Size textSize, 
         ref int baseline);*/
      #endregion

      /*
      /// <summary>
      /// Copies the entire sequence or subsequence to the specified buffer and returns the pointer to the buffer
      /// </summary>
      /// <param name="seq">Sequence</param>
      /// <param name="elements">Pointer to the destination array that must be large enough. It should be a pointer to data, not a matrix header</param>
      /// <param name="slice">The sequence part to copy to the array</param>
      /// <returns>the pointer to the buffer</returns>
#if ANDROID
      public static IntPtr cvCvtSeqToArray(IntPtr seq, IntPtr elements, MCvSlice slice)
      {
         return cvCvtSeqToArray(seq, elements, slice.start_index, slice.end_index);
      }
      
      [DllImport(OpencvCoreLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
      private static extern IntPtr cvCvtSeqToArray(IntPtr seq, IntPtr elements, int startIndex, int endIndex);
#else
      [DllImport(OpencvCoreLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
      public static extern IntPtr cvCvtSeqToArray(IntPtr seq, IntPtr elements, MCvSlice slice);
#endif

      /// <summary>
      /// Initializes sequence header for array. The sequence header as well as the sequence block are allocated by the user (for example, on stack). No data is copied by the function. The resultant sequence will consists of a single block and have IntPtr.Zero storage pointer, thus, it is possible to read its elements, but the attempts to add elements to the sequence will raise an error in most cases
      /// </summary>
      /// <param name="seqType">Type of the created sequence</param>
      /// <param name="headerSize">Size of the header of the sequence. Parameter sequence must point to the structure of that size or greater size.</param>
      /// <param name="elemSize">Size of the sequence element</param>
      /// <param name="elements">Elements that will form a sequence</param>
      /// <param name="total">Total number of elements in the sequence. The number of array elements must be equal to the value of this parameter</param>
      /// <param name="seq">Pointer to the local variable that is used as the sequence header. </param>
      /// <param name="block">Pointer to the local variable that is the header of the single sequence block. </param>
      /// <returns>Pointer to the local variable that is used as the sequence header</returns>
      [DllImport(OpencvCoreLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
      public static extern IntPtr cvMakeSeqHeaderForArray(
         int seqType,
         int headerSize,
         int elemSize,
         IntPtr elements,
         int total,
         IntPtr seq,
         IntPtr block);
      */
      internal static void MinMax(IImage arr, out double[] minValues, out double[] maxValues, out Point[] minLocations, out Point[] maxLocations)
      {
         int numberOfChannels = arr.NumberOfChannels;
         minValues = new double[numberOfChannels];
         maxValues = new double[numberOfChannels];
         minLocations = new Point[numberOfChannels];
         maxLocations = new Point[numberOfChannels];

         double minVal = 0, maxVal = 0;
         Point minLoc = new Point(), maxLoc = new Point();
         //int[] minIdx = new int[2], maxIdx = new int[2];
         if (numberOfChannels == 1)
         {
            CvInvoke.MinMaxLoc(arr, ref minVal, ref maxVal, ref minLoc, ref maxLoc);
            minValues[0] = minVal; maxValues[0] = maxVal;
            //minLoc.X = minIdx[1]; minLoc.Y = minIdx[0];
            //maxLoc.X = maxIdx[1]; maxLoc.Y = maxIdx[0];
            minLocations[0] = minLoc; maxLocations[0] = maxLoc;

         }
         else
         {
            IImage[] channels = arr.Split();
            try
            {
               for (int i = 0; i < channels.Length; i++)
               {
                  CvInvoke.MinMaxLoc(channels[i], ref minVal, ref maxVal, ref minLoc, ref maxLoc, null);
                  minValues[i] = minVal; maxValues[i] = maxVal;
                  minLocations[i] = minLoc; maxLocations[i] = maxLoc;
               }
            }
            finally
            {
               for (int i = 0; i < channels.Length; i++)
                  channels[i].Dispose();
            }
         }
      }
开发者ID:Delaley,项目名称:emgucv,代码行数:98,代码来源:CvInvokeCore.cs


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