I am a beginner in openCV and C++ as well.I am stuck in a particular place while trying to implement face recognition in open cv.
I have the stored training images in a folder called data
the images of first person is stored like 1_john1.pgm
2nd image of first person .................1_john2.pgm and so on.
Next persons first image is again 2_peter1.pgm etc etc
Now I have -
vector<string> personNames;// array of person names (indexed by the person number).
Now after running face recognition algorithm i am getting -
personNames[nearest-1].c_str()
which contains the string with the persons name which has been detected.
SO if john was detected it will return john.
Now I have to display the image of john from the training folder but there it is stored in the format 1_john1.pgm.
ANY one image of john is required to be displayed out of several images stored there.
I am not able to use wildcard in the strcat command properly to pass the name stored in the string to the opencv command for loading image. my unsuccessful efforts of last 25-30 hours of coding is below :-
strcpy (cstr, personNames[nearest-1].c_str());
//strcat(cstr,("\\*.*"));
IplImage *img1=0, *img2;
strcat(cstr, "data/%d_%s%d.pgm", 9, personNames[nearest-1].c_str(), 6);
img2=cvLoadImage(cstr);
// img2 = cvLoadImage("data/9_john5.pgm");
The above is the latest bit of code which does not work at all, i have tried many many different techniques but did not succeed.
Now I am able to save the training image list in a text file called train.txt.
here the names are stored as
4 sachin data/4_sachin1.pgm
4 sachin data/4_sachin2.pgm
4 sachin data/4_sachin3.pgm
4 sachin data/4_sachin4.pgm
while the images are stored in the folder data
as
4_sachin1.pgm
4_sachin2.pgm
4_sachin3.pgm
4_sachin4.pgm
Let us assume personNames[nearest-1].c_str() has the string "sachin"
Basically I need to search the string 'sachin' in the train.txt file ,search through it till it comes to the entry -4 sachin data/4_sachin1.pgm
Now I have to remove "4 sachin "from the above so that i am only left with string 4_sachin1.pgm.
I need to pass this to the cvLoadimage command so that the image opens.
Will be very very grateful for the help of the experts in this forum to help me with the correct syntax.
Please Help"