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 #include <ros/ros.h>
00012 
00013 #define THIS KeyPointHelper
00014 
00015 void THIS::bBoxFilter( std::vector< KeyPoint > keyPointsIn, std::vector< KeyPoint >& keyPointsOut,
00016                               Box2D<> boundingBox )
00017 {
00018   keyPointsOut.clear();
00019   keyPointsOut.reserve ( keyPointsIn.size() );
00020   for ( unsigned i = 0; i < keyPointsIn.size(); i++ )
00021   {
00022     if ( boundingBox.contains ( keyPointsIn[i].x, keyPointsIn[i].y ) )
00023     {
00024       keyPointsOut.push_back ( keyPointsIn[i] );
00025     }
00026   }
00027 }
00028 
00029 void THIS::imageBorderFilter( std::vector< KeyPoint > keyPointsIn, std::vector< KeyPoint >& keyPointsOut, int imgWidth, int imgHeight )
00030 {
00031   const double border = 17;
00032   keyPointsOut.clear();
00033   for ( unsigned i = 0; i < keyPointsIn.size(); i++ )
00034   {
00035     // ignore points that are too close to the edge of the image
00036     const unsigned long border_size = static_cast<unsigned long> ( border * keyPointsIn[i].scale );
00037     Box2D<int> imageBBox ( 0, 0, imgWidth, imgHeight );
00038     imageBBox.shrink( border_size );
00039 
00040     if ( imageBBox.contains( keyPointsIn[i].x, keyPointsIn[i].y ) )
00041     {
00042       keyPointsOut.push_back ( keyPointsIn[i] );
00043     }
00044   }
00045 }
00046 
00047 void THIS::maskFilter( std::vector< KeyPoint > keyPointsIn, std::vector< KeyPoint >& keyPointsOut,
00048                               ImageMaskCV& mask )
00049 {
00050   keyPointsOut.clear();
00051   keyPointsOut.reserve ( keyPointsIn.size() );
00052   for ( unsigned i = 0; i < keyPointsIn.size(); i++ )
00053   {
00054     if ( !mask.findValue ( keyPointsIn[i].x, keyPointsIn[i].y, ImageMaskCV::MASKED, keyPointsIn[i].scale* 4.5/1.2 / 2.0 ) )
00055     {
00056       keyPointsOut.push_back ( keyPointsIn[i] );
00057     }
00058   }
00059 }
00060 
00061 
00062 bool strengthComp( KeyPoint& a, KeyPoint& b )
00063 {
00064   return ( a.strength > b.strength );
00065 }
00066 
00067 void THIS::getStrongest( std::vector< KeyPoint > keyPointsIn, std::vector< KeyPoint >& keyPointsOut, unsigned numKeyPoints )
00068 {
00069   if ( keyPointsIn.size() < numKeyPoints )
00070   {
00071     ROS_ERROR_STREAM( "Not enough keypoints!" );
00072     numKeyPoints = keyPointsIn.size();
00073   }
00074   keyPointsOut.assign( numKeyPoints, KeyPoint() );
00075   partial_sort_copy( keyPointsIn.begin(), keyPointsIn.end(), keyPointsOut.begin(), keyPointsOut.end(), strengthComp );
00076 }
00077 
00078 void THIS::sortByStrength( std::vector< KeyPoint > keyPointsIn, std::vector< KeyPoint >& keyPointsOut )
00079 {
00080   keyPointsOut.assign( keyPointsIn.size(), KeyPoint() );
00081   partial_sort_copy( keyPointsIn.begin(), keyPointsIn.end(), keyPointsOut.begin(), keyPointsOut.end(), strengthComp );
00082 }
00083 
00084 #undef THIS
00085 


or_libs
Author(s): raphael
autogenerated on Mon Oct 6 2014 02:53:18