HoughIndexCalculator.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  HoughIndexCalculator.cpp
00003  *
00004  *  (C) 2007 AG Aktives Sehen <agas@uni-koblenz.de>
00005  *           Universitaet Koblenz-Landau
00006  *
00007  *  Additional information:
00008  *  $Id: $
00009  *******************************************************************************/
00010 
00011 #include "HoughIndexCalculator.h"
00012 
00013 //#include "Architecture/Tracer/Tracer.h" // TODO
00014 //#include "Architecture/Config/Config.h" // TODO
00015 
00016 #include "Workers/Math/Math.h"
00017 #include "Workers/Puma2/GrayLevelImage8.h"
00018 
00019 #include "ImageProperties.h"
00020 
00021 #include "Workers/Math/vec2.h"
00022 
00023 #include <algorithm>    // for max_element
00024 #include <assert.h>
00025 #include <map>
00026 #include <list>
00027 #include <math.h>
00028 #include <cstring>
00029 
00030 #include <fstream>
00031 
00032 using namespace std;
00033 
00034 #define THIS HoughIndexCalculator
00035 
00036 void THIS::calculateScaleIndex(double scaleQuotient, int& scaleIndexFloor, int& scaleIndexCeil)
00037 {
00038   int scaleBins = 1; // TODO Config::getInt( "ObjectRecognition.HoughClustering.iScaleBins" );
00039 
00040   //( log2( scaleQuotient ) -> anzahl der verdoppelungen(octaven) und halbierungen(octaven)  log2( ]0..inf] ) = [-inf..inf]
00041   //( log2( scaleQuotient ) / (maxOctaves-1) -> [-inf..inf] (-1 damit scalierung 1 und nicht nur octaven dazukommen)
00042   //( log2( scaleQuotient ) / (maxOctaves-1) / 2 + 0.5 ) -> wertebereich verschieben (bei scaleQuotient < 1 ist log2 negativ)
00043   //( log2( scaleQuotient ) / (maxOctaves-1) / 2 + 0.5 ) * scaleBins; -> auf anzahl der bins hochskalieren
00044 
00045   //Bsp: scaleQuotient 0.5 -> bin 3
00046   //Bsp: scaleQuotient 1 -> bin 5, also noch verdoppelungen und 4 halbierungen möglich
00047   //Bsp: scaleQuotient 2 -> bin 6
00048 
00049   /* Scale Index: a factor of 2 for scale (log2), 1/4 size to 4 times */
00050   int maxOctaves=5;
00051   float scaleIndex = ( log2( scaleQuotient ) / (maxOctaves-1) / 2 + 0.5 ) * scaleBins;
00052 
00053   //put all scales that are too large in last bin for ceil
00054   if ( scaleIndex >= scaleBins ) {
00055     scaleIndex = scaleBins-1;
00056   }
00057 
00058   if ( scaleIndex < 0 ) {
00059     scaleIndex = 0;
00060   }
00061 
00062   scaleIndexFloor = scaleIndex;
00063   scaleIndexCeil = scaleIndex+1;
00064 
00065   if(scaleIndexCeil >= scaleBins)
00066   {
00067     scaleIndexCeil = scaleBins-1;
00068   }
00069 }
00070 
00071 void THIS::calculateOrientationIndex(double turnAngle, int& orientationFloor, int& orientationCeil)
00072 {
00073   int orientationBins = 1; // TODO Config::getInt( "ObjectRecognition.HoughClustering.iOrientationBins" );
00074 
00075   //turnAngle in radians (-PI to PI)
00076   
00077   if(turnAngle<-M_PI || turnAngle>M_PI)
00078   {
00079     // TRACE_ERROR("Orientation "<< turnAngle); // TODO use ros
00080   }
00081 
00082   //( turnAngle+M_PI ) -> [0..2*PI]
00083   //( turnAngle+M_PI ) /M_PI/2.0 -> [0..1]
00084   //( turnAngle+M_PI ) /M_PI/2.0 * orientationBins -> [0..orientationBins] float
00085 
00086   float orientationIndex = ( turnAngle+M_PI ) /M_PI/2.0 * orientationBins;
00087 
00088   assert( orientationIndex >= 0.0 );
00089 
00090   //int(orientationIndex) % orientationBins; -> [0..orientationBins] int
00091   orientationFloor = int(orientationIndex) % orientationBins;
00092   orientationCeil = ( orientationFloor+1 ) % orientationBins;
00093 }
00094 
00095 void THIS::calculatePositionIndex(KeyPoint sceneKeyPoint, KeyPoint objectKeyPoint, Point2D center, int w, int h, int& xDistanceFloor, int& xDistanceCeil, int& yDistanceFloor, int& yDistanceCeil)
00096 {
00097   int xLocationBins = 10; // TODO Config::getInt( "ObjectRecognition.HoughClustering.iXLocationBins" );
00098   int yLocationBins = 10; // TODO Config::getInt( "ObjectRecognition.HoughClustering.iYLocationBins" );
00099 
00100   //calculate offset between object and scene keypoints
00101   Point2D objectPoint = objectKeyPoint.position();
00102   Point2D scenePoint = sceneKeyPoint.position();
00103 
00104   //points from objectPoint to objectCenter
00105   Point2D v = center - objectPoint;
00106   v *= sceneKeyPoint.scale/ objectKeyPoint.scale;
00107   v.rotate ( Math::minTurnAngle(sceneKeyPoint.orientation, objectKeyPoint.orientation) );
00108 
00109   //position of object center in scene
00110   Point2D centerScene = v + scenePoint;
00111 
00112   //compute index depending on image dimension
00113   float xPositionIndex = (centerScene.x()/w)*xLocationBins;
00114   float yPositionIndex = (centerScene.y()/h)*yLocationBins;
00115 
00116   //values could be equal at border (don't just use ceil() and floor() )
00117   xDistanceFloor = xPositionIndex;
00118   xDistanceCeil = xDistanceFloor+1;
00119 
00120   yDistanceFloor = yPositionIndex;
00121   yDistanceCeil = yDistanceFloor+1;
00122 }
00123 
00124 #undef THIS


obj_rec_gui
Author(s): AGAS/agas@uni-koblenz.de
autogenerated on Mon Oct 6 2014 02:53:43