KeyPointHelper.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  KeyPointHelper.cpp
00003  *
00004  *  (C) 2007 AG Aktives Sehen <agas@uni-koblenz.de>
00005  *           Universitaet Koblenz-Landau
00006  *******************************************************************************/
00007 
00008 #include "KeyPointHelper.h"
00009 
00010 #include <algorithm>
00011 
00012 #define THIS KeyPointHelper
00013 
00014 void THIS::bBoxFilter( std::vector< KeyPoint > keyPointsIn, std::vector< KeyPoint >& keyPointsOut,
00015                               Box2D<> boundingBox )
00016 {
00017   keyPointsOut.clear();
00018   keyPointsOut.reserve ( keyPointsIn.size() );
00019   for ( unsigned i = 0; i < keyPointsIn.size(); i++ )
00020   {
00021     if ( boundingBox.contains ( keyPointsIn[i].x, keyPointsIn[i].y ) )
00022     {
00023       keyPointsOut.push_back ( keyPointsIn[i] );
00024     }
00025   }
00026 }
00027 
00028 void THIS::imageBorderFilter( std::vector< KeyPoint > keyPointsIn, std::vector< KeyPoint >& keyPointsOut, int imgWidth, int imgHeight )
00029 {
00030   const double border = 17;
00031   keyPointsOut.clear();
00032   for ( unsigned i = 0; i < keyPointsIn.size(); i++ )
00033   {
00034     // ignore points that are too close to the edge of the image
00035     const unsigned long border_size = static_cast<unsigned long> ( border * keyPointsIn[i].scale );
00036     Box2D<int> imageBBox ( 0, 0, imgWidth, imgHeight );
00037     imageBBox.shrink( border_size );
00038 
00039     if ( imageBBox.contains( keyPointsIn[i].x, keyPointsIn[i].y ) )
00040     {
00041       keyPointsOut.push_back ( keyPointsIn[i] );
00042     }
00043   }
00044 }
00045 
00046 void THIS::maskFilter( std::vector< KeyPoint > keyPointsIn, std::vector< KeyPoint >& keyPointsOut,
00047                               ImageMask& mask )
00048 {
00049   keyPointsOut.clear();
00050   keyPointsOut.reserve ( keyPointsIn.size() );
00051   for ( unsigned i = 0; i < keyPointsIn.size(); i++ )
00052   {
00053     //if ( mask.findValue ( keyPointsIn[i].x, keyPointsIn[i].y, ImageMask::VISIBLE, 1 ) )
00054     if ( !mask.findValue ( keyPointsIn[i].x, keyPointsIn[i].y, ImageMask::MASKED, keyPointsIn[i].scale* 4.5/1.2 / 2.0 ) )
00055     {
00056       keyPointsOut.push_back ( keyPointsIn[i] );
00057     }
00058   }
00059 }
00060 
00061 bool strengthComp( KeyPoint& a, KeyPoint& b )
00062 {
00063   return ( a.strength > b.strength );
00064 }
00065 
00066 void THIS::getStrongest( std::vector< KeyPoint > keyPointsIn, std::vector< KeyPoint >& keyPointsOut, unsigned numKeyPoints )
00067 {
00068   if ( keyPointsIn.size() < numKeyPoints )
00069   {
00070     // TRACE_ERROR( "Not enough keypoints!" ); // TODO use ros
00071     numKeyPoints = keyPointsIn.size();
00072   }
00073   keyPointsOut.assign( numKeyPoints, KeyPoint() );
00074   partial_sort_copy( keyPointsIn.begin(), keyPointsIn.end(), keyPointsOut.begin(), keyPointsOut.end(), strengthComp );
00075 }
00076 
00077 void THIS::sortByStrength( std::vector< KeyPoint > keyPointsIn, std::vector< KeyPoint >& keyPointsOut )
00078 {
00079   keyPointsOut.assign( keyPointsIn.size(), KeyPoint() );
00080   partial_sort_copy( keyPointsIn.begin(), keyPointsIn.end(), keyPointsOut.begin(), keyPointsOut.end(), strengthComp );
00081 }
00082 
00083 #undef THIS
00084 


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