Exemple #1
0
        public void personRecognize(long[] IDs, FSDK.TFacePosition facePosition, int left, int top, int w, int i, int tracker, Image frameImage)
        {
            String   name;
            Graphics gr  = Graphics.FromImage(frameImage);
            int      res = FSDK.GetAllNames(tracker, IDs[i], out name, 65536); // maximum of 65536 characters

            if (FSDK.FSDKE_OK == res && name.Length > 0)
            { // draw name
                StringFormat format = new StringFormat();
                format.Alignment = StringAlignment.Center;

                gr.DrawString(name, new Font("Arial", 16),
                              new SolidBrush(Color.LightGreen),
                              facePosition.xc, top + w + 5, format);
            }
            Pen pen = Pens.LightGreen;

            if (mouseX >= left && mouseX <= left + w && mouseY >= top && mouseY <= top + w)
            {
                pen = Pens.Blue;

                if (ProgramState.psRemember == programState)
                {
                    if (FSDK.FSDKE_OK == FSDK.LockID(tracker, IDs[i]))
                    {
                        Console.WriteLine(mouseY + "Mouse Move2" + mouseX);
                        // get the user name
                        InputName inputName = new InputName();
                        if (DialogResult.OK == inputName.ShowDialog())
                        {
                            Console.WriteLine(mouseY + "Mouse Move3" + mouseX);
                            userName = inputName.userName;
                            if (userName == null || userName.Length <= 0)
                            {
                                String s = "";
                                FSDK.SetName(tracker, IDs[i], "");
                                FSDK.PurgeID(tracker, IDs[i]);
                            }
                            else
                            {
                                FSDK.SetName(tracker, IDs[i], userName);
                            }
                            FSDK.UnlockID(tracker, IDs[i]);
                        }
                    }
                }
                gr.DrawRectangle(pen, left, top, w, w);
            }
            programState      = ProgramState.psRecognize;
            pictureBox1.Image = frameImage;
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.button1.Hide();
            this.panel2.Show();
            this.pictureBox1.Show();
            this.webBrowser1.Show();



            int cameraHandle = 0;

            int r = FSDKCam.OpenVideoCamera(ref cameraName, ref cameraHandle);

            if (r != FSDK.FSDKE_OK)
            {
                MessageBox.Show("Error opening the first camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            int tracker = 0;                                                                     // creating a Tracker

            if (FSDK.FSDKE_OK != FSDK.LoadTrackerMemoryFromFile(ref tracker, TrackerMemoryFile)) // try to load saved tracker state
            {
                FSDK.CreateTracker(ref tracker);                                                 // if could not be loaded, create a new tracker
            }
            int err = 0;                                                                         // set realtime face detection parameters

            FSDK.SetTrackerMultipleParameters(tracker, "HandleArbitraryRotations=false; DetermineFaceRotationAngle=false; InternalResizeWidth=100; FaceDetectionThreshold=5;", ref err);

            while (!needClose)
            {
                Int32 imageHandle = 0;
                if (FSDK.FSDKE_OK != FSDKCam.GrabFrame(cameraHandle, ref imageHandle)) // grab the current frame from the camera
                {
                    Application.DoEvents();
                    continue;
                }
                FSDK.CImage image = new FSDK.CImage(imageHandle);

                long[] IDs;
                long   faceCount = 0;
                FSDK.FeedFrame(tracker, 0, image.ImageHandle, ref faceCount, out IDs, sizeof(long) * 256); // maximum of 256 faces detected
                Array.Resize(ref IDs, (int)faceCount);

                // make UI controls accessible (to find if the user clicked on a face)
                Application.DoEvents();

                Image    frameImage = image.ToCLRImage();
                Graphics gr         = Graphics.FromImage(frameImage);

                for (int i = 0; i < IDs.Length; ++i)
                {
                    FSDK.TFacePosition facePosition = new FSDK.TFacePosition();
                    FSDK.GetTrackerFacePosition(tracker, 0, IDs[i], ref facePosition);

                    int left = facePosition.xc - (int)(facePosition.w * 0.6);
                    int top  = facePosition.yc - (int)(facePosition.w * 0.5);
                    int w    = (int)(facePosition.w * 1.2);

                    String name    = null;
                    String address = "sunrinwiki.layer7.kr/index.php/";
                    String new_address;

                    int res = FSDK.GetAllNames(tracker, IDs[i], out name, 65536); // maximum of 65536 characters

                    if (FSDK.FSDKE_OK == res && name.Length > 0)
                    { // draw name
                        StringFormat format = new StringFormat();
                        format.Alignment = StringAlignment.Center;

                        gr.DrawString(name, new System.Drawing.Font("Arial", 16),

                                      new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen),
                                      facePosition.xc, top + w + 5, format);

                        if ((saved_name != name) && (name != null))
                        {
                            new_address = address + name;
                            webBrowser1.Navigate(new_address);
                            saved_name = name;
                        }
                    }

                    Pen pen = Pens.LightGreen;
                    if (mouseX >= left && mouseX <= left + w && mouseY >= top && mouseY <= top + w)
                    {
                        pen = Pens.Blue;
                        if (ProgramState.psRemember == programState)
                        {
                            if (FSDK.FSDKE_OK == FSDK.LockID(tracker, IDs[i]))
                            {
                                // get the user name
                                InputName inputName = new InputName();
                                if (DialogResult.OK == inputName.ShowDialog())
                                {
                                    userName = inputName.userName;
                                    if (userName == null || userName.Length <= 0)
                                    {
                                        String s = "";
                                        FSDK.SetName(tracker, IDs[i], "");
                                        FSDK.PurgeID(tracker, IDs[i]);
                                    }
                                    else
                                    {
                                        FSDK.SetName(tracker, IDs[i], userName);
                                    }
                                    FSDK.UnlockID(tracker, IDs[i]);
                                }
                            }
                        }
                    }
                    gr.DrawRectangle(pen, left, top, w, w);
                }
                programState = ProgramState.psRecognize;

                // display current frame
                pictureBox1.Image = frameImage;
                GC.Collect(); // collect the garbage after the deletion
            }
            FSDK.SaveTrackerMemoryToFile(tracker, TrackerMemoryFile);
            FSDK.FreeTracker(tracker);

            FSDKCam.CloseVideoCamera(cameraHandle);
            FSDKCam.FinalizeCapturing();
        }
Exemple #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.button1.Enabled = false;
            int cameraHandle = 0;

            int r = FSDKCam.OpenVideoCamera(ref cameraName, ref cameraHandle);

            if (r != FSDK.FSDKE_OK)
            {
                MessageBox.Show("Error opening the first camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            int tracker = 0;                                                                     // creating a Tracker

            if (FSDK.FSDKE_OK != FSDK.LoadTrackerMemoryFromFile(ref tracker, TrackerMemoryFile)) // try to load saved tracker state
            {
                FSDK.CreateTracker(ref tracker);                                                 // if could not be loaded, create a new tracker
            }
            int err = 0;                                                                         // set realtime face detection parameters

            FSDK.SetTrackerMultipleParameters(tracker, "HandleArbitraryRotations=false; DetermineFaceRotationAngle=false; InternalResizeWidth=100; FaceDetectionThreshold=5;", ref err);

            while (!needClose)
            {
                Int32 imageHandle = 0;
                if (FSDK.FSDKE_OK != FSDKCam.GrabFrame(cameraHandle, ref imageHandle)) // grab the current frame from the camera
                {
                    Application.DoEvents();
                    continue;
                }
                FSDK.CImage image = new FSDK.CImage(imageHandle);

                long[] IDs;
                long   faceCount = 0;
                FSDK.FeedFrame(tracker, 0, image.ImageHandle, ref faceCount, out IDs, sizeof(long) * 256); // maximum of 256 faces detected
                Array.Resize(ref IDs, (int)faceCount);

                // make UI controls accessible (to find if the user clicked on a face)
                Application.DoEvents();

                Image    frameImage = image.ToCLRImage();
                Graphics gr         = Graphics.FromImage(frameImage);

                for (int i = 0; i < IDs.Length; ++i)
                {
                    FSDK.TFacePosition facePosition = new FSDK.TFacePosition();
                    FSDK.GetTrackerFacePosition(tracker, 0, IDs[i], ref facePosition);

                    int left = facePosition.xc - (int)(facePosition.w * 0.6);
                    int top  = facePosition.yc - (int)(facePosition.w * 0.5);
                    int w    = (int)(facePosition.w * 1.2);

                    String name;
                    int    res = FSDK.GetAllNames(tracker, IDs[i], out name, 65536);          // maximum of 65536 characters

                    if (FSDK.FSDKE_OK == res && name.Length > 0)
                    { // draw name
                        StringFormat format = new StringFormat();
                        format.Alignment = StringAlignment.Center;

                        gr.DrawString("", new System.Drawing.Font("Arial", 16),
                                      new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen),
                                      facePosition.xc, top + w + 5, format);
                        label3.Text = name;
                    }
                    else
                    {
                        label3.Text = "UnKnow FACE";
                    }



                    Pen pen = Pens.LightGreen;
                    if (mouseX >= left && mouseX <= left + w && mouseY >= top && mouseY <= top + w)
                    {
                        pen = Pens.Blue;
                        if (ProgramState.psRemember == programState)
                        {
                            if (FSDK.FSDKE_OK == FSDK.LockID(tracker, IDs[i]))
                            {
                                // get the user name
                                InputName inputName = new InputName();
                                inputName.bmp = new Bitmap(pictureBox1.Image);


                                if (DialogResult.OK == inputName.ShowDialog())
                                {
                                    userName = inputName.userName;
                                    if (userName == null || userName.Length <= 0)
                                    {
                                        String s = "";
                                        FSDK.SetName(tracker, IDs[i], "");
                                        FSDK.PurgeID(tracker, IDs[i]);
                                    }
                                    else
                                    {
                                        FSDK.SetName(tracker, IDs[i], userName);
                                    }
                                    FSDK.UnlockID(tracker, IDs[i]);
                                }
                            }
                        }
                    }
                    gr.DrawRectangle(pen, left, top, w, w);
                }
                programState = ProgramState.psRecognize;

                // display current frame
                pictureBox1.Image = frameImage;
                GC.Collect(); // collect the garbage after the deletion
                FSDK.SaveTrackerMemoryToFile(tracker, TrackerMemoryFile);
            }
            FSDK.SaveTrackerMemoryToFile(tracker, TrackerMemoryFile);

            if (label3.Text == label4.Text)
            {
                //con.Open();
                //cmd = new SqlCommand("select * from facetb where NAme='" + label3.Text + "'", con);
                //SqlDataReader dr = cmd.ExecuteReader();
                //if (dr.Read())
                //{
                //}
                //else
                //{
                //    dr.Close();


                //    FileStream fs = new FileStream(TrackerMemoryFile, FileMode.Open, FileAccess.Read);
                //    BinaryReader br = new BinaryReader(fs);
                //    Byte[] bytes = br.ReadBytes((Int32)fs.Length);
                //    br.Close();
                //    fs.Close();

                //    cmd = new SqlCommand("insert into facetb values('" + label3.Text + "',@Image)", con);
                //    conv_photo();
                //    cmd.Parameters.AddWithValue("@Image", bytes);
                //    // con.Open();
                //    cmd.ExecuteNonQuery();
                //    ///con.Close();
                //}
                //con.Close();
            }


            FSDK.FreeTracker(tracker);

            FSDKCam.CloseVideoCamera(cameraHandle);
            FSDKCam.FinalizeCapturing();
        }
Exemple #4
0
        private void visorCamaraLuxand_Shown(object sender, EventArgs e)
        {
            #region liveRecognition
            int cameraHandle = 0;
            int r            = FSDKCam.OpenVideoCamera(ref cameraName, ref cameraHandle);
            if (r != FSDK.FSDKE_OK)
            {
                MessageBox.Show("Error opening the first camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
            int tracker = 0;                                                                     // creating a Tracker
            if (FSDK.FSDKE_OK != FSDK.LoadTrackerMemoryFromFile(ref tracker, TrackerMemoryFile)) // try to load saved tracker state
            {
                FSDK.CreateTracker(ref tracker);                                                 // if could not be loaded, create a new tracker
            }
            int err = 0;                                                                         // set realtime face detection parameters
            FSDK.SetTrackerMultipleParameters(tracker, "HandleArbitraryRotations=false; DetermineFaceRotationAngle=false; InternalResizeWidth=100; FaceDetectionThreshold=5;", ref err);
            while (!needClose)
            {
                Int32 imageHandle = 0;
                if (FSDK.FSDKE_OK != FSDKCam.GrabFrame(cameraHandle, ref imageHandle)) // grab the current frame from the camera
                {
                    Application.DoEvents();
                    continue;
                }
                FSDK.CImage image = new FSDK.CImage(imageHandle);
                long[]      IDs;
                long        faceCount = 0;
                FSDK.FeedFrame(tracker, 0, image.ImageHandle, ref faceCount, out IDs, sizeof(long) * 256); // maximum of 256 faces detected
                Array.Resize(ref IDs, (int)faceCount);
                // make UI controls accessible (to find if the user clicked on a face)
                Application.DoEvents();
                Image    frameImage = image.ToCLRImage();
                Graphics gr         = Graphics.FromImage(frameImage);
                for (int i = 0; i < IDs.Length; ++i)
                {
                    FSDK.TFacePosition facePosition = new FSDK.TFacePosition();
                    FSDK.GetTrackerFacePosition(tracker, 0, IDs[i], ref facePosition);
                    int    left = facePosition.xc - (int)(facePosition.w * 0.6);
                    int    top  = facePosition.yc - (int)(facePosition.w * 0.5);
                    int    w    = (int)(facePosition.w * 1.2);
                    String name = this.nombre + " Edad: " + this.edad + " Puesto: " + this.puesto;
                    //String name;
                    //String nombre;
                    int res = FSDK.GetAllNames(tracker, IDs[i], out nombre, 65536); // maximum of 65536 characters
                    if (FSDK.FSDKE_OK == res && name.Length > 0)
                    {                                                               // draw name
                        StringFormat format = new StringFormat();
                        format.Alignment = StringAlignment.Center;
                        gr.DrawString(name, new System.Drawing.Font("Arial", 16),
                                      new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen),
                                      facePosition.xc, top + w + 5, format);
                    }
                    Pen pen = Pens.LightGreen;
                    if (mouseX >= left && mouseX <= left + w && mouseY >= top && mouseY <= top + w)
                    {
                        pen = Pens.Blue;
                        if (ProgramState.psRemember == programState)
                        {
                            if (FSDK.FSDKE_OK == FSDK.LockID(tracker, IDs[i]))
                            {
                                // get the user name
                                InputName inputName = new InputName();
                                if (DialogResult.OK == inputName.ShowDialog())
                                {
                                    userName = inputName.userName;

                                    /**********************************
                                    *  extraemos data del form input name
                                    **********************************/
                                    string nombre    = inputName.userName;
                                    string a_paterno = inputName.userPaterno;
                                    string a_materno = inputName.userMaterno;
                                    string genero    = inputName.userGenero;
                                    string edad      = inputName.userEdad;
                                    string rol       = inputName.userRol;
                                    string puesto    = inputName.userPuesto;
                                    string correo    = inputName.userCorreo;

                                    /*******************************************
                                    *  guardamos los datos en la tabla de usuarios
                                    *******************************************/
                                    fnRegistraUsuarioBD(nombre, a_paterno, a_materno, genero, edad, rol, puesto, correo);
                                    if (userName == null || userName.Length <= 0)
                                    {
                                        String s = "";
                                        FSDK.SetName(tracker, IDs[i], "");
                                        FSDK.PurgeID(tracker, IDs[i]);
                                    }
                                    else
                                    {
                                        FSDK.SetName(tracker, IDs[i], userName);
                                    }
                                    FSDK.UnlockID(tracker, IDs[i]);
                                }
                            }
                        }
                    }
                    gr.DrawRectangle(pen, left, top, w, w);
                }
                programState = ProgramState.psRecognize;
                // display current frame
                pictureBox1.Image = frameImage;
                GC.Collect(); // collect the garbage after the de
            }
            FSDK.SaveTrackerMemoryToFile(tracker, TrackerMemoryFile);
            FSDK.FreeTracker(tracker);
            FSDKCam.CloseVideoCamera(cameraHandle);
            FSDKCam.FinalizeCapturing();
            #endregion
        }
Exemple #5
0
        private void Capturar()
        {
            this.button1.Enabled = false;
            int cameraHandle = 0;

            int r = FSDKCam.OpenVideoCamera(ref cameraName, ref cameraHandle);

            Debug.WriteLine("cameraName: " + cameraName);
            Debug.WriteLine("cameraHandle: " + cameraHandle);
            Debug.WriteLine("r: " + r);


            if (r != FSDK.FSDKE_OK)
            {
                MessageBox.Show("Error opening the first camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            int tracker = 0;

            // creating a Tracker
            if (FSDK.FSDKE_OK != FSDK.LoadTrackerMemoryFromFile(ref tracker, TrackerMemoryFile)) // try to load saved tracker state
            {
                FSDK.CreateTracker(ref tracker);                                                 // if could not be loaded, create a new tracker
            }
            int err = 0;                                                                         // set realtime face detection parameters

            FSDK.SetTrackerMultipleParameters(tracker, "HandleArbitraryRotations=false; DetermineFaceRotationAngle=false; InternalResizeWidth=100; FaceDetectionThreshold=5;", ref err);

            while (!needClose)
            {
                Int32 imageHandle = 0;
                if (FSDK.FSDKE_OK != FSDKCam.GrabFrame(cameraHandle, ref imageHandle)) // grab the current frame from the camera
                {
                    Application.DoEvents();
                    continue;
                }

                FSDK.CImage image = new FSDK.CImage(imageHandle);


                long[] IDs;
                long   faceCount = 0;
                FSDK.FeedFrame(tracker, 0, image.ImageHandle, ref faceCount, out IDs, sizeof(long) * 256); // maximum of 256 faces detected
                Array.Resize(ref IDs, (int)faceCount);

                // make UI controls accessible (to find if the user clicked on a face)
                Application.DoEvents();

                Image    frameImage = image.ToCLRImage();
                Graphics gr         = Graphics.FromImage(frameImage);
                //pictureBox2.Image = frameImage;

                for (int i = 0; i < IDs.Length; ++i)
                {
                    //Debug.WriteLine("Cant: " + IDs.Length);
                    FSDK.TFacePosition facePosition = new FSDK.TFacePosition();
                    FSDK.GetTrackerFacePosition(tracker, 0, IDs[i], ref facePosition);

                    int left = facePosition.xc - (int)(facePosition.w * 0.6);
                    int top  = facePosition.yc - (int)(facePosition.w * 0.5);
                    int w    = (int)(facePosition.w * 1.2);

                    String name;
                    int    res = FSDK.GetAllNames(tracker, IDs[i], out name, 65536); // maximum of 65536 characters

                    //DETECCION

                    if (FSDK.FSDKE_OK == res)
                    { // draw name
                        if (name.Length <= 0)
                        {
                            name    = "Desconocido";
                            usuario = new Usuario();
                        }
                        else
                        {
                            usuario = BuscarUsuario(name);
                            name    = usuario.Nombre + " " + usuario.Apellido;
                        }

                        StringFormat format = new StringFormat();
                        format.Alignment = StringAlignment.Center;

                        gr.DrawString(name, new Font("Century Gothic", 16, FontStyle.Bold),
                                      new SolidBrush(Color.LightGreen),
                                      facePosition.xc, top + w + 5, format);
                    }


                    //REGISTRO
                    Pen pen = Pens.DarkGreen;
                    if (mouseX >= left && mouseX <= left + w && mouseY >= top && mouseY <= top + w)
                    {
                        pen = Pens.DarkBlue;
                        if (ProgramState.psRemember == programState)
                        {
                            if (FSDK.FSDKE_OK == FSDK.LockID(tracker, IDs[i]))
                            {
                                // get the user name
                                ////CamposBloqueados(false);
                                //Debug.WriteLine("desbloqueo campos");
                                //Debug.WriteLine("estaGuar: " + estaGuardado);

                                inputDatos inputDatos   = new inputDatos();
                                bool       nuevoUsuario = false;

                                if (usuario.Id <= 0)
                                {
                                    Debug.WriteLine("Nuevo usuario");
                                    nuevoUsuario = true;
                                }
                                else
                                {
                                    Debug.WriteLine("Nombre: " + usuario.Nombre + "\tCedula: " + usuario.Cedula);
                                    inputDatos.setDatos(usuario);
                                    nuevoUsuario = false;
                                }



                                if (DialogResult.OK == inputDatos.ShowDialog())
                                //if (estaGuardado)
                                {
                                    Debug.WriteLine("entró if");
                                    //userName = textBox_cedula.Text;
                                    usuario = inputDatos.usuario;

                                    //userName = inputName.userName;
                                    userName = usuario.Cedula;

                                    if (userName == null || userName.Length <= 0)
                                    {
                                        String s = "";
                                        FSDK.SetName(tracker, IDs[i], "");
                                        FSDK.PurgeID(tracker, IDs[i]);
                                    }
                                    else
                                    {
                                        FSDK.SetName(tracker, IDs[i], userName);
                                    }
                                    FSDK.UnlockID(tracker, IDs[i]);

                                    usuario.Imagen = frameImage;

                                    if (nuevoUsuario)
                                    {
                                        usuario = UsuarioDatos.insertUsuario(usuario);
                                        MessageBox.Show("Registro guardado correctamente");
                                    }
                                    else
                                    {
                                        Debug.WriteLine("id: " + usuario.Id);
                                        Debug.WriteLine("ced: " + usuario.Cedula);
                                        usuario = UsuarioDatos.updateUsuario(usuario);
                                        MessageBox.Show("Registro actualizado correctamente");
                                    }

                                    CargarUsuarioDB();

                                    //CamposBloqueados(true);
                                }
                                estaGuardado = false;
                            }
                        }
                    }
                    gr.DrawRectangle(pen, left, top, w, w);
                }
                programState = ProgramState.psRecognize;

                // display current frame
                pictureBox1.Image = frameImage;
                GC.Collect(); // collect the garbage after the deletion
            }

            FSDK.SaveTrackerMemoryToFile(tracker, TrackerMemoryFile);
            FSDK.FreeTracker(tracker);


            FSDKCam.CloseVideoCamera(cameraHandle);
            FSDKCam.FinalizeCapturing();
        }