00001 /*!@file SIFT/Keypoint.C Keypoint for SIFT obj recognition */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: James Bonaiuto <bonaiuto@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/SIFT/Keypoint.C $ 00035 // $Id: Keypoint.C 7506 2006-12-08 06:28:33Z siagian $ 00036 // 00037 00038 #include "SIFT/Keypoint.H" 00039 #include "Util/log.H" 00040 00041 #include <istream> 00042 #include <ostream> 00043 00044 // ####################################################################### 00045 // ####################################################################### 00046 // ########## Keypoint implementation 00047 // ####################################################################### 00048 // ####################################################################### 00049 00050 // ####################################################################### 00051 Keypoint::Keypoint() : 00052 itsX(0.0F), itsY(0.0F), itsS(0.0F), itsM(0.0), itsOriFV(), 00053 itsOriWeight(1.0), itsColWeight(0.0) 00054 { } 00055 00056 // ####################################################################### 00057 Keypoint::Keypoint(const std::vector<byte>& features, const float x, 00058 const float y, const float s, const float o, 00059 const float mag) : 00060 itsX(x), itsY(y), itsS(s), itsO(o), itsM(mag), itsOriFV(features), 00061 itsOriWeight(1.0), itsColWeight(0.0) 00062 { 00063 // note: copy-constructor of std::vector copies the elements from 00064 // 'features' into 'itsOriFV', also resizing itsOriFV. 00065 } 00066 00067 // ####################################################################### 00068 Keypoint::Keypoint(const std::vector<byte>& features, 00069 const std::vector<byte>& colFeatures, 00070 const float x, const float y, const float s, const float o, 00071 const float mag, float oriWeight, float colWeight) : 00072 itsX(x), itsY(y), itsS(s), itsO(o), itsM(mag), 00073 itsOriFV(features), itsColFV(colFeatures), 00074 itsOriWeight(oriWeight), itsColWeight(colWeight) 00075 { 00076 // note: copy-constructor of std::vector copies the elements from 00077 // 'features' into 'itsOriFV' and Color features, also resizing itsOriFV. 00078 } 00079 00080 // ###################################################################### 00081 Keypoint::Keypoint(const Keypoint& k) : 00082 itsX(k.itsX), itsY(k.itsY), itsS(k.itsS), itsO(k.itsO), 00083 itsM(k.itsM), itsOriFV(k.itsOriFV) 00084 { } 00085 00086 // ###################################################################### 00087 void Keypoint::reset(const std::vector<byte>& features, const float x, 00088 const float y, const float s, const float o, 00089 const float mag) 00090 { 00091 itsOriFV = features; // std::vector assignment copies all values 00092 itsX = x; itsY = y; itsS = s; itsO = o; itsM = mag; 00093 } 00094 00095 00096 // ###################################################################### 00097 Keypoint& Keypoint::operator=(const Keypoint& k) 00098 { 00099 itsX = k.itsX; itsY = k.itsY; itsS = k.itsS; itsO = k.itsO; 00100 itsM = k.itsM; itsOriFV = k.itsOriFV; // std::vector assignment copies all values 00101 return *this; 00102 } 00103 00104 // ####################################################################### 00105 Keypoint::~Keypoint() 00106 { } 00107 00108 // ####################################################################### 00109 std::ostream& operator<<(std::ostream& os, const Keypoint& k) 00110 { 00111 const uint siz = k.itsOriFV.size(); 00112 00113 os<<k.itsX<<' '<<k.itsY<<' '<<k.itsS<<' '<<k.itsO<<' ' 00114 <<k.itsM<<' '<<siz<<std::endl; 00115 00116 for (uint i = 0; i < siz; i++) os<<int(k.itsOriFV[i])<<' '; 00117 os<<std::endl; 00118 00119 return os; 00120 } 00121 00122 // ####################################################################### 00123 std::istream& operator>>(std::istream& is, Keypoint& k) 00124 { 00125 uint siz; 00126 is>>k.itsX>>k.itsY>>k.itsS>>k.itsO>>k.itsM>>siz; 00127 00128 k.itsOriFV.clear(); k.itsOriFV.resize(siz); 00129 for (uint j = 0; j < siz; j++) 00130 { 00131 int val; is>>val; 00132 if (val < 0 || val > 255) LFATAL("Bogus file format!"); 00133 k.itsOriFV[j] = byte(val); 00134 } 00135 return is; 00136 } 00137 00138 // ###################################################################### 00139 /* So things look consistent in everyone's emacs... */ 00140 /* Local Variables: */ 00141 /* indent-tabs-mode: nil */ 00142 /* End: */