0

I am developing Teacher Attendance Management System using face recognition technique in C# using Emgu CV, first of all teachers' faces will be trained (registered) then their attendance will be marked using Face Recognition technique. But whenever I try to open camera for face recognition it freezes after some seconds and does not respond. First I thought it is because of continuously attempt oof insertion of attendance into database (primary key in Attendance table is name + date so no duplicate attendance will be marked of a teacher) but when I commented out all code related to database it freezes too. Anyone knows how can I overcome this issue ? Here is my FrameProceedure methode it will run when my form will be loaded as follows Application.Idle += new EventHandler(FrameProcedure);

FrameProceedure Method :

private void FrameProcedure(object sender, EventArgs e)
        {
            try
            {
                // Thread.Sleep(1000);
                Users.Add("");
                Frame = camera.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                grayFace = Frame.Convert<Gray, Byte>();
                MCvAvgComp[][] facesDetectedNow = grayFace.DetectHaarCascade(faceDetected, 1.2, 10, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20));
                foreach (MCvAvgComp f in facesDetectedNow[0])
                {
                    result = Frame.Copy(f.rect).Convert<Gray, Byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                    Frame.Draw(f.rect, new Bgr(Color.Green), 3);
                    if (trainingImages.ToArray().Length != 0)
                    {

                        MCvTermCriteria termCriterias = new MCvTermCriteria(Count, 0.001);
                        EigenObjectRecognizer recognizer = new EigenObjectRecognizer(trainingImages.ToArray(), labels.ToArray(), 1500, ref termCriterias);
                        name = recognizer.Recognize(result);
                        Frame.Draw(name, ref font, new Point(f.rect.X - 2, f.rect.Y - 2), new Bgr(Color.Red));

                        if (name != null)
                        {
                            try
                            {

                                MySqlConnection databaseConnection = new MySqlConnection(connString);
                                int id = 0;
                                MySqlCommand cmd;

                                //Check if the face recognized exists in the Registration Table then retrieve its ID to store in Attendance Table

                                cmd = new MySqlCommand("SELECT id FROM mydb.registration WHERE name = @n", databaseConnection);
                                cmd.Parameters.Add("@n", MySqlDbType.Text);
                                cmd.Parameters["@n"].Value = name;
                                MySqlDataReader myReader;

                                databaseConnection.Open();
                                myReader = cmd.ExecuteReader();
                                while (myReader.Read())
                                {
                                    id = (int)(myReader["id"]);

                                }
                                databaseConnection.Close();
                                //If ID is retrieved successfully (means face exists in Registration Table)  
                                if (id != 0)
                                {
                                    MySqlConnection dbconn = new MySqlConnection(connString);
                                    dbconn.Open();
                                    MySqlCommand comm = dbconn.CreateCommand();
                                    comm.CommandText = "UPDATE mydb.attendance SET att_status = @status WHERE id = '" + id + "' AND att_status = '' AND name = '" + name + "' AND att_status = ''";
                                    comm.Parameters.Add("?status", MySqlDbType.VarChar).Value = "P";
                                    comm.ExecuteNonQuery();
                                    dbconn.Close();
                                   Frame.Draw(name + " Marked Present", ref font, new Point(f.rect.X - 2, f.rect.Y - 2), new Bgr(Color.Yellow));
                                    SystemSounds.Beep.Play();
                                }
                            }
                            catch (Exception ee)
                            {
                                 ```
                            }
                        }                 
                        Users.Add("");
                    }
                    imageBox1.Image = Frame;
                    names = "";
                    Users.Clear();
                }
            }
            catch (Exception ee)
            {
                //  MessageBox.Show(ee.ToString());
            }
        }

Bilal Hassan
  • 37
  • 1
  • 6
  • does it return any exception? – Maytham Fahmi Sep 18 '19 at 20:03
  • This error occurs sometimes in Design and design disappears _Could not find type 'Emgu.CV.UI.ImageBox'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU._ – Bilal Hassan Sep 19 '19 at 19:12
  • I will try to look at it, if I can find thing I will get back. – Maytham Fahmi Sep 19 '19 at 20:14
  • ok i'll wait sir :) – Bilal Hassan Sep 19 '19 at 20:20
  • One thing mean while, when you ask question about Emgu.CV make your method show things related to Emgu, the method you have has Sql and and few other stuff. just make tiny and clear. ;) – Maytham Fahmi Sep 19 '19 at 20:22

0 Answers0