I have run this code below but it have a few error..hope someone could help me to solve this problem..tq..:)

#include <stdio.h>
#include <string.h>
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"

int nTrainFaces=0;
int nEigens=0;
IplImage ** faceImgArr =0;
CvMat * personNumTruthMat =0;
IplImage * pAvgTrainImg = 0;
IplImage ** eigenVector =0;
CvMat * eigenValMat =0;
CvMat * projectedTrainFaceMat =0;

void learn ();
void recognize ();
void doPCA ();
void storeTrainingData ();
int loadTrainingData (CvMat ** pTrainPersonNumMat);
int findNearestNeighbor (float * projectedTestFace);
int loadFaceImgArray ( char * filename);
void printUsage ();

void main (int argc, char ** argv)
{
  if (argc !=2)
{

printUsage ();
return;
}

if (!strcmp (argv[1], "train") )learn ();
else if (!strcmp (argv [1] , "test")) recognize ();
else
{
 printf ("Unknown command: %s\n", argv[1]);
printUsage ();
}


 printf ("Usage : eigenface <command>\\n", "valid commands are \n" "train\n" "test\n");



 int i;

nTrainFaces = loadFaceImgArray ("train.txt");
if (nTrainFaces <2)
{
 fprintf (stderr, "Need 2 or more training faces \n" "Input file contains only %d\n", nTrainFaces);
return;
}

doPCA ();

projectedTrainFaceMat = cvCreateMat (nTrainFaces, nEigens, CV_32FC1);
for (i=0; i<nTrainFaces; i++)
{
 cvEigenDecomposite 
( faceImgArr [i], 
 nEigens, 
 eigenVectArr, 
 0, 0, 
 pAvgTrainImg, 
 projectedTrainFaceMat ->data.f1 + i*nEigens);
}

storeTrainingData ();



 FILE * imgListFile = 0;
char imgFilename [512];
int iFace, nFaces=0;

imgListFile = fopen (filename, "r");

while (fgets (imgFilename, 512, imgListFile)) ++nFaces;
rewind (imgListFile);

faceImgArr = (IplImage **) cvAlloc (nFaces * sizeof (IplImage *));
personNumTruthMat = cvCreateMat (1, nFaces, CV_32SC1);

for (iFace=0; iFace<nFaces; iFace ++)
{
 fscanf (imgListFile,
 %d %s, personNumTruthMat -> data.i + iFace, imgFilename);

 faceImgArr [iFace]= cvLoadImage (imgFilename, CV_LOAD_IMAGE_GRAYSCALE);
}

fclose (imgListFile);

return nFaces;




 int i;
CvTermCriteria calcLimit;
CvSize faceImgSize;

nEigens = nTrainFaces -1;

faceImgSize.width = faceImgArr [0]-> width;
faceImgSize.height = faceImgArr [0]-> height;
eigenVectArr =(IplImage **) cvAlloc (sizeof (IplImage *) * nEigens);
for (i=0; i<nEigens; i++)
 eigenVectArr [i]=cvCreateImage (faceImgSize, IPL_DEPTH_32F, 1);

eigenValMat = cvCreateMat (1, nEigens, CV_32FC1);

pAvgTrainImg = cvCreateImage (faceImgSize, IPL_DEPTH_32F, 1);

calcLimit = cvTermCriteria (CV_TERMCRIT_ITER, nEigens, 1);

cvCalcEigenObjects(
nTrainFaces,
(void *) faceImgArr,
(void *) eigenVectArr,
CV_EIGOBJ_NO_CALLBACK,
0,
0,
&caclLimit,
pAvgTrainImg,
eigenValMat->data.f1);




 CvFileStorage * fileStorage;
  int i;

fileStorage = cvOpenFileStorage ("facedata.xml", 0, CV_STORAGE_WRITE);

cvWriteInt (fileStorage, "nEigens" , nEigens);
cvWriteInt (fileStorage, "nTrainFaces", nTrainFaces);
cvWrite(fileStorage, "trainsPersonNumMat", personNumTruthMat, cvAttrList (0.0));
cvWrite (fileStorage, "eigenValMat", eigenValMat, cvAttrList (0,0));
cvWrite (fileStorage, "projectedTrainFaceMat", projectedTrainFaceMat, cvAttrList (0,0));
cvWrite (fileStorage, "avgTrainImg", pAvgTrainImg, cvAttrList (0,0));

for (i=0; i<nEigens; i++)
{
 char varname [200];
sprintf (varname, "eigenVect_%d", i);
cvWrite (fileStorage, varname, eigenVectArr [i], cvAttrList (0,0));
}

cvReleaseFileStorage (&fileStorage);

}


errors:
1)'eigenVectArr' : undeclared identifier
2)'f1' : is not a member of '__unnamed'
3)'filename' : undeclared identifier
4)syntax error : '%'
5)'main' : 'void' function returning a value
6) see declaration of 'main'
7)'i' : redefinition
8)'=' : cannot convert from 'struct _IplImage ** ' to 'int'
9) subscript requires array or pointer type
10)'=' : cannot convert from 'struct _IplImage *' to 'int'
   This conversion requires a reinterpret_cast, a C-style cast or function-style cast
11) 'caclLimit' : undeclared identifier
12)'f1' : is not a member of '__unnamed'
 13) 'cvAttrList' : cannot convert parameter 1 from 'const double' to 'const char ** '
        There is no context in which this conversion is possible
14) 'i' : redefinition
15) 'cvWrite' : cannot convert parameter 3 from 'int' to 'const void *'
        Conversion from integral type to pointer type requires reinterpret_cast, 

some error said i did't declare but i had declare..what exactly the problem of my code??

you should use code tags when posting a program.

you should use code tags when posting a program.

ok2...sorry for that..

Always start with the first error and ignore the rest for now.
Where is eigenVectArr actgually declared?

Always start with the first error and ignore the rest for now.
Where is eigenVectArr actgually declared?

tq2..i make a mistake on type the code..but when i had declare that eigenVectArr it still have the prob..

It still says it is undeclared?

It still says it is undeclared?

nope...another error which f1: is not a member of '__unnamed..i did't understand what the meaning of this error..hope u can help me...thank you..

Good. The first error is gone.
So, for the next error, does projectedTrainFaceMat have a member called "data"?

projectedTrainFaceMat->data.f1

When you reference data.f1, do both "data" and "data.f1" exist?

Good. The first error is gone.
So, for the next error, does projectedTrainFaceMat have a member called "data"?

projectedTrainFaceMat->data.f1

When you reference data.f1, do both "data" and "data.f1" exist?

yes..that data had exist..so, what exactly the problem with that code??thank you for helping me

What line did the compiler say that error was on?

Sorry guys, i just HAD to repost the code as it was practically unreadable without code tags and indentation.

#include <stdio.h>
#include <string.h>
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"

//-------------------- DECLARATIONS -----------------------------
int nTrainFaces=0;
int nEigens=0;
IplImage ** faceImgArr =0;
CvMat * personNumTruthMat =0;
IplImage * pAvgTrainImg = 0;
IplImage ** eigenVector =0;
CvMat * eigenValMat =0;
CvMat * projectedTrainFaceMat =0;

//----------------------------------------------

//------------------- Function Prototypes -----------------
void learn ();
void recognize ();
void doPCA ();
void storeTrainingData ();
int loadTrainingData (CvMat ** pTrainPersonNumMat);
int findNearestNeighbor (float * projectedTestFace);
int loadFaceImgArray ( char * filename);
void printUsage ();

//------------------------------------------------------

void main (int argc, char ** argv)
{
    if (argc !=2)
     {
        printUsage ();
        return;             //"since im rewritin the code i wanna point out an error"
      }                // "u cant use a return statement, data type of main is void" 

    if (!strcmp (argv[1], "train") )
       learn ();
    else 
        if (!strcmp (argv [1] , "test")) 
            recognize (); 
        else 
             {
               printf ("Unknown command: %s\n", argv[1]);
               printUsage ();
               }

   printf ("Usage : eigenface <command>\\n", "valid commands are\ntrain\ntest\n");
           
        // "one more change... Y so many " ", when it can be written as 1 ?? "

   int i;

   nTrainFaces = loadFaceImgArray ("train.txt");

   if (nTrainFaces <2)
      {
       fprintf (stderr, "Need 2 or more training faces \nInput file contains only       %d\n", nTrainFaces);
        return;         // "Cant use return as specified above"
       }

     doPCA ();

     projectedTrainFaceMat = cvCreateMat (nTrainFaces, nEigens, CV_32FC1);

     for (i=0; i<nTrainFaces; i++) 
         {
            cvEigenDecomposite 
           (  faceImgArr [i], 
              nEigens,  
              eigenVectArr, 
              0, 0,  
              pAvgTrainImg, 
              projectedTrainFaceMat ->data.f1 + i*nEigens);
          } 

     storeTrainingData ();

     FILE * imgListFile = 0;
     char imgFilename [512];
     int iFace, nFaces=0;

     imgListFile = fopen (filename, "r");

     while (fgets (imgFilename, 512, imgListFile)) 
            ++nFaces;

     rewind (imgListFile);

     faceImgArr = (IplImage **) cvAlloc (nFaces * sizeof (IplImage *));
     personNumTruthMat = cvCreateMat (1, nFaces, CV_32SC1);

     for (iFace=0; iFace<nFaces; iFace ++) 
         { fscanf (imgListFile, %d %s, personNumTruthMat -> data.i + iFace, imgFilename);

           faceImgArr [iFace]= cvLoadImage (imgFilename, CV_LOAD_IMAGE_GRAYSCALE);
          }

     fclose (imgListFile);

     return nFaces;   // "As mentioned earlier, u cant return "

     int i;
     CvTermCriteria calcLimit;
     CvSize faceImgSize;

     nEigens = nTrainFaces -1;

     faceImgSize.width = faceImgArr [0]-> width;
     faceImgSize.height = faceImgArr [0]-> height;
     eigenVectArr =(IplImage **) cvAlloc (sizeof (IplImage *) * nEigens);

     for (i=0; i<nEigens; i++)
          eigenVectArr [i]=cvCreateImage (faceImgSize, IPL_DEPTH_32F, 1);

     eigenValMat = cvCreateMat (1, nEigens, CV_32FC1);

     pAvgTrainImg = cvCreateImage (faceImgSize, IPL_DEPTH_32F, 1);

     calcLimit = cvTermCriteria (CV_TERMCRIT_ITER, nEigens, 1);

     cvCalcEigenObjects(nTrainFaces,
     (void *) faceImgArr,
     (void *) eigenVectArr,
     CV_EIGOBJ_NO_CALLBACK,
     0,0,
     &caclLimit,
     pAvgTrainImg,
     eigenValMat->data.f1);




     CvFileStorage * fileStorage;
     int i;

     fileStorage = cvOpenFileStorage ("facedata.xml", 0, CV_STORAGE_WRITE);

     cvWriteInt (fileStorage, "nEigens" , nEigens);
     cvWriteInt (fileStorage, "nTrainFaces", nTrainFaces);
     cvWrite(fileStorage, "trainsPersonNumMat", personNumTruthMat, cvAttrList (0.0));
     cvWrite (fileStorage, "eigenValMat", eigenValMat, cvAttrList (0,0));
     cvWrite (fileStorage, "projectedTrainFaceMat", projectedTrainFaceMat, cvAttrList      (0,0));
     cvWrite (fileStorage, "avgTrainImg", pAvgTrainImg, cvAttrList (0,0));

     for (i=0; i<nEigens; i++) 
         { char varname [200];
           sprintf (varname, "eigenVect_%d", i);
           cvWrite (fileStorage, varname, eigenVectArr [i], cvAttrList (0,0));
          }

     cvReleaseFileStorage (&fileStorage);

}

Woof ! Got tired indenting that stuff !! Newayz good luck reading it and correcting, hope this makes the code more readable - coz i dint understand shit in the code :P

And so that u dont have to keep scrolling up for the errors, here they are :
Errors:
1)'eigenVectArr' : undeclared identifier
2)'f1' : is not a member of '__unnamed'
3)'filename' : undeclared identifier
4)syntax error : '%'
5)'main' : 'void' function returning a value
6) see declaration of 'main'
7)'i' : redefinition
8)'=' : cannot convert from 'struct _IplImage ** ' to 'int'
9) subscript requires array or pointer type
10)'=' : cannot convert from 'struct _IplImage *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
11) 'caclLimit' : undeclared identifier
12)'f1' : is not a member of '__unnamed'
13) 'cvAttrList' : cannot convert parameter 1 from 'const double' to 'const char ** '
There is no context in which this conversion is possible
14) 'i' : redefinition
15) 'cvWrite' : cannot convert parameter 3 from 'int' to 'const void *'
Conversion from integral type to pointer type requires reinterpret_cast,

What line did the compiler say that error was on?

on the line which

projectedTrainFaceMat ->data.f1 + i*nEigens);
#include <stdio.h>
#include <string.h>
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"

int nTrainFaces=0;
int nEigens=0;
IplImage ** faceImgArr =0;
CvMat * personNumTruthMat =0;
IplImage * pAvgTrainImg = 0;
IplImage ** eigenVectArr =0;
CvMat * eigenValMat =0;
CvMat * projectedTrainFaceMat =0;

void learn ();
void recognize ();
void doPCA ();
void storeTrainingData ();
int loadTrainingData (CvMat ** pTrainPersonNumMat);
int findNearestNeighbor (float * projectedTestFace);
int loadFaceImgArray ( char * filename);
void printUsage ();

void main (int argc, char ** argv)
{
{
  if (argc !=2)
{
 
printUsage ();
return;
}

if (!strcmp (argv[1], "train") )learn ();
else if (!strcmp (argv [1] , "test")) recognize ();
else
{
 printf ("Unknown command: %s\n", argv[1]);
printUsage ();
}


 printf ("Usage : eigenface <command>\\n", "valid commands are \n" "train\n" "test\n");

}

{
 int i;

nTrainFaces = loadFaceImgArray ("train.txt");
if (nTrainFaces <2)
{
 fprintf (stderr, "Need 2 or more training faces \n" "Input file contains only %d\n", nTrainFaces);
return;
}

doPCA ();

projectedTrainFaceMat = cvCreateMat (nTrainFaces, nEigens, CV_32FC1);
for (i=0; i<nTrainFaces; i++)
{
 cvEigenDecomposite 
( faceImgArr [i], 
 nEigens, 
 eigenVectArr, 
 0, 0, 
 pAvgTrainImg, 
 projectedTrainFaceMat ->data.f1 + i*nEigens);
}

storeTrainingData ();
}

{
 char * filename;
 FILE * imgListFile = 0;
char imgFilename [512];
int iFace, nFaces=0;

imgListFile = fopen (filename, "r");

while (fgets (imgFilename, 512, imgListFile)) ++nFaces;
rewind (imgListFile);

faceImgArr = (IplImage **) cvAlloc (nFaces * sizeof (IplImage *));
personNumTruthMat = cvCreateMat (1, nFaces, CV_32SC1);

for (iFace=0; iFace<nFaces; iFace ++)
{
 fscanf (imgListFile,
 %d %s, personNumTruthMat -> data.i + iFace, imgFilename);

 faceImgArr [iFace]= cvLoadImage (imgFilename, CV_LOAD_IMAGE_GRAYSCALE);
}

fclose (imgListFile);

return nFaces;
}

{

 int i;
CvTermCriteria calcLimit;
CvSize faceImgSize;

nEigens = nTrainFaces -1;

faceImgSize.width = faceImgArr [0]-> width;
faceImgSize.height = faceImgArr [0]-> height;
eigenVectArr =(IplImage **) cvAlloc (sizeof (IplImage *) * nEigens);
for (i=0; i<nEigens; i++)
 eigenVectArr [i]=cvCreateImage (faceImgSize, IPL_DEPTH_32F, 1);

eigenValMat = cvCreateMat (1, nEigens, CV_32FC1);

pAvgTrainImg = cvCreateImage (faceImgSize, IPL_DEPTH_32F, 1);

calcLimit = cvTermCriteria (CV_TERMCRIT_ITER, nEigens, 1);

cvCalcEigenObjects(
nTrainFaces,
(void *) faceImgArr,
(void *) eigenVectArr,
CV_EIGOBJ_NO_CALLBACK,
0,
0,
&caclLimit,
pAvgTrainImg,
eigenValMat->data.f1);
}



 CvFileStorage * fileStorage;
  int i;

fileStorage = cvOpenFileStorage ("facedata.xml", 0, CV_STORAGE_WRITE);

cvWriteInt (fileStorage, "nEigens" , nEigens);
cvWriteInt (fileStorage, "nTrainFaces", nTrainFaces);
cvWrite(fileStorage, "trainsPersonNumMat", personNumTruthMat, cvAttrList (0.0));
cvWrite (fileStorage, "eigenValMat", eigenValMat, cvAttrList (0,0));
cvWrite (fileStorage, "projectedTrainFaceMat", projectedTrainFaceMat, cvAttrList (0,0));
cvWrite (fileStorage, "avgTrainImg", pAvgTrainImg, cvAttrList (0,0));

for (i=0; i<nEigens; i++)
{
 char varname [200];
sprintf (varname, "eigenVect_%d", i);
cvWrite (fileStorage, varname, eigenVectArr [i], cvAttrList (0,0));
}

cvReleaseFileStorage (&fileStorage);


}

Sorry guys, i just HAD to repost the code as it was practically unreadable without code tags and indentation.

#include <stdio.h>
#include <string.h>
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"

//-------------------- DECLARATIONS -----------------------------
int nTrainFaces=0;
int nEigens=0;
IplImage ** faceImgArr =0;
CvMat * personNumTruthMat =0;
IplImage * pAvgTrainImg = 0;
IplImage ** eigenVector =0;
CvMat * eigenValMat =0;
CvMat * projectedTrainFaceMat =0;

//----------------------------------------------

//------------------- Function Prototypes -----------------
void learn ();
void recognize ();
void doPCA ();
void storeTrainingData ();
int loadTrainingData (CvMat ** pTrainPersonNumMat);
int findNearestNeighbor (float * projectedTestFace);
int loadFaceImgArray ( char * filename);
void printUsage ();

//------------------------------------------------------

void main (int argc, char ** argv)
{
    if (argc !=2)
     {
        printUsage ();
        return;             //"since im rewritin the code i wanna point out an error"
      }                // "u cant use a return statement, data type of main is void" 

    if (!strcmp (argv[1], "train") )
       learn ();
    else 
        if (!strcmp (argv [1] , "test")) 
            recognize (); 
        else 
             {
               printf ("Unknown command: %s\n", argv[1]);
               printUsage ();
               }

   printf ("Usage : eigenface <command>\\n", "valid commands are\ntrain\ntest\n");
           
        // "one more change... Y so many " ", when it can be written as 1 ?? "

   int i;

   nTrainFaces = loadFaceImgArray ("train.txt");

   if (nTrainFaces <2)
      {
       fprintf (stderr, "Need 2 or more training faces \nInput file contains only       %d\n", nTrainFaces);
        return;         // "Cant use return as specified above"
       }

     doPCA ();

     projectedTrainFaceMat = cvCreateMat (nTrainFaces, nEigens, CV_32FC1);

     for (i=0; i<nTrainFaces; i++) 
         {
            cvEigenDecomposite 
           (  faceImgArr [i], 
              nEigens,  
              eigenVectArr, 
              0, 0,  
              pAvgTrainImg, 
              projectedTrainFaceMat ->data.f1 + i*nEigens);
          } 

     storeTrainingData ();

     FILE * imgListFile = 0;
     char imgFilename [512];
     int iFace, nFaces=0;

     imgListFile = fopen (filename, "r");

     while (fgets (imgFilename, 512, imgListFile)) 
            ++nFaces;

     rewind (imgListFile);

     faceImgArr = (IplImage **) cvAlloc (nFaces * sizeof (IplImage *));
     personNumTruthMat = cvCreateMat (1, nFaces, CV_32SC1);

     for (iFace=0; iFace<nFaces; iFace ++) 
         { fscanf (imgListFile, %d %s, personNumTruthMat -> data.i + iFace, imgFilename);

           faceImgArr [iFace]= cvLoadImage (imgFilename, CV_LOAD_IMAGE_GRAYSCALE);
          }

     fclose (imgListFile);

     return nFaces;   // "As mentioned earlier, u cant return "

     int i;
     CvTermCriteria calcLimit;
     CvSize faceImgSize;

     nEigens = nTrainFaces -1;

     faceImgSize.width = faceImgArr [0]-> width;
     faceImgSize.height = faceImgArr [0]-> height;
     eigenVectArr =(IplImage **) cvAlloc (sizeof (IplImage *) * nEigens);

     for (i=0; i<nEigens; i++)
          eigenVectArr [i]=cvCreateImage (faceImgSize, IPL_DEPTH_32F, 1);

     eigenValMat = cvCreateMat (1, nEigens, CV_32FC1);

     pAvgTrainImg = cvCreateImage (faceImgSize, IPL_DEPTH_32F, 1);

     calcLimit = cvTermCriteria (CV_TERMCRIT_ITER, nEigens, 1);

     cvCalcEigenObjects(nTrainFaces,
     (void *) faceImgArr,
     (void *) eigenVectArr,
     CV_EIGOBJ_NO_CALLBACK,
     0,0,
     &caclLimit,
     pAvgTrainImg,
     eigenValMat->data.f1);




     CvFileStorage * fileStorage;
     int i;

     fileStorage = cvOpenFileStorage ("facedata.xml", 0, CV_STORAGE_WRITE);

     cvWriteInt (fileStorage, "nEigens" , nEigens);
     cvWriteInt (fileStorage, "nTrainFaces", nTrainFaces);
     cvWrite(fileStorage, "trainsPersonNumMat", personNumTruthMat, cvAttrList (0.0));
     cvWrite (fileStorage, "eigenValMat", eigenValMat, cvAttrList (0,0));
     cvWrite (fileStorage, "projectedTrainFaceMat", projectedTrainFaceMat, cvAttrList      (0,0));
     cvWrite (fileStorage, "avgTrainImg", pAvgTrainImg, cvAttrList (0,0));

     for (i=0; i<nEigens; i++) 
         { char varname [200];
           sprintf (varname, "eigenVect_%d", i);
           cvWrite (fileStorage, varname, eigenVectArr [i], cvAttrList (0,0));
          }

     cvReleaseFileStorage (&fileStorage);

}

Woof ! Got tired indenting that stuff !! Newayz good luck reading it and correcting, hope this makes the code more readable - coz i dint understand shit in the code :P

could u explain why i can't use the return statement??i did't understand..anyway thank you for your comment..

Yea, the reason u cant use the return statement is coz ur calling everything from main and ur active function is only your main. Since the return type of your main function is void (see line 31 in the code i posted), u cannot return a value to the function! Change the return type to void... Thats the only mistake i could figure out coz i think it was pretty basic... I dint understand anything u did, hats off to u for knowing it and writing that code( irrespective of the errors) :)

It's been a long time I coded in C, but I don't see any C++ type streams, or std containers, mostly printf, scanf, fprintf, fscanf, fgets, and pointers everywhere. I am sorry, are you coding in C or C++?

Oh yea, if this is C , you got another forum :P

Yea, the reason u cant use the return statement is coz ur calling everything from main and ur active function is only your main. Since the return type of your main function is void (see line 31 in the code i posted), u cannot return a value to the function! Change the return type to void... Thats the only mistake i could figure out coz i think it was pretty basic... I dint understand anything u did, hats off to u for knowing it and writing that code( irrespective of the errors) :)

oooooo...thank you..actually i had solve the prob for that..i made a mistake which i put everything in main and return that function..anyway thank you for helping and your comment.

It's been a long time I coded in C, but I don't see any C++ type streams, or std containers, mostly printf, scanf, fprintf, fscanf, fgets, and pointers everywhere. I am sorry, are you coding in C or C++?

i coded in c++..some of the output i had change to the c++...from my code i still had afew error which it unresolved external symbol _cvEigenDecomposite..can you help me why this happen..thank you..:)

[TEX]#include <stdio.h>
#include <string.h>
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"

int nTrainFaces=0;
int nEigens=0;
IplImage ** faceImgArr =0;
CvMat * personNumTruthMat =0;
IplImage * pAvgTrainImg = 0;
IplImage ** eigenVectArr =0;
CvMat * eigenValMat =0;
CvMat * projectedTrainFaceMat =0;

void learn();
void recognize();
void doPCA();
void storeTrainingData();
int loadTrainingData(CvMat ** pTrainPersonNumMat);
int findNearestNeighbor(float * projectedTestFace);
int loadFaceImgArray( char * filename);
void printUsage();

void main (int argc, char ** argv)
{
	
  if (argc !=2)
	{printUsage();
	return;
	}

if (!strcmp (argv[1], "train") )
	 learn();
else if (!strcmp (argv [1] , "test")) 
	recognize ();
else
{
 printf ("Unknown command: %s\n", argv[1]);

 printUsage();
}
}

void printUsage()
{
 printf("Usage : eigenface <command> \n", "valid commands are \n train \n test \n");
}



void learn()
{
	int i;

	nTrainFaces = loadFaceImgArray("train.txt");
	if (nTrainFaces <2)
	{
	fprintf (stderr, "Need 2 or more training faces \n", "Input file contains only %d\n", nTrainFaces);
	}
	
	doPCA();

	projectedTrainFaceMat = cvCreateMat (nTrainFaces, nEigens, CV_32FC1);

	for (i=0; i<nTrainFaces; i++)
	{
	cvEigenDecomposite( faceImgArr[i], nEigens, eigenVectArr, 0, 0, pAvgTrainImg, projectedTrainFaceMat->data.fl + i*nEigens);
	}

	storeTrainingData();
}


int loadFaceImgArray(char * filename)
{ 
	FILE * imgListFile = 0;
	char imgFilename [512];
	int iFace, nFaces=0;

	imgListFile = fopen (filename, "r");

	while (fgets (imgFilename, 512, imgListFile))
		++nFaces;

	rewind(imgListFile);

	faceImgArr = (IplImage **) cvAlloc (nFaces * sizeof (IplImage *));

	personNumTruthMat = cvCreateMat (1, nFaces, CV_32SC1);

	for (iFace=0; iFace<nFaces; iFace ++)
	{
	fscanf (imgListFile," %d %s", personNumTruthMat -> data.i + iFace, imgFilename);

	faceImgArr [iFace]= cvLoadImage (imgFilename, CV_LOAD_IMAGE_GRAYSCALE);
	}

fclose (imgListFile);

return nFaces;
}


void doPCA()
{
 int i;
CvTermCriteria calcLimit;
CvSize faceImgSize;

nEigens = nTrainFaces -1;

faceImgSize.width = faceImgArr [0]-> width;
faceImgSize.height = faceImgArr [0]-> height;
eigenVectArr = (IplImage **) cvAlloc (sizeof (IplImage *) * nEigens);
for (i=0; i<nEigens; i++)
 eigenVectArr [i] = cvCreateImage (faceImgSize, IPL_DEPTH_32F, 1);

eigenValMat = cvCreateMat (1, nEigens, CV_32FC1);

pAvgTrainImg = cvCreateImage (faceImgSize, IPL_DEPTH_32F, 1);

calcLimit = cvTermCriteria (CV_TERMCRIT_ITER, nEigens, 1);

cvCalcEigenObjects(nTrainFaces,(void *) faceImgArr,(void *) eigenVectArr,CV_EIGOBJ_NO_CALLBACK,0,0,&calcLimit,pAvgTrainImg,eigenValMat->data.fl); 

}

void storeTrainingData ()
{
 CvFileStorage * fileStorage;
int i;

fileStorage = cvOpenFileStorage ("facedata.xml", 0, CV_STORAGE_WRITE);

cvWriteInt (fileStorage, "nEigens" , nEigens);
cvWriteInt (fileStorage, "nTrainFaces", nTrainFaces);
cvWrite(fileStorage, "trainsPersonNumMat", personNumTruthMat, cvAttrList(0,0));
cvWrite (fileStorage, "eigenValMat", eigenValMat, cvAttrList(0,0));
cvWrite (fileStorage, "projectedTrainFaceMat", projectedTrainFaceMat, cvAttrList(0,0));
cvWrite (fileStorage, "avgTrainImg", pAvgTrainImg, cvAttrList(0,0));

for (i=0; i<nEigens; i++)
{
 char varname [200];
sprintf (varname, "eigenVect_%d", i);
cvWrite (fileStorage, varname, eigenVectArr [i], cvAttrList(0,0));
}

cvReleaseFileStorage (&fileStorage);

}


void recognize ()
{
  int i, nTestFaces =0;
  CvMat * trainPersonNumMat = 0;
  float * projectedTestFace =0;

  nTestFaces = loadFaceImgArray ("test.txt");
  printf ("%d test face loaded\n", nTestFaces);

  if (!loadTrainingData (& trainPersonNumMat)) 
	  return;

  projectedTestFace = (float *)cvAlloc (nEigens * sizeof (float));
  for (i=0; i<nTestFaces; i++)
  {
    int iNearest, nearest, truth;

    cvEigenDecomposite(faceImgArr[i],nEigens,eigenVectArr,0,0,pAvgTrainImg,projectedTestFace);

    iNearest = findNearestNeighbor (projectedTestFace);
    truth = personNumTruthMat -> data.i [i];
    nearest = trainPersonNumMat -> data.i [iNearest];

    printf ("nearest = %d, Truth=%d\n" , nearest, truth);
  }
}

int loadTrainingData (CvMat ** pTrainPersonNumMat)
{
  CvFileStorage * fileStorage;
  int i;

  fileStorage=cvOpenFileStorage ("facedata.xml", 0, CV_STORAGE_READ);
  if (!fileStorage)
  {
   fprintf (stderr, "can't open facedata.xml\n");
  }

  nEigens = cvReadIntByName (fileStorage, 0, "nEigens", 0);
  nTrainFaces = cvReadIntByName (fileStorage, 0, "nTrainFaces", 0);
  *pTrainPersonNumMat = (CvMat *)cvReadByName (fileStorage, 0, "trainPersonNumMat", 0);
  eigenValMat = (CvMat *) cvReadByName (fileStorage,0, "eigenValMat", 0);
  projectedTrainFaceMat =(CvMat *)cvReadByName(fileStorage,0, "projectedTrainFaceMat", 0);
  pAvgTrainImg = (IplImage *)cvReadByName(fileStorage,0, "avgTrainImg",0);
  eigenVectArr = (IplImage **) cvAlloc (nTrainFaces * sizeof (IplImage *));
  for (i=0; i<nEigens; i++)
  {
   char varname[200];
   sprintf (varname, "eigenVect_%d", i);
   eigenVectArr[i]= (IplImage *)cvReadByName(fileStorage, 0, varname, 0);
  }

  cvReleaseFileStorage (&fileStorage);

  return 1;
}

int findNearestNeighbor (float * projectedTestFace)
{
  double leastDistSq = DBL_MAX;
  int i, iTrain, iNearest =0;

  for (iTrain =0; iTrain<nTrainFaces;iTrain ++)
  {
   double distSq=0;

   for (i=0; i<nEigens; i++)
   {
    float d_i=projectedTestFace[i]- projectedTrainFaceMat-> data.fl[iTrain * nEigens + i];
     distSq +=d_i * d_i;
   }

  if (distSq < leastDistSq)
  {
   leastDistSq = distSq;
   iNearest = iTrain;
  }
  }

 return iNearest;
}
[/TEX]

from the highlight, it cant resolve the external symbol cvEigenDecomposite and cvCalcEigenObjects...anyone..can help me...:(

1)'eigenVectArr' : undeclared identifier
2)'f1' : is not a member of '__unnamed'
3)'filename' : undeclared identifier
4)syntax error : '%'
5)'main' : 'void' function returning a value
6) see declaration of 'main'
7)'i' : redefinition
8)'=' : cannot convert from 'struct _IplImage ** ' to 'int'
9) subscript requires array or pointer type
10)'=' : cannot convert from 'struct _IplImage *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
11) 'caclLimit' : undeclared identifier
12)'f1' : is not a member of '__unnamed'
13) 'cvAttrList' : cannot convert parameter 1 from 'const double' to 'const char ** '
There is no context in which this conversion is possible
14) 'i' : redefinition
15) 'cvWrite' : cannot convert parameter 3 from 'int' to 'const void *'
Conversion from integral type to pointer type requires reinterpret_cast,

I just don't understand how on earth did you manage to stack up so many different type of errors. While you were writing this, have you ever compiled it? It is a mess, and now asking us to fix your code is cruel, and unfair. :( LRRR doesn't like it.

1)'eigenVectArr' : undeclared identifier
2)'f1' : is not a member of '__unnamed'
3)'filename' : undeclared identifier
4)syntax error : '%'
5)'main' : 'void' function returning a value
6) see declaration of 'main'
7)'i' : redefinition
8)'=' : cannot convert from 'struct _IplImage ** ' to 'int'
9) subscript requires array or pointer type
10)'=' : cannot convert from 'struct _IplImage *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
11) 'caclLimit' : undeclared identifier
12)'f1' : is not a member of '__unnamed'
13) 'cvAttrList' : cannot convert parameter 1 from 'const double' to 'const char ** '
There is no context in which this conversion is possible
14) 'i' : redefinition
15) 'cvWrite' : cannot convert parameter 3 from 'int' to 'const void *'
Conversion from integral type to pointer type requires reinterpret_cast,

I just don't understand how on earth did you manage to stack up so many different type of errors. While you were writing this, have you ever compiled it? It is a mess, and now asking us to fix your code is cruel, and unfair. :( LRRR doesn't like it.

i have fix my code..and after i fix and compile i had a problem...iam also newbie in this language..so i need a guide from the person who expect..so that i asked a help from who want to help me..if you don't want help me it's ok....

Why don't you close this thread and start a new one with whatever problem you are now having?

commented: Exactly.... +0

Why don't you close this thread and start a new one with whatever problem you are now having?

ok..anyway thank you for those who help me alot...

:@ please solve this program for me
print series of 20 numbers and show the minimum value

@TAnzila Akbar, please start a new post with your question so this one can be closed or solved.

@TAnzila Akbar, please start a new post with your question so this one can be closed or solved.

my prob it had been solve already..tq :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.