public void LoadCompleteTrainingSet() { int i = 0; ConnectToDatabase(); ImageInDatabase imageToStore = new ImageInDatabase(); SqlCommand cmd = new SqlCommand("SP_Select_All_FAces", m_conMyConnection); cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter sDataAdapter = new SqlDataAdapter(); sDataAdapter.SelectCommand = cmd; DataSet sDataSet = new DataSet(); sDataAdapter.Fill(sDataSet); DisconnectFromDatabase(); int iUlngthTrainingArray = sDataSet.Tables[0].Rows.Count; m_trainingImages = new Emgu.CV.Image<Gray, Byte>[iUlngthTrainingArray]; m_TrainingLabels = new string[iUlngthTrainingArray]; foreach (DataRow row in sDataSet.Tables[0].Rows) { byte[] ImageByteArrayToConert = (byte[])row["FacialPic"]; ImageOfFace = new Bitmap(ConvertByteArray(ImageByteArrayToConert)); m_trainingImages[i] = new Emgu.CV.Image<Gray, byte>(ImageOfFace); m_TrainingLabels[i] = row["ID"].ToString(); i++; } DisconnectFromDatabase(); }
private void cmdSearch_Click(object sender, EventArgs e) { // Check if all is filled if (txtLastName.TextLength > 0) { // Load the face ImageInDatabase dgimgObject = new ImageInDatabase(); dgimgObject.ReadImageFromDB(txtLastName.Text); if (dgimgObject.FirstName.Length > 0) //@rie, not veryu nice, but lets assume that in this case a person was found... { txtFirstName.Text = dgimgObject.FirstName; txtLastName.Text = dgimgObject.LastName; dtDateOfBirth.Value = dgimgObject.DateOfBirth; txtCoffeePreference.Text = dgimgObject.CoffeePreference; imgFaceToSave.Image = new Image<Bgr, byte>((dgimgObject.ImageOfFace)); } else { MessageBox.Show("No person was found with that name"); } //Exit // this.Close(); } else { MessageBox.Show("Vul de achternaam in...", "Check gegevens", MessageBoxButtons.OK); } }
//-------------------------------------------------------------------------------------// //<<<<<----------------FUNCTIONS USED TO TRAIN RECOGNIZER ON TRAINING SET----------->>>> //-------------------------------------------------------------------------------------// /// <summary> /// Trains recognizer on fetched face-label pairs and saves the trained data to recognition variables /// </summary> public void TrainRecognizer() { MCvTermCriteria termCrit = new MCvTermCriteria(iMaxItereations, dEPS); ImageInDatabase dbTrainingSet = new ImageInDatabase(); // This will fill the training images array AND labels array dbTrainingSet.LoadCompleteTrainingSet(); recognizer = new EigenObjectRecognizer(dbTrainingSet.m_trainingImages, dbTrainingSet.m_TrainingLabels, dDistTreshHold, ref termCrit); }
private void cmdOk_Click(object sender, EventArgs e) { // Check if all is filled if (txtCoffeePreference.TextLength > 0 && txtLastName.TextLength > 0 && txtFirstName.TextLength > 0) { // Save the face ImageInDatabase dgimgObject = new ImageInDatabase(); dgimgObject.FirstName = txtFirstName.Text; dgimgObject.LastName = txtLastName.Text; dgimgObject.DateOfBirth = dtDateOfBirth.Value; dgimgObject.CoffeePreference = txtCoffeePreference.Text; dgimgObject.ImageOfFace = m_ImageOfFaceToRegister; dgimgObject.StoreImageToDataBase(); //Exit RegisterFace.ActiveForm.Close(); } else { MessageBox.Show("Vul alle gegevens in aub", "Check gegevens", MessageBoxButtons.OK); } }
public void ReadImageFromDBWithID(string strFacialID) { ConnectToDatabase(); //Retrieve the image ImageInDatabase imageToStore = new ImageInDatabase(); SqlCommand cmd = new SqlCommand("SP_Select_Face_by_ID", m_conMyConnection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@FacialID", SqlDbType.NVarChar).Value = strFacialID; SqlDataReader sdResult = cmd.ExecuteReader(); if (sdResult.Read()) { LastName = (string)sdResult["LastName"]; FirstName = (string)sdResult["FirstName"]; DateOfBirth = (DateTime)sdResult["DateOfBirth"]; CoffeePreference = (string)sdResult["CoffeePreference"]; byte[] ImageByteArrayToConert = (byte[])sdResult["FacialPic"]; ImageOfFace = new Bitmap(ConvertByteArray(ImageByteArrayToConert)); } sdResult.Close(); DisconnectFromDatabase(); }
private void TryRecognizePerson(IImage imageToRecognize) { // This will result in a facialID string RecognizeResultID = recognizer.Recognize((Image<Gray, Byte>)imageToRecognize); string sResultOfRecognize = "Nope, couldn't find you. Please click save if you want me to recognize you next time..."; if (RecognizeResultID.Length > 0) { ImageInDatabase iidRecPerson = new ImageInDatabase(); iidRecPerson.ReadImageFromDBWithID(RecognizeResultID); sResultOfRecognize = "Hallo " + iidRecPerson.FirstName + " " + iidRecPerson.LastName + ",\r\n"; sResultOfRecognize += "Wilt u weer een " + iidRecPerson.CoffeePreference + "?\r\n"; sResultOfRecognize += "Paremeters: Tresh - " + dDistTreshHold.ToString() + " \r\n"; sResultOfRecognize += "Paremeters: EPS - " + dEPS.ToString() + " \r\n"; sResultOfRecognize += "Paremeters: MaxIt - " + iMaxItereations.ToString(); } lblResult.Text = sResultOfRecognize; }