Keypoint.H
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef KEYPOINT_H_DEFINED
00039 #define KEYPOINT_H_DEFINED
00040
00041 #include "Component/ModelManager.H"
00042 #include "Raster/Raster.H"
00043 #include "Util/Types.H"
00044 #include "Util/Assert.H"
00045 #include "rutz/shared_ptr.h"
00046 #include <vector>
00047 #include <iosfwd>
00048
00049
00050
00051
00052
00053
00054
00055
00056 class Keypoint
00057 {
00058 public:
00059 enum CHANNEL {ORI, COL};
00060
00061
00062
00063
00064
00065 Keypoint();
00066
00067
00068 Keypoint(const std::vector<byte>& features, const float x, const float y,
00069 const float s, const float o, const float dogmag);
00070
00071
00072 Keypoint(const std::vector<byte>& features,
00073 const std::vector<byte>& colFeatures,
00074 const float x, const float y,
00075 const float s, const float o, const float dogmag,
00076 float oriWeight=1.0F, float colWeight=1.0F);
00077
00078
00079 Keypoint(const Keypoint& k);
00080
00081
00082 void reset(const std::vector<byte>& features,
00083 const float x, const float y,
00084 const float s, const float o, const float dogmag);
00085
00086
00087 ~Keypoint();
00088
00089
00090 Keypoint& operator=(const Keypoint& k);
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 typedef std::vector<byte>::iterator iterator;
00103
00104
00105 typedef std::vector<byte>::const_iterator const_iterator;
00106
00107
00108 inline const_iterator begin(CHANNEL channel=ORI) const;
00109
00110
00111 inline const_iterator end(CHANNEL channel=ORI) const;
00112
00113
00114 inline iterator beginw(CHANNEL channel=ORI);
00115
00116
00117 inline iterator endw(CHANNEL channel=ORI);
00118
00119
00120 inline float getX() const;
00121
00122
00123 inline float getY() const;
00124
00125
00126 inline float getS() const;
00127
00128
00129 inline float getO() const;
00130
00131
00132 inline float getM() const;
00133
00134
00135 inline uint getFVlength(CHANNEL channel=ORI) const;
00136
00137
00138 inline byte getFVelement(const uint index, CHANNEL channel=ORI) const;
00139
00140
00141 inline std::vector<byte> getOriFV() { return itsOriFV; };
00142
00143
00144 inline std::vector<byte> getColFV() { return itsColFV; };
00145
00146
00147
00148
00149
00150
00151
00152 inline int distSquared(const rutz::shared_ptr<Keypoint>& k) const;
00153
00154
00155
00156 inline int maxDistSquared(CHANNEL channel=ORI) const;
00157
00158
00159
00160
00161
00162
00163 inline bool operator<(const Keypoint& k) const;
00164
00165
00166
00167
00168 protected:
00169 float itsX;
00170 float itsY;
00171 float itsS;
00172 float itsO;
00173 float itsM;
00174 std::vector<byte> itsOriFV;
00175 std::vector<byte> itsColFV;
00176 float itsOriWeight;
00177 float itsColWeight;
00178
00179
00180 private:
00181 friend std::istream& operator>>(std::istream& is, Keypoint& k);
00182 friend std::ostream& operator<<(std::ostream& os, const Keypoint& k);
00183 };
00184
00185
00186
00187
00188
00189
00190 std::istream& operator>>(std::istream& is, Keypoint& k);
00191
00192
00193 std::ostream& operator<<(std::ostream& os, const Keypoint& k);
00194
00195
00196
00197
00198 inline Keypoint::const_iterator Keypoint::begin(CHANNEL channel) const
00199 {
00200 switch (channel){
00201 case ORI:
00202 return itsOriFV.begin();
00203 case COL:
00204 return itsColFV.begin();
00205 default:
00206 return itsOriFV.begin();
00207 }
00208 }
00209
00210 inline Keypoint::const_iterator Keypoint::end(CHANNEL channel) const
00211 {
00212 switch (channel){
00213 case ORI:
00214 return itsOriFV.end();
00215 case COL:
00216 return itsColFV.end();
00217 default:
00218 return itsOriFV.end();
00219 }
00220 }
00221
00222
00223 inline Keypoint::iterator Keypoint::beginw(CHANNEL channel)
00224 {
00225 switch (channel){
00226 case ORI:
00227 return itsOriFV.begin();
00228 case COL:
00229 return itsColFV.begin();
00230 default:
00231 return itsOriFV.begin();
00232 }
00233 }
00234
00235 inline Keypoint::iterator Keypoint::endw(CHANNEL channel)
00236 {
00237 switch (channel){
00238 case ORI:
00239 return itsOriFV.end();
00240 case COL:
00241 return itsColFV.end();
00242 default:
00243 return itsOriFV.end();
00244 }
00245 }
00246
00247
00248 inline float Keypoint::getX() const
00249 { return itsX; }
00250
00251 inline float Keypoint::getY() const
00252 { return itsY; }
00253
00254 inline float Keypoint::getS() const
00255 { return itsS; }
00256
00257 inline float Keypoint::getO() const
00258 { return itsO; }
00259
00260 inline float Keypoint::getM() const
00261 { return itsM; }
00262
00263 inline uint Keypoint::getFVlength(CHANNEL channel) const
00264 {
00265 switch (channel){
00266 case ORI:
00267 return itsOriFV.size();
00268 case COL:
00269 return itsColFV.size();
00270 default:
00271 return itsOriFV.size();
00272 }
00273 }
00274
00275 inline byte Keypoint::getFVelement(const uint index,CHANNEL channel) const
00276 {
00277 switch (channel){
00278 case ORI:
00279 ASSERT(index < itsOriFV.size());
00280 return itsOriFV[index];
00281 case COL:
00282 ASSERT(index < itsColFV.size());
00283 return itsColFV[index];
00284 default:
00285 ASSERT(index < itsOriFV.size());
00286 return itsOriFV[index];
00287 }
00288 }
00289
00290 inline int Keypoint::distSquared(const rutz::shared_ptr<Keypoint>& k) const
00291 {
00292 int oriDistsq = 0;
00293 int colDistsq = 0;
00294
00295 ASSERT(itsOriFV.size() == k->itsOriFV.size());
00296 if (itsColFV.size() > 0)
00297 ASSERT(itsColFV.size() == k->itsColFV.size());
00298
00299 Keypoint::const_iterator oriF1 = begin(ORI), oriF2 = k->begin(ORI),
00300 oriStop = end(ORI);
00301
00302 while(oriF1 != oriStop)
00303 {
00304 const int of1 = int(*oriF1++);
00305 const int of2 = int(*oriF2++);
00306 const int dif = of1 - of2;
00307 oriDistsq += dif * dif;
00308 }
00309
00310 if (itsColFV.size() > 0) {
00311 Keypoint::const_iterator colF1 = begin(COL), colF2 = k->begin(COL),
00312 colStop = end(COL);
00313 while(colF1 != colStop)
00314 {
00315 const int dif = int(*colF1++) - int(*colF2++);
00316 colDistsq += dif * dif;
00317 }
00318 }
00319
00320 return int(itsOriWeight*float(oriDistsq) + itsColWeight*float(colDistsq));
00321
00322 }
00323
00324 inline int Keypoint::maxDistSquared(CHANNEL channel) const
00325 {
00326 switch (channel){
00327 case ORI:
00328 return 255 * 255 * itsOriFV.size();
00329 case COL:
00330 return 255 * 255 * itsColFV.size();
00331 default:
00332 return 255 * 255 * itsOriFV.size();
00333 }
00334 }
00335
00336 inline bool Keypoint::operator<(const Keypoint& k) const
00337 { return (itsM < k.itsM); }
00338
00339 #endif
00340
00341
00342
00343
00344
00345