OpenCVSharp color image segmentation

OpencvSharp function using the image segmentation InRange RGB colors.

. 1  the using the System;
 2  the using OpenCvSharp;
 . 3  the using OpenCvSharp.Extensions;
 . 4  the using OpenCvSharp.XFeatures2D;
 . 5  the using  static OpenCvSharp.Cv2;
 . 6  namespace Mycv 
 . 7  {
 . 8      public  class cvGO
 . 9      {
 10           ///  <Summary> 
. 11          /// divided color with an area accounting for the size
 12 is          ///  </ Summary> 
13 is          ///  <param name = "srcbmp"> original </ param> 
14          /// <param name = "dstbmp"> Results FIG. </ param> 
15          ///  <param name = "value_Low"> lowest value RGB (0-255) ([0] : R, [1]: G, [2] : B) 3 where an array of RGB values stored with a minimum length of </ param> 
16          ///  <param name = "value_High"> highest value RGB (0-255) ([0] : R, [1]: G, [2]: B) where 3 array storing the highest RGB value of length </ param> 
. 17          public  a float Color_Inrange (Bitmap srcbmp, OUT Bitmap dstbmp, int [] value_Low, int [] value_High)
 18 is          {
 . 19              / / Bitmap turn MAT 
20 is              the using (Mat the src = BitmapConverter.
Tomatoes (srcbmp)) 21              using (Matt dst =new new Mat ())
 22 is              {
 23 is                  // New passed in accordance with two arrays 2 the Scalar 
24                  the Scalar = CVL new new the Scalar (value_Low [ 0 ], value_Low [ . 1 ], value_Low [ 2 ]);
 25                  the Scalar CVH = new new the Scalar (value_High [ 0 ], value_High [ . 1 ], value_High [ 2 ]);
 26 is                  
27                  // this is the color segmentation step 
28                  InRange (the src, CVL, CVH, dst);
 29                  // Inrange when the assignment has been moved to dst, here mat is transferred Bitmap 
30                  dstbmp =dst.ToBitmap ();
 31 is                  // used to obtain CountNonZero area, then return the value is calculated and accounted for 
32                  return (CountNonZero (DST) / (src.Width src.Height * * 1.0f ) * 100 );
 33 is              }
 34          }
 35      }
 36 }

Guess you like

Origin www.cnblogs.com/ybqjymy/p/12170836.html