Note that there are some explanatory texts on larger screens.

plurals
  1. POC# - Emgu Cv - Face Recognition- Loading training sets of Faces saved to Access database as a binary in to EigenObjectRecognizer for Face recognition
    primarykey
    data
    text
    <p>I was having a hard time loading training set from Ms Access database in to the main form that does the Face Recognition. I saved the training sets with their names and ID in to the database as a binary data with an OLE Object format.The method i used to change, save and read the data from the database and in to the training sets is </p> <pre><code>private static byte[] ConvertImageToBytes(Image InputImage) { using (Bitmap BmpImage = new Bitmap(InputImage)) { using (MemoryStream MyStream = new MemoryStream()) { BmpImage.Save(MyStream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] ImageAsBytes = MyStream.ToArray(); return ImageAsBytes; } } } </code></pre> <p>The method that i use to store the converted byte data to the database is the following:</p> <pre><code> private void StoreData(byte[] ImageAsBytes,String NameStudent,String IDStudent) { if (DBConnection.State.Equals(ConnectionState.Closed)) DBConnection.Open(); try { //MessageBox.Show("Saving image at index : " + rowPosition); using (OleDbCommand insert = new OleDbCommand(String.Format("Insert INTO TrainingSet(rowPosition,StudentName,StudentID,StudentFace) values (' {0}','{1}','{2}',@StudentFace)", rowPosition, NameStudent, IDStudent), DBConnection)) { OleDbParameter imageParameter = insert.Parameters.AddWithValue(@"StudentFace", SqlDbType.Binary); imageParameter.Value = ImageAsBytes; imageParameter.Size = ImageAsBytes.Length; int rowsAffected = insert.ExecuteNonQuery(); MessageBox.Show(String.Format("Data stored successfully in {0} Row",rowsAffected)); } rowPosition++; } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.Message); } finally { RefreshDBConnection(); } } </code></pre> <p>The method that i use to Read this binary data is as follows: </p> <pre><code> private Image ReadImageFromDB() { Image FetchedImg; if (rowNumber &gt;= 0) { byte[] FetchedImgBytes = (byte[])LocalDataTable.Rows[rowNumber]["StudentFace"]; MemoryStream stream = new MemoryStream(FetchedImgBytes); FetchedImg = Image.FromStream(stream); return FetchedImg; } else { MessageBox.Show("There are no images in the database yet.Please reconnect or add some pictures."); return null; } } </code></pre> <p>I have successfully saved the training sets/images as a binary data in to the database.The problem is when i load these training sets for Recognition.</p> <pre><code> // Declaring the variables=====trainingImages is where the training sets are // loaded from the database NameLabels and IDLabels are text in the database // and where name and Id of subject //is saved. List&lt;Image&lt;Gray,byte&gt;&gt; trainingImages = new List&lt;Image&lt;Gray,byte&gt;&gt;(); List&lt;string&gt; NameLables= new List&lt;string&gt;(); List&lt;string&gt; IDLables = new List&lt;string&gt;(); int ContTrain, NumNameLabels,NumIDLabels, t; //The training sets from the database are loaded in to the facerecognizer code as // follows public FaceRecognizer() { InitializeComponent(); try { //Load previous trained and labels for each image from the database Here RefreshDBConnection(); String[] NameLabels = (String[])LocalDataTable.Rows[rowNumber]["StudentName"]; NumNameLabels = Convert.ToInt16(NameLabels[0]); String[] IDLabels = (String[])LocalDataTable.Rows[rowNumber]["StudentID"]; NumIDLabels = Convert.ToInt16(IDLabels[0]); if (NumNameLabels == NumIDLabels) { ContTrain = NumNameLabels; string LoadFaces; // Converting the master image to a bitmap Image imageFromDB; Bitmap imageChangedToBitmap; // Normalizing it to grayscale Image&lt;Gray, Byte&gt; normalizedMasterImage; for (int tf = 1; tf &lt; NumNameLabels + 1; tf++) { imageFromDB = ReadImageFromDB(); //image loaded from the database is converted in to Bitmap and then //convert the bitmap image in to Image&lt;Gray,byte&gt; for input to //EigenObjectRecognizer(,,,) imageChangedToBitmap = new Bitmap(imageFromDB); normalizedMasterImage = new Image&lt;Gray, Byte&gt;(imageChangedToBitmap); LoadFaces = String.Format("face{0}.bmp", tf); trainingImages.Add(normalizedMasterImage); //trainingImages.Add(new Image&lt;Gray, byte&gt;()); NameLables.Add(NameLabels[tf]); IDLables.Add(IDLabels[tf]); rowNumber = rowNumber + 1; } } else MessageBox.Show("There's a conflict between Name labels and id labels"); } catch (Exception e) { MessageBox.Show("Nothing in the database, please add at least a face.Train the database","Triained faces load",MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } </code></pre> <p>I am only getting the message in the catch when the the form loads even if there are faces saved in the database. I have used EigenObjectRecognizer and i will post the code if necessary.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload