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??