15 #include <mrpt/otherlibs/do_opencv_includes.h>    32                 unsigned int                    nDesiredFeatures,
    43         const unsigned int MAX_COUNT = 300;
    54                 const cv::Mat 
img( cv::cvarrToMat( inImg.
getAs<IplImage>() ) );
    57                 cout << 
"[KLT] Attach: " << tictac.
Tac()*1000.0f << endl;
    60                 const cv::Mat cGrey( cv::cvarrToMat( inImg_gray.
getAs<IplImage>() ) );
    62                 nDesiredFeatures <= 0 ? nPts = MAX_COUNT : nPts = nDesiredFeatures;
    69                 cout << 
"[KLT] Create: " << tictac.
Tac()*1000.0f << endl;
    76                 const bool use_harris = ( options.featsType == 
featHarris );
    81                 std::vector<cv::Point2f> 
points;
    82                 cv::goodFeaturesToTrack(
    84                         (
double)options.harrisOptions.threshold,    
    85                         (
double)options.harrisOptions.min_distance, 
    89                         options.harrisOptions.k 
    92                 cout << 
"[KLT] Find feats: " << tictac.
Tac()*1000.0f << endl;
    95                 if( nDesiredFeatures > 0 && 
count < nPts )
    96                         cout << 
"\n[WARNING][selectGoodFeaturesKLT]: Only " << 
count << 
" of " << nDesiredFeatures << 
" points could be extracted in the image." << endl;
    98                 if( options.FIND_SUBPIXEL )
   100 #ifdef VERBOSE_TIMING   104                         cv::cornerSubPix(cGrey,
points,
   105                                 cv::Size(3,3), cv::Size(-1,-1),
   106                                 cv::TermCriteria( CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 10, 0.05 ));
   108 #ifdef VERBOSE_TIMING   109                         cout << 
"[KLT] subpixel: " << tictac.
Tac()*1000.0f << endl;
   116 #ifdef VERBOSE_TIMING   121                 unsigned int    borderFeats = 0;
   122                 unsigned int    nCFeats         = init_ID;
   125                 int                             offset          = (int)this->options.patchSize/2 + 1;
   127                 unsigned int    imgW            = inImg.
getWidth();
   131                         const int xBorderInf = (int)floor( 
points[i].
x - options.patchSize/2 );
   132                         const int xBorderSup = (int)floor( 
points[i].
x + options.patchSize/2 );
   133                         const int yBorderInf = (int)floor( 
points[i].
y - options.patchSize/2 );
   134                         const int yBorderSup = (int)floor( 
points[i].
y + options.patchSize/2 );
   136                         if( options.patchSize==0 || ( (xBorderSup < (
int)imgW) && (xBorderInf > 0) && (yBorderSup < (int)imgH) && (yBorderInf > 0) ) )
   146                                 ft->patchSize   = options.patchSize;            
   148                                 if( options.patchSize > 0 )
   167 #ifdef VERBOSE_TIMING   168                 cout << 
"[KLT] Create output: " << tictac.
Tac()*1000.0f << endl;
   173                         THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
   180 MRPT_TODO(
"Delete? Refactor / join to mrpt::vision::CGenericFeatureTracker?")
   188                                                                                         unsigned int nDesiredFeats)
 const   202                 for( itKLT = inList.
begin(); itKLT != inList.
end(); itKLT++ )
   204                         int cx = (int)(*itKLT)->x;
   205                         int cy = (
int)(*itKLT)->y;
   208                         size_t xxI = max( 0, cx - 15 );
   209                         size_t xxE = 
min( cx + 15, 
mask.cols()-1 );
   210                         size_t yyI = max( 0, cy - 15 );
   211                         size_t yyE = 
min( cy + 15, (
int)
mask.rows()-1 );
   213                         for(
size_t yy = yyI; yy < yyE; yy++)
   214                                 for(
size_t xx = xxI; xx < xxE; xx++)
   215                                         cvSet2D( 
mask, yy, xx, zero );
   217                         if( (*itKLT)->ID > mxID )
   221                 selectGoodFeaturesKLT( 
img, outList, mxID + 1, nDesiredFeats, &
mask );
   223         else if( options.featsType == 
featFAST )
   226                 extractFeaturesFAST( 
img, outList, mxID+1 );            
   231                 for( itInList = inList.
begin(); itInList != inList.
end(); ++itInList )
   233                         for( itOutList = outList.
begin(); itOutList != outList.
end(); )
   235                                 if( fabs((*itOutList)->x-(*itInList)->x) < 15 ||  fabs((*itOutList)->y-(*itInList)->y) < 15 )
   236                                         itOutList = outList.
erase( itOutList );
   242                 if( nDesiredFeats != 0 && outList.
size() > nDesiredFeats )
   243                         outList.
resize( nDesiredFeats );
   253 MRPT_TODO(
"Delete? Is not this a duplicate of extractFeaturesKLT ()???")
   258 void  CFeatureExtraction::selectGoodFeaturesKLT(
   261                 unsigned int                    init_ID,
   262                 unsigned int                    nDesiredFeatures)
 const   266         size_t imgW = 
img.getWidth();
   267         size_t imgH = 
img.getHeight();
   270         ASSERT_( imgH > 0 && imgW > 0 );                                                                                                        
   271         ASSERT_( ROI.xMin >= 0 && ROI.yMin >= 0 && ROI.xMax < imgW && ROI.yMax < imgH );        
   274         CvMatrix 
mask( imgH, imgW, CV_8UC1 );
   275         CvScalar zero = cvRealScalar( 0.0 );
   276         CvScalar one = cvRealScalar( 1.0 );
   278         if( ROI.xMin == 0 && ROI.xMax == 0 && ROI.yMin == 0 && ROI.yMax == 0 )          
   280                 if( options.patchSize == 0 )
   281                         selectGoodFeaturesKLT( 
img, feats, init_ID, nDesiredFeatures, NULL );
   300                         size_t border = (options.patchSize-1)/2 + 1;
   302                         for( xx = 0; xx < imgW; xx++ )
   303                                 for( yy = 0; yy < 
border; yy++ )
   304                                         cvSet2D( 
mask, yy, xx, zero );                                                  
   306                         for( xx = 0; xx < imgW; xx++ )
   307                                 for( yy = imgH - 
border; yy < imgH; yy++ )
   308                                         cvSet2D( 
mask, yy, xx, zero );                                                  
   310                         for( xx = 0; xx < 
border; xx++ )
   312                                         cvSet2D( 
mask, yy, xx, zero ) ;                                                 
   314                         for( xx = imgW - 
border; xx < imgW; xx++ )
   316                                         cvSet2D( 
mask, yy, xx, zero ) ;                                                 
   318                         selectGoodFeaturesKLT( 
img, feats, init_ID, nDesiredFeatures, &
mask );
   324                 for( 
unsigned int xx = ROI.xMin; xx < ROI.xMax; xx++ )
   325                         for( 
unsigned int yy = ROI.yMin; yy < ROI.yMax; yy++ )
   326                                 cvSet2D( 
mask, yy, xx, one) ;                                                           
   328                 selectGoodFeaturesKLT( 
img, feats, init_ID, nDesiredFeatures, &
mask );
 GLuint GLuint GLsizei count
 
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL. 
 
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
 
A class for storing images as grayscale or RGB bitmaps. 
 
#define THROW_EXCEPTION(msg)
 
TInternalFeatList::const_iterator const_iterator
 
Feature correctly tracked. 
 
void Tic()
Starts the stopwatch. 
 
const T * getAs() const
Returns a pointer to a const T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers. 
 
GLsizei const GLfloat * points
 
FAST feature detector, OpenCV's implementation ("Faster and better: A machine learning approach to co...
 
A structure for defining a ROI within an image. 
 
GLint GLint GLsizei GLsizei GLsizei GLint border
 
MRPT_TODO("Modify ping to run on Windows + Test this")
 
Harris border and corner detector [HARRIS]. 
 
This class implements a high-performance stopwatch. 
 
Classes for computer vision, detectors, features, etc. 
 
void push_back(const CFeaturePtr &f)
 
iterator erase(const iterator &it)
 
uint64_t TFeatureID
Definition of a feature ID. 
 
A list of visual features, to be used as output by detectors, as input/output by trackers, etc. 
 
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries. 
 
void extract_patch(CImage &patch, const unsigned int col=0, const unsigned int row=0, const unsigned int width=1, const unsigned int height=1) const
Extract a patch from this image, saveing it into "patch" (its previous contents will be overwritten)...
 
double Tac()
Stops the stopwatch. 
 
TFeatureID getMaxID() const
Get the maximum ID into the list. 
 
int round(const T value)
Returns the closer integer (int) to x. 
 
TInternalFeatList::iterator iterator
 
static CFeaturePtr Create()
 
EIGEN_STRONG_INLINE void ones(const size_t row, const size_t col)
Resize matrix and set all elements to one. 
 
Kanade-Lucas-Tomasi feature [SHI'94]. 
 
size_t getWidth() const MRPT_OVERRIDE
Returns the width of the image in pixels. 
 
size_t getHeight() const MRPT_OVERRIDE
Returns the height of the image in pixels.