Example #1
0
        private void FaceDetect_Click(object sender, EventArgs e)
        {
            if (!sw.IsRunning)
            {
                sw.Reset();
                sw.Start();
            }
            Process.Image = Image.FromFile(filepath, true);
            if (bvis == false)
            {
                bvis = true;
            }
            else
            {
                bvis = false;
            }
            GridOn.GridPaint(bvis, (Bitmap)Process.Image);//绘制网格线
            label3.Text = "网络线划分";
            try {
                Bitmap gray_img  = Knowledge.ToGray(originalimg);    //将原图转化为灰度图
                Bitmap BW        = Knowledge.Thresholding(gray_img); //利用大津法进行二值化处理
                Bitmap detectimg = Knowledge.FaceDetection(BW);      //最后利用算法进行检测
                AForge.Imaging.BlobCounter blobCounter = new AForge.Imaging.BlobCounter(detectimg);
                Rectangle[] rects       = blobCounter.GetObjectsRectangles();
                Rectangle[] outputrects = new Rectangle[rects.Count()];
                ////object count
                int            minx = 100; 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 = (gray_img.Width * gray_img.Height) / 2;
                    if (p > minx && (double)bl < 1.8 && (double)bl > 0.8 && p < maxx)
                    {
                        test.Add(bl);
                        outputrects[tmp++] = rects[c];
                    }
                }
                RectanglesMarker marker = new RectanglesMarker(outputrects, Color.Red);
                this.Detected.Image = marker.Apply((Bitmap)Image.FromFile(filepath, true));
                label4.Text         = "检测结果";
                ShowMsg("检测结束!");
            }
            catch (ArgumentException)
            {
                MessageBox.Show("Invalid usage!");
            }

            if (sw.IsRunning)
            {
                sw.Stop();

                string str = sw.Elapsed.ToString();
                timeElpse.Text = string.Empty;
                timeElpse.Text = "运行时间:" + str;
            }
        }
        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;
        }