Beispiel #1
0
        private void Count_timer_Tick(object sender, EventArgs e)
        {
            Countbox.Visible = true;
            Countbox.Image   = timePhotos[c_flag];
            c_flag++;

            if (c_flag > 3)
            {
                face_image = camera.QueryFrame();
                faces      =
                    gray.DetectHaarCascade(haar, 1.2, 10,
                                           HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                           new Size(25, 25))[0];

                Count_timer.Stop();

                Camera_timer.Start();
            }
        }
Beispiel #2
0
        private void face_detect()
        {
            gray = face_image.Convert <Gray, byte>();//將camera輸出影像轉為灰階(EmguCV 語法)

            //人臉抓取語法
            faces =
                gray.DetectHaarCascade(haar, 1.2, 10,
                                       HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                       new Size(25, 25))[0];


            Image Input = face_image.ToBitmap();//轉檔camera輸出影像為Bitmap

            //判斷人臉抓取是否為空
            if (faces.Length > 0)
            {
                if (c_flag == 0)
                {
                    Camera_timer.Stop(); //抓取到人臉後camera_timer停止

                    Count_timer.Start(); //計數圖片顯示
                }
                else
                {
                    //Array.Clear(pic, 0, pic.Length);
                    Countbox.Image = timePhotos[c_flag];
                    c_flag         = 0;
                    //Array.Clear(pic, 0, pic.Length);
                    Camera_timer.Stop();        //抓取到人臉後camera_timer停止

                    MCvAvgComp face = faces[0]; //宣告取得的人臉為face
                    //face_image.Draw(face.rect, new Bgr(Color.Red), 3);//將camera輸出影像對應抓取到的人臉,標記紅框

                    //將取得的人臉分割出來並另存為Bitmap
                    ExtractedFace = new Bitmap(face.rect.Width, face.rect.Height);
                    FaceCanvas    = Graphics.FromImage(ExtractedFace);
                    FaceCanvas.DrawImage(Input, 0, 0, face.rect, GraphicsUnit.Pixel);
                    ExtractedFace.RotateFlip(RotateFlipType.Rotate270FlipNone); //旋轉影像

                    pictureBoxCenter.Visible = true;                            //顯示大圖影像

                    pictureBoxCenter.Image    = ExtractedFace;                  //將分割的人臉載入當前的picturebox中
                    pictureBoxCenter.SizeMode = PictureBoxSizeMode.Zoom;

                    Invalidate();//清空box,重新繪製圖片

                    //半透明處理
                    matrix = new ColorMatrix(nArray);
                    attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                    Image    srcImage    = (Image)ExtractedFace;
                    Bitmap   resultImage = new Bitmap(srcImage.Width, srcImage.Height);
                    Graphics g           = Graphics.FromImage(resultImage);
                    g.DrawImage(srcImage, new Rectangle(0, 0, srcImage.Width, srcImage.Height), 0, 0, srcImage.Width, srcImage.Height, GraphicsUnit.Pixel, attributes);
                    ExtFaces = resultImage;

                    in_taiwan();

                    //分割動畫距離格數
                    vx = (pictureBoxCenter.Location.X - pic[faceNo].Location.X) / fps;
                    vy = (pictureBoxCenter.Location.Y - pic[faceNo].Location.Y) / fps;

                    picout();

                    faceNo = (faceNo + 1) % (cnt_x * cnt_y); //faceNO++,限制圖片載量(台灣外部)
                    faces  = null;                           //抓取一次人臉,清空一次,釋放記憶體

                    Countbox.Visible = false;
                }
            }

            //攝影機影像顯示
            pictureBoxCamera.Image    = face_image.ToBitmap();
            pictureBoxCamera.SizeMode = PictureBoxSizeMode.Zoom;
        }