Changeset 94
- Timestamp:
- 07/23/2009 01:04:04 PM (10 years ago)
- Location:
- foam/trunk
- Files:
-
- 14 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
foam/trunk/eigentools/src/main.cpp
r93 r94 40 40 PCA pca(w*h); 41 41 Vector<float> params(100); 42 Image src(" data/dave.png");42 Image src("../data/images/faces/dave/dave.png"); 43 43 44 44 void Recalc() … … 46 46 glob_t g; 47 47 48 glob(" data/spacek-large/*.png",GLOB_PERIOD,NULL,&g);48 glob("../data/images/faces/spacek-large/*.png",GLOB_PERIOD,NULL,&g); 49 49 for (unsigned int n=0; n<g.gl_pathc; n++) 50 50 { … … 68 68 //pca.Save(f); 69 69 70 FILE *f=fopen(" spacek-50x80.pca", "rb");70 FILE *f=fopen("../data/eigenspaces/spacek-50x80.pca", "rb"); 71 71 pca.Load(f); 72 72 fclose(f); … … 236 236 ////////////////////////////////// 237 237 // test the debayering 238 /*Image im(" data/bayer.pgm");238 /*Image im("../data/images/bayer.pgm"); 239 239 im.Crop(300,300,320,240); 240 240 im.RGB2GRAY(); … … 245 245 /* 246 246 vector<Image> imagevec; 247 //imagevec.push_back(Image(" data/audrey.png"));248 imagevec.push_back(Image(" data/dave-1.png"));249 imagevec.push_back(Image(" data/dave-2.png"));250 imagevec.push_back(Image(" data/amber-1.png"));251 imagevec.push_back(Image(" data/amber-2.png"));252 //imagevec.push_back(Image(" data/false.png"));247 //imagevec.push_back(Image("../data/audrey.png")); 248 imagevec.push_back(Image("../data/dave-1.png")); 249 imagevec.push_back(Image("../data/dave-2.png")); 250 imagevec.push_back(Image("../data/amber-1.png")); 251 imagevec.push_back(Image("../data/amber-2.png")); 252 //imagevec.push_back(Image("../data/false.png")); 253 253 254 254 for(unsigned int x=0; x<imagevec.size(); x++) -
foam/trunk/faceident/Makefile
r91 r94 5 5 src/Face.cpp\ 6 6 src/ImageUtils.cpp\ 7 src/SceneState.cpp 7 src/SceneState.cpp\ 8 src/tinyxml.cpp\ 9 src/tinyxmlerror.cpp\ 10 src/tinyxmlparser.cpp 8 11 9 12 # for the minute, go out and up to link to the vision lib 10 CCFLAGS = -I../vision/src`pkg-config --cflags opencv` -ggdb -Wall -O3 -ffast-math -Wno-unused -DTIXML_USE_STL11 LDFLAGS = -L../vision/12 LIBS = `pkg-config --libs opencv` -lYARP_dev -lYARP_sig -lYARP_OS -lACE -lvision13 CCFLAGS = `pkg-config --cflags opencv` -ggdb -Wall -O3 -ffast-math -Wno-unused -DTIXML_USE_STL 14 LDFLAGS = 15 LIBS = `pkg-config --libs opencv` -lYARP_dev -lYARP_sig -lYARP_OS -lACE 13 16 14 17 CC = g++ -
foam/trunk/vision/src/Classifier.cpp
r86 r94 29 29 } 30 30 31 void Classifier::AddFeature (int group, const Vector<float> &v)31 void Classifier::AddFeatureToGroup(int group, const Vector<float> &v) 32 32 { 33 33 assert(v.Size()==m_FeatureSize); 34 34 m_Features[group].push_back(v); 35 // possibly overkill to do this each time we add a new feature... 36 CalcGroupMeans(); 35 37 } 36 38 … … 50 52 m_Mean/=m_FeatureSize; 51 53 } 54 55 void Classifier::CalcGroupMeans() 56 { 57 for (FeatureMap::iterator i=m_Features.begin(); 58 i!=m_Features.end(); ++i) 59 { 60 Vector<float> mean; 61 for (FeatureVec::iterator vi = i->second.begin(); vi!=i->second.end(); ++vi) 62 { 63 mean+=*vi; 64 } 65 mean/=i->second.size(); 66 m_GroupMeans[i->first]=mean; 67 } 68 } 69 -
foam/trunk/vision/src/Classifier.h
r90 r94 32 32 ~Classifier(); 33 33 34 v oid AddFeature(int group, const Vector<float> &f);35 virtual int Classify(const Vector<float> &f ) = 0;34 virtual void AddFeature(int group, const Vector<float> &f) = 0; 35 virtual int Classify(const Vector<float> &f, float &error) = 0; 36 36 37 37 protected: 38 38 39 void CalcMean(); 39 40 void CalcGroupMeans(); 41 void AddFeatureToGroup(int group, const Vector<float> &f); 42 40 43 typedef std::vector<Vector<float> > FeatureVec; 41 44 typedef std::map<int,FeatureVec> FeatureMap; … … 47 50 48 51 Vector<float> m_Mean; 49 52 std::map<int,Vector<float> > m_GroupMeans; 50 53 }; 51 54 -
foam/trunk/vision/src/Image.cpp
r93 r94 171 171 cvReleaseImage(&m_Image); 172 172 m_Image=newimage; 173 } 174 175 Image Image::SubImage(int x, int y, int w, int h) 176 { 177 CvRect roi; 178 roi.x=x; 179 roi.y=y; 180 roi.width=w; 181 roi.height=h; 182 IplImage *newimage; 183 cvSetImageROI(m_Image,roi); 184 newimage = cvCreateImage( cvSize(roi.width, roi.height), m_Image->depth, m_Image->nChannels ); 185 cvCopy(m_Image,newimage); 186 cvReleaseImage(&m_Image); 187 return newimage; 173 188 } 174 189 -
foam/trunk/vision/src/Image.h
r90 r94 25 25 { 26 26 public: 27 Image() : m_Image(NULL) {} 27 28 Image(int w, int h, int d, int c); 28 29 Image(const std::string &filename); … … 42 43 void Crop(int x, int y, int w, int h); 43 44 Image Scale(int w, int h); 45 Image SubImage(int x, int y, int w, int h); 44 46 45 47 // Paste an image into this one -
foam/trunk/vision/src/PCA.cpp
r90 r94 77 77 } 78 78 79 Vector<float> PCA::Project(Vector<float> v) 79 Vector<float> PCA::Project(Vector<float> v) const 80 80 { 81 81 return m_EigenTransform*v; 82 82 } 83 83 84 Vector<float> PCA::Synth(Vector<float> v) 84 Vector<float> PCA::Synth(Vector<float> v) const 85 85 { 86 86 return m_Mean+m_EigenTransform.VecMulTransposed(v); -
foam/trunk/vision/src/PCA.h
r90 r94 41 41 void Compress(unsigned int s, unsigned int e); 42 42 43 Vector<float> Project(Vector<float> v) ;44 Vector<float> Synth(Vector<float> v) ;43 Vector<float> Project(Vector<float> v) const; 44 Vector<float> Synth(Vector<float> v) const; 45 45 46 46 static void RunTests(); 47 47 48 const Vector<float> &GetEigenValues() { return m_EigenValues; } 49 const Matrix<float> &GetEigenTransform() { return m_EigenTransform; } 50 const FeatureVec &GetFeatures() { return m_Features; } 51 const Vector<float> &GetMean() { return m_Mean; } 48 const Vector<float> &GetEigenValues() const { return m_EigenValues; } 49 const Matrix<float> &GetEigenTransform() const { return m_EigenTransform; } 50 const FeatureVec &GetFeatures() const { return m_Features; } 51 const Vector<float> &GetMean() const { return m_Mean; } 52 unsigned int GetFeatureSize() const { return m_FeatureSize; } 52 53 53 54 -
foam/trunk/vision/src/PCAClassifier.cpp
r89 r94 15 15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 16 17 #include <cfloat> 17 18 #include "PCAClassifier.h" 18 19 19 PCAClassifier::PCAClassifier(unsigned int FeatureSize) : 20 Classifier(FeatureSize) 20 using namespace std; 21 22 PCAClassifier::PCAClassifier(const PCA &pca) : 23 Classifier(pca.GetFeatureSize()), 24 m_PCA(pca) 21 25 { 22 26 } … … 26 30 } 27 31 32 void PCAClassifier::AddFeature(int group, const Vector<float> &f) 33 { 34 AddFeatureToGroup(group, m_PCA.Project(f)); 35 } 28 36 37 int PCAClassifier::Classify(const Vector<float> &f, float &error) 38 { 39 Vector<float> params=m_PCA.Project(f); 40 41 // find the closest point in all the group means 42 error = FLT_MAX; 43 int ret=-1; 44 for (map<int,Vector<float> >::iterator i=m_GroupMeans.begin(); 45 i!=m_GroupMeans.end(); ++i) 46 { 47 float d=params.DistanceFrom(i->second); 48 if (d<error) 49 { 50 ret=i->first; 51 error=d; 52 } 53 } 54 55 return ret; 56 } 57 58 void PCAClassifier::Refresh() 59 { 60 61 } 62 -
foam/trunk/vision/src/PCAClassifier.h
r89 r94 21 21 #include "Matrix.h" 22 22 #include "Classifier.h" 23 #include "PCA.h" 23 24 24 25 #ifndef FOAM_PCA_CLASSIFIER … … 28 29 { 29 30 public: 30 PCAClassifier( unsigned int FeatureSize);31 PCAClassifier(const PCA &pca); 31 32 ~PCAClassifier(); 32 33 34 // take image vectors in internally uses pca space parameters 35 virtual void AddFeature(int group, const Vector<float> &f); 36 virtual int Classify(const Vector<float> &f, float &error); 37 33 38 private: 34 35 39 void Refresh(); 40 41 PCA m_PCA; 36 42 37 43 };
Note: See TracChangeset
for help on using the changeset viewer.