Error comparing values in "if" construct

116 views Asked by At

I am doing a face recognition project, and I want to compare the x.label returned value with the ID saved to database. I always get an error in if condition comparing the ID with the x.label

  public int Predict(Image<Gray, Byte> testImage)
        {

            Emgu.CV.FaceRecognizer.PredictionResult x;
            if (testImage != null)
            {
                x= fr.Predict(testImage);
                pictureBox1.Image = testImage.ToBitmap();
                //MessageBox.Show(x.Label.ToString()+" "+x.Distance.ToString());

                OleDbCommand D1 = new OleDbCommand("Select [ID] FROM [connect]", DBConnection);
                OleDbDataReader reader = D1.ExecuteReader();
                while (reader.Read())
                {

                   if (Convert.ToInt32(reader["ID"]) == x.Label)
                   {

                       OleDbCommand insert1 = new OleDbCommand("UPDATE OutputReport SET [Attendance]='yes' WHERE [StudentID]='109';", DBConnection);
                       insert1.ExecuteNonQuery();
                        MessageBox.Show(" its working");
                    }
               }
                RefreshDBConnection();


                if (x.Distance < 69)
                    return x.Label;
                else
                    MessageBox.Show("Error!!, The detected Face is neither recognised nor enrolled");
                return -1;
            }

            else

            {

                return -1;
            }

        }
1

There are 1 answers

19
Sachu On BEST ANSWER

If my understanding is correct you need to check x.Label value with ID column value in the database of MS-Access. For that you need to do execute reader and assign the value.

   public int Predict(Image<Gray, Byte> testImage)
        {

            Emgu.CV.FaceRecognizer.PredictionResult x;
            if (testImage != null)
            {
                x= fr.Predict(testImage);
                pictureBox1.Image = testImage.ToBitmap();
                //MessageBox.Show(x.Label.ToString()+" "+x.Distance.ToString());

                OleDbCommand D1 = new OleDbCommand("Select [ID] FROM [connect]", DBConnection);
                OleDbDataReader reader = D1.ExecuteReader();
                while (reader.Read())
                {

                   if (Convert.ToInt32(reader["ID"]) == x.Label)
                   {

                       OleDbCommand insert1 = new OleDbCommand("UPDATE OutputReport SET [Attendance]='yes' WHERE [StudentID]='109';", DBConnection);
                      int i= insert1.ExecuteNonQuery();
                      MessageBox.Show(i.ToString());
                   }
               }
                RefreshDBConnection();

                if (x.Distance < 69)
                    return x.Label;
                else
                    MessageBox.Show("Error!!, The detected Face is neither recognised nor enrolled");
                return -1;
            }

        else

        {

            return -1;
        }


    }