00001 /*!@file Beobot/Landmark.H Landmark class for localization */ 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: Christian Siagian <siagian@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/Beobot2/Navigation/FOE_Navigation/OpticalFlow.H $ 00035 // $Id: $ 00036 // 00037 00038 #ifndef MOTION_OPTICALFLOW_DEFINED 00039 #define MOTION_OPTICALFLOW_DEFINED 00040 00041 #include "Image/Image.H" 00042 #include "Image/Pixels.H" 00043 #include "Raster/Raster.H" 00044 00045 #include "Robots/LoBot/util/triple.hh" 00046 #include "rutz/shared_ptr.h" 00047 00048 // ###################################################################### 00049 //! a flow vector struct to describe 1 flow vector 00050 //! it also provide motion/flow strength value as well 00051 struct FlowVector 00052 { 00053 FlowVector() { }; 00054 00055 FlowVector(const Point2D<float> inP1, 00056 const Point2D<float> inP2, 00057 const float inVal) : 00058 p1(inP1), 00059 p2(inP2), 00060 val(inVal) 00061 { 00062 angle = atan2(double(p2.j - p1.j), double(p2.i - p1.i))/M_PI * 180; 00063 angle = fmod(angle +360.0, 360.0); 00064 00065 mag = sqrt( pow(p2.j - p1.j, 2.0) + pow(p2.i - p1.i, 2.0) ); 00066 } 00067 00068 FlowVector(const Point2D<float> inP1, 00069 const float inAngle, 00070 const float inMag, 00071 const float inVal) : 00072 p1(inP1), 00073 angle(inAngle), 00074 mag(inMag), 00075 val(inVal) 00076 { 00077 float ang = angle/180.0F * M_PI; 00078 00079 float i = p1.i + (mag * cos(ang)); 00080 float j = p1.j + (mag * sin(ang)); 00081 p2 = Point2D<float>(i,j); 00082 } 00083 00084 Point2D<float> p1; 00085 Point2D<float> p2; 00086 00087 float angle; // should be in degrees 00088 float mag; 00089 float val; 00090 }; 00091 00092 //! an Optical flow class that can return both: 00093 //! a vector of FlowVector: for sparse flow 00094 //! (note: also feed in image size) 00095 //! or a triple of images for direction, length, and strength 00096 class OpticalFlow 00097 { 00098 public: 00099 // ###################################################################### 00100 //! @name Constructor, assigment and destructor 00101 //@{ 00102 00103 //! Constructor taking in sparse flow vector 00104 /*! @param flow the vector of flow vectors in the image 00105 @param dims size of the image 00106 */ 00107 OpticalFlow(std::vector<rutz::shared_ptr<FlowVector> > flowVectors, 00108 Dims dims); 00109 00110 //! Constructor taking in dense flow field 00111 /*! @param flow field of the image 00112 */ 00113 OpticalFlow 00114 (lobot::triple<Image<float>, Image<float>, Image<float> > flowField); 00115 00116 //! Destructor 00117 ~OpticalFlow(); 00118 00119 //@} 00120 00121 // ###################################################################### 00122 //! @name Access functions 00123 //@{ 00124 00125 //! get the flow vectors 00126 std::vector<rutz::shared_ptr<FlowVector> > getFlowVectors(); 00127 00128 //! get the flow vector locations 00129 std::vector<Point2D<float> > getFlowLocations(); 00130 00131 //! get the image dimensions 00132 Dims getImageDims(); 00133 00134 //! get the flow field 00135 lobot::triple<Image<float>,Image<float>,Image<float> > 00136 getFlowField(); 00137 00138 //! get the direction field 00139 Image<float> getDirectionField(); 00140 00141 //! get the vector length field 00142 Image<float> getVectorLengthField(); 00143 00144 //! get the strength field 00145 Image<float> getFlowStrengthField(); 00146 00147 //@} 00148 00149 private: 00150 00151 // ###################################################################### 00152 //! @name Compute functions (all the inner-working functions) 00153 //@{ 00154 00155 //! compute functions to compute (sparse) flow field 00156 //! given flow vectors 00157 void computeFlowField(); 00158 00159 //! compute functions to compute flow vectors 00160 //! given a (what should be a sparse) flow field 00161 void computeFlowVectors(); 00162 00163 //! put the flow locations in one vector 00164 void computeFlowLocations(); 00165 00166 //@} 00167 00168 //! flag to check if the flow field or flow vector is computed 00169 bool itsFlowFieldComputed; 00170 bool itsFlowVectorsComputed; 00171 bool itsFlowLocationsComputed; 00172 00173 std::vector<rutz::shared_ptr<FlowVector> > itsFlowVectors; 00174 00175 //! dimension of the image of the flow 00176 Dims itsImageDims; 00177 00178 //! its flow locations 00179 std::vector<Point2D<float> > itsFlowLocations; 00180 00181 //! Flow field represented by a triple of images: 00182 //! first: direction 00183 //! second: length 00184 //! third: flow strength 00185 //! usually for dense maps 00186 lobot::triple<Image<float>,Image<float>,Image<float> > itsFlowField; 00187 }; 00188 00189 00190 #endif 00191 00192 // ###################################################################### 00193 /* So things look consistent in everyone's emacs... */ 00194 /* Local Variables: */ 00195 /* indent-tabs-mode: nil */ 00196 /* End: */