コード例 #1
0
 public double GetPercentageOfSkinInImage(string filePath, string debugImageFilePath = null)
 {
     using (IplImage imgSrc = new IplImage(filePath))
     {
         using (CvMemStorage storage = new CvMemStorage())
         {
             CvRect rect;
             using (IplImage imgGray = new IplImage(filePath, LoadMode.GrayScale))
             {
                 rect = FindBorder(imgGray);
             }
             if (rect.Width < imgSrc.Width * 0.10 || rect.Height < imgSrc.Height * 0.10)
             {
                 rect = new CvRect(0, 0, imgSrc.Width, imgSrc.Height);
             }
             using (var subImg = imgSrc.GetSubImage(rect))
             {
                 using (IplImage imgHueMask = new IplImage(subImg.Size, BitDepth.U8, 1))
                 {
                     CvAdaptiveSkinDetector detector = new CvAdaptiveSkinDetector(1, MorphingMethod.ErodeDilate);
                     detector.Process(subImg, imgHueMask);
                     int count   = CountSkinPoints(imgHueMask, CvColor.White);
                     var percent = ((double)count / (double)(subImg.Width * subImg.Height) * 100);
                     if (debugImageFilePath != null)
                     {
                         imgHueMask.SaveImage(debugImageFilePath);
                     }
                     return(percent);
                 }
             }
         }
     }
 }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        public SkinDetector()
        {
            using (IplImage imgSrc = new IplImage(Const.ImageBalloon, LoadMode.Color))
                using (IplImage imgHueMask = new IplImage(imgSrc.Size, BitDepth.U8, 1))
                    using (IplImage imgDst = imgSrc.Clone())
                    {
                        CvAdaptiveSkinDetector detector = new CvAdaptiveSkinDetector(1, MorphingMethod.None);
                        detector.Process(imgSrc, imgHueMask);
                        DisplaySkinPoints(imgHueMask, imgDst, CvColor.Green);

                        using (CvWindow windowSrc = new CvWindow("src", imgSrc))
                            using (CvWindow windowDst = new CvWindow("skin", imgDst))
                            {
                                Cv.WaitKey(0);
                            }
                    }
        }