Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

VisualOdometry.h

Go to the documentation of this file.
00001 #ifndef VISUAL_ODOMETRY_H
00002 #define VISUAL_ODOMETRY_H
00003 
00004 #include <math.h>
00005 #include <algorithm>
00006 #include <vector>
00007 
00008 #include "IPC/SharedObject.h"
00009 #include "Motion/HeadPointerMC.h"
00010 #include "Motion/MMAccessor.h"
00011 #include "Shared/mathutils.h"
00012 #include "DualCoding/Sketch.h"
00013 #include "OpticalFlow.h"
00014 
00015 namespace DualCoding {
00016 
00017   //! Generic visual odometry class; can be used for multiple algorithms
00018   class VisualOdometry {
00019   public:
00020     VisualOdometry() : sleeping(true), lastAngle(0.0), lastTranslation(0) {};
00021 
00022     virtual ~VisualOdometry() {}
00023 
00024     virtual void update(bool overrideSleep=false) = 0;
00025     virtual float getAngle() { return lastAngle; }
00026     virtual int getTranslation() { return lastTranslation; }
00027     virtual float getIntegratedAngle() { return 0.0f; }
00028 
00029     //! Set parameters for converting from translation units (pixels) to rotation angle (radians)
00030     virtual void setConversionParameters(float slope, float offset) = 0;
00031 
00032     //! Number of milliseconds between odometry updates.
00033     virtual unsigned int suggestedFrameRate() const = 0;
00034 
00035     //! Number of pixels of translation accross the camera frame per degree of camera rotation.
00036     //static const float ANGULAR_RESOLUTION = 10.0f;
00037     static const float ANGULAR_RESOLUTION;
00038 
00039   protected:
00040     bool sleeping;  //!< True if not currently subscribed to images
00041     float lastAngle;
00042     int lastTranslation;
00043   };
00044 
00045 
00046   //! Optical flow implementation of visual odometry
00047   class OpticalFlowOdometry : public OpticalFlow, public VisualOdometry {
00048   public:
00049     OpticalFlowOdometry(const std::string &dummyName="") :
00050       OpticalFlow(), VisualOdometry(), scalingFactor(ANGULAR_RESOLUTION) {};
00051 
00052     virtual void update(bool overrideSleep=false);
00053 
00054     //! Set parameters for converting from translation units (pixels) to angle (radians)
00055     virtual void setConversionParameters(float slope, float offset);
00056 
00057     virtual float getIntegratedAngle() { return integratedFlow / scalingFactor; }
00058 
00059     //! Number of milliseconds between odometry updates.
00060     virtual unsigned int suggestedFrameRate() const { return 100; }
00061 
00062   private:
00063     float scalingFactor;
00064   };
00065 
00066 
00067   //! Image profile visual odometry.
00068   
00069   class ImageProfileOdometry : public VisualOdometry {
00070   public:
00071     ImageProfileOdometry(const std::string &dummyName="") :
00072       VisualOdometry(), currImageProfile(&profile1),
00073       profile1(RobotInfo::CameraResolutionX), profile2(RobotInfo::CameraResolutionX),
00074       translationProfile(RobotInfo::CameraResolutionX),
00075       angularResolution(ANGULAR_RESOLUTION), slope(ANGULAR_RESOLUTION), offset(0.0f)
00076     {}
00077 
00078     ImageProfileOdometry(const ImageProfileOdometry &other); //!< do not call
00079     virtual ~ImageProfileOdometry() {}
00080     virtual float getAngle();
00081     virtual int getTranslation();
00082     virtual void update(bool sleepOverride=false);
00083 
00084     //! Set parameters for converting from translation units (pixels) to angle (radians)
00085     virtual void setConversionParameters(float slope, float offset);
00086 
00087     //! Number of milliseconds between odometry updates.
00088     virtual unsigned int suggestedFrameRate() const { return  4; }
00089 
00090     float getSlope() { return slope; }
00091     float getOffset() { return offset; }
00092 
00093   protected:
00094     std::vector<float> *currImageProfile;
00095     std::vector<float> profile1;
00096     std::vector<float> profile2;
00097     std::vector<float> translationProfile;
00098 
00099   private:
00100     ImageProfileOdometry & operator=(const ImageProfileOdometry &rhs);
00101     float angularResolution;
00102     float slope;
00103     float offset;
00104 
00105     float differenceMeasure(int s);
00106     int minTranslation();
00107 
00108     //! Convert from translation units (pixels) to angle (radians)
00109     float translationToAngle(int trans);
00110 
00111     //! Builds a translation profile comparing how similar the two image profiles are at different translations.
00112     /*! The horizontal axis is translation, starting at -WIDTH/2 on
00113         the leftmost part of the axis and ending with WIDTH/2 on the right.  
00114 
00115         The vertical axis is the difference measure between the two 
00116         image profiles using the translation at that point on the horizontal axis.
00117       */
00118     void buildImageProfile();
00119 
00120     void displayImageProfile();
00121     void swapCurrentProfile();
00122     void buildTranslationProfile();
00123     void displayTranslationProfile();
00124   };
00125 
00126   typedef OpticalFlowOdometry CurrVisualOdometry;
00127 
00128 }
00129 
00130 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:52 2016 by Doxygen 1.6.3