Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

fv.h

Go to the documentation of this file.
00001 
00019 #ifndef __FV_H
00020 #define __FV_H
00021 #include <vector>
00022 #include <iostream>
00023 #include <assert.h>
00024 
00025 using namespace std;
00026 
00027 
00032 class Coords : public pair<float,float>{
00033   public : 
00034     Coords( float a=0, float b=0 ) { first = a; second = b; }
00035     //look like the vgl libs version for future association
00036     float x() { return first; }
00037     float y() { return second; }
00038     void set(float in1, float in2 ) {
00039       first = in1; 
00040       second = in2;
00041     }
00042     void print() {
00043       cerr<<" "<<x()<<" "<<y()<<" ";
00044     }
00045 };
00046 
00053 class Feature : public Coords {
00054   public:
00055 
00056     vector<float> descriptor;        
00057 
00058 
00059     float orientation;               
00060     float dx;                        
00061     float dy;                        
00062     float magnitude;                 
00063 
00064     Feature() {
00065       descriptor.reserve(128*sizeof(float));
00066     }
00068     double norm() {                  
00069       double n=0.0;
00070       for( int i=0 ;i<128; i++ ) { 
00071         n += descriptor[i]*descriptor[i];
00072       } 
00073       return sqrt(n);
00074     }
00075 };
00076 
00078 class Scene {
00079   public:
00080     vector<Feature> features;
00081 };
00082 
00083 //typedef pair<Feature *, Feature *> Match ;
00084 
00086 class Match : public pair<Feature *, Feature *> {
00087   public:
00088     Match( Feature *a, Feature *b ) : pair<Feature *,Feature*>( a, b ) {} 
00089 
00091     bool Match::operator==(Match op) {    
00092       return ( ( first==op.first )&&( second==op.second ) );
00093     }
00094 };
00095 
00097 typedef vector<Match> Matches ; 
00098 /*
00101 double distSq( Coords &c0, Coords &c1 ) {
00102   double X,Y;
00103   X = c0.x() - c1.x();
00104   Y = c0.y() - c1.y();
00105   return X*X + Y*Y ;
00106 }
00107 
00108 
00109 float featureDiffSq( Feature &f0, Feature &f1 ) 
00110 {
00111   assert( f0.descriptor.size() == 128 ); 
00112   assert( f1.descriptor.size() == 128 ); 
00113   double ssd = 0.0;
00114   for( int i=0 ; i<128 ; i++ ) {
00115     float diff = (f0.descriptor[i]-f1.descriptor[i]);
00116     ssd += (double)diff*(double)diff;
00117   }
00118   return (float)ssd; 
00119 }
00120 
00121 Feature *findBestMatch( Feature &f0, Scene &s1, float magRadius, float thresh) 
00122 {
00123   float dist1 = 9999;
00124   float dist2 = 9999;
00125 
00126   vector<Feature>::iterator it1, bestMatch ; 
00127 
00128   for( it1 = s1.features.begin() ; it1 != s1.features.end() ; it1++ ) {
00129 
00130     // only check those vectors who have nearby magnitudes (restricts it to 
00131     //  a shell of radius it->magnitude around the origin )
00132 
00133     if( fabsf(f0.magnitude - it1->magnitude) < magRadius*magRadius ) {
00134 
00135       float dist = featureDiffSq ( f0, *it1 );
00136 
00137       if( dist < dist1 ) { 
00138         dist2 = dist1 ;
00139         dist1 = dist ;
00140         bestMatch = it1 ; 
00141       }
00142       else if( dist < dist2 ) {
00143         dist2 = dist;
00144       }//endif
00145 
00146     }//endiff
00147     
00148 
00149   }//endfor
00150 
00151   // returns if the match is well defined (not a noisy clump) 
00152   if( dist1 < thresh*thresh * dist2  ) { 
00153     return &(*bestMatch) ;  
00154   }
00155   else {
00156     return NULL;
00157   }
00158 }
00159 
00160 Matches &findMatches( Scene &s0, 
00161                       Scene &s1, 
00162                       float magRadius , 
00163                       float improvement  ) 
00164 {
00165   Matches *matches = new Matches() ;
00166   vector<Feature>::iterator it0 ;     
00167 
00168   //cerr<<"start\n";
00169   for( it0 = s0.features.begin() ; it0 != s0.features.end() ; it0++ ) {
00170     Feature *bestMatch = NULL;
00171     if( ( bestMatch = findBestMatch( *it0, s1, magRadius, improvement ) ) != NULL ) {
00172       Match *match = new Match( &(*it0), bestMatch  );
00173       matches->push_back( *match );
00174     }
00175   }
00176   //cerr<<"Done "<<matches->size() <<" matches found"<<endl;
00177   return *matches;
00178 }
00179 */
00180 #endif

Generated on Mon Jun 27 14:54:29 2005 for OPENVIDIA by  doxygen 1.4.0