示例#1
0
        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
            Painel painel = new Painel();

            painel.label3.Text = nivellbl.Text;
            painel.label4.Text = nomelbl.Text;
            painel.Closed     += (s, args) => this.Close();
            painel.Show();
        }
示例#2
0
        void FrameGrabber(object sender, EventArgs e)
        {
            label3.Text = "0";
            //label4.Text = "";
            NamePersons.Add("");


            //Pega o frame para captura
            currentFrame = grabber.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

            //Converte em Grayscale
            gray = currentFrame.Convert <Gray, Byte>();

            //Face Detector
            MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
                face,
                1.2,
                10,
                Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                new Size(20, 20));

            //Ação para cada elemnto detectado
            foreach (MCvAvgComp f in facesDetected[0])
            {
                t      = t + 1;
                result = currentFrame.Copy(f.rect).Convert <Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                //Desenha o quadrado na cara
                currentFrame.Draw(f.rect, new Bgr(Color.Red), 2);


                if (trainingImages.ToArray().Length != 0)
                {
                    //TermCriteria for face recognition with numbers of trained images like maxIteration
                    MCvTermCriteria termCrit = new MCvTermCriteria(ContTrain, 0.001);

                    //Eigen face recognizer
                    EigenObjectRecognizer recognizer = new EigenObjectRecognizer(
                        trainingImages.ToArray(),
                        labels.ToArray(),
                        3000,
                        ref termCrit);

                    name = recognizer.Recognize(result);

                    //Escreve o nome para cada face
                    currentFrame.Draw(name, ref font, new Point(f.rect.X - 2, f.rect.Y - 2), new Bgr(Color.LightGreen));
                }

                NamePersons[t - 1] = name;
                NamePersons.Add("");


                //Seta o numero de faces detectadas
                label3.Text = facesDetected[0].Length.ToString();

                /*
                 *
                 *  //Le a quantidade de pessoas e atribui a variavel pessoas
                 * string Pessoas = facesDetected[0].Length.ToString();
                 * if (Pessoas != "0")
                 * {
                 * Application.Idle -= FrameGrabber;
                 * grabber.Dispose();
                 * this.Hide();
                 * Painel painel = new Painel();
                 * painel.label4.Text = names;
                 * painel.Closed += (s, args) => this.Close();
                 * painel.Show();
                 * }
                 *
                 * //Set the region of interest on the faces
                 *
                 * gray.ROI = f.rect;
                 * MCvAvgComp[][] eyesDetected = gray.DetectHaarCascade(
                 * eye,
                 * 1.1,
                 * 10,
                 * Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                 * new Size(20, 20));
                 * gray.ROI = Rectangle.Empty;
                 *
                 * foreach (MCvAvgComp ey in eyesDetected[0])
                 * {
                 *  Rectangle eyeRect = ey.rect;
                 *  eyeRect.Offset(f.rect.X, f.rect.Y);
                 *  currentFrame.Draw(eyeRect, new Bgr(Color.Blue), 2);
                 * }
                 */
            }
            t = 0;

            //Concatena o nome das pessoas
            for (int nnn = 0; nnn < facesDetected[0].Length; nnn++)
            {
                names = names + NamePersons[nnn];
            }

            //Le a quantidade de pessoas e atribui a variavel pessoas
            string Pessoas = facesDetected[0].Length.ToString();

            if (Pessoas != "0")
            {
                Application.Idle -= FrameGrabber;
                grabber.Dispose();
                this.Hide();
                Painel painel = new Painel();

                //Faz a separação do nome pro nivel
                char[]   Separador  = { '|' };
                string   NomeENivel = names;
                string[] split      = NomeENivel.Split(Separador, StringSplitOptions.None);

                painel.label4.Text = split[0];
                painel.label3.Text = split[1];

                painel.Closed += (s, args) => this.Close();
                painel.Show();
            }
            //Show the faces procesed and recognized
            imageBoxFrameGrabber.Image = currentFrame;
            label4.Text = names;
            names       = "";
            //Clear the list(vector) of names
            NamePersons.Clear();
        }