C# - Emgu Cv - Face Recognition- Loading training sets of Faces saved to Access database as a binary in to EigenObjectRecognizer for Face recognition -


i having hard time loading training set ms access database in main form face recognition. saved training sets names , id in database binary data ole object format.the method used change, save , read data database , in training sets

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;             }         }     } 

the method use store converted byte data database following:

   private void storedata(byte[] imageasbytes,string namestudent,string idstudent)     {          if (dbconnection.state.equals(connectionstate.closed))             dbconnection.open();         try         {              //messagebox.show("saving image @ index : " + rowposition);             using (oledbcommand insert = new oledbcommand(string.format("insert                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 in {0}                                        row",rowsaffected));          }             rowposition++;          }         catch (exception ex)         {             messagebox.show(ex.message);             messagebox.show(ex.message);         }                 {             refreshdbconnection();         }       } 

the method use read binary data follows:

    private image readimagefromdb()     {          image fetchedimg;         if (rownumber >= 0)         {          byte[] fetchedimgbytes = (byte[])localdatatable.rows[rownumber]["studentface"];             memorystream stream = new memorystream(fetchedimgbytes);             fetchedimg = image.fromstream(stream);             return fetchedimg;         }         else         {              messagebox.show("there no images in database yet.please reconnect                        or add pictures.");             return null;         }      } 

i have saved training sets/images binary data in database.the problem when load these training sets recognition.

        // declaring variables=====trainingimages training sets         // loaded database namelabels , idlabels text in database         // , name , id of subject         //is saved.       list<image<gray,byte>> trainingimages = new list<image<gray,byte>>();       list<string> namelables= new list<string>();       list<string> idlables = new list<string>();       int conttrain, numnamelabels,numidlabels, t;     //the training sets database loaded in facerecognizer code     //       follows    public facerecognizer()     {         initializecomponent();          try         {             //load previous trained , labels each image 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 master image bitmap           image imagefromdb;           bitmap imagechangedtobitmap;           // normalizing grayscale           image<gray, byte> normalizedmasterimage;            (int tf = 1; tf < numnamelabels + 1; tf++)            {               imagefromdb = readimagefromdb();               //image loaded database converted in bitmap ,                //convert bitmap image in image<gray,byte> input                //eigenobjectrecognizer(,,,)               imagechangedtobitmap = new bitmap(imagefromdb);               normalizedmasterimage = new image<gray, byte>(imagechangedtobitmap);               loadfaces = string.format("face{0}.bmp", tf);               trainingimages.add(normalizedmasterimage);                 //trainingimages.add(new image<gray, byte>());               namelables.add(namelabels[tf]);               idlables.add(idlabels[tf]);               rownumber = rownumber + 1;             }          }        else            messagebox.show("there's conflict between name labels , id labels");         }       catch (exception e)         {    messagebox.show("nothing in database, please add @ least                face.train database","triained faces load",messageboxbuttons.ok,                messageboxicon.exclamation);         }      } 

i getting message in catch when the form loads if there faces saved in database. have used eigenobjectrecognizer , post code if necessary.

at part of loading face, did not save face1, face2, face3 etc. can not load using;

loadfaces = string.format("face{0}.bmp", tf); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -