コード例 #1
0
        private void skindetect_Click(object sender, EventArgs e)
        {
            sw.Reset();
            sw.Start();
            Bitmap img           = (Bitmap)Image.FromFile(filepath, true); //将原图进行导入并进行格式转化
            Bitmap normalizedImg = YCbCr.Lightingconpensate(img);
            Bitmap skin          = YCbCr.SkinDetect1(normalizedImg);       //肤色检测
            Bitmap BWskin        = Knowledge.Thresholding(skin);           //图片二值化
            Bitmap gray_img      = Knowledge.ToGray(img);

            AForge.Imaging.SusanCornersDetector scd = new AForge.Imaging.SusanCornersDetector(); //susan检测子
                                                                                                 //检测人眼部分

            AForge.Imaging.BlobCounter blobCounter = new AForge.Imaging.BlobCounter(BWskin);     //对图片进行检测联通区域
            Rectangle[] rects       = blobCounter.GetObjectsRectangles();
            Rectangle[] outputrects = new Rectangle[rects.Count()];
            ////object count
            int            minx = 150; int tmp = 0;
            int            rectsCount = rects.Count();
            List <decimal> test       = new List <decimal>();

            for (int c = 0; c < rectsCount; c++)
            {
                int     p  = rects[c].Width * rects[c].Height;
                decimal bl = (decimal)rects[c].Height / (decimal)rects[c].Width;

                int maxx = (img.Width * img.Height) / 2;
                if (p > minx && (double)bl < 1.8 && (double)bl > 0.9 && p < maxx)
                {
                    test.Add(bl);
                    outputrects[tmp++] = rects[c];
                }
            }
            RectanglesMarker marker = new RectanglesMarker(outputrects, Color.Red);

            Process2.Image = img;
            Detected.Image = marker.Apply((Bitmap)Image.FromFile(filepath, true));
            sw.Stop();
            string str = sw.Elapsed.ToString();

            timeElpsed.Text = string.Empty;
            timeElpsed.Text = "运行时间:" + str;
        }
コード例 #2
0
        private void normalieddetect_Click(object sender, EventArgs e)
        {
            Bitmap normalizedImg = YCbCr.Lightingconpensate((Bitmap)Image.FromFile(filepath)); //利用图像基准白矫正

            Process1.Image = normalizedImg;                                                    //显示结果1
        }