ViSP  2.6.2
vpKltOpencv Class Reference

#include <vpKltOpencv.h>

Public Member Functions

 vpKltOpencv ()
 
 vpKltOpencv (const vpKltOpencv &copy)
 
virtual ~vpKltOpencv ()
 
void initTracking (const IplImage *I, const IplImage *mask=NULL)
 
void track (const IplImage *I)
 
void display (const vpImage< unsigned char > &I, vpColor color=vpColor::red)
 
void setMaxFeatures (const int input)
 
void setWindowSize (const int input)
 
void setQuality (double input)
 
void setMinDistance (double input)
 
void setHarrisFreeParameter (double input)
 
void setBlockSize (const int input)
 
void setUseHarris (const int input)
 
void setPyramidLevels (const int input)
 
void setTrackerId (int tid)
 
void setOnInitialize (funcevent input)
 
void setOnFeatureLost (funcinfo input)
 
void setOnNewFeature (funcinfo input)
 
void setOnMeasureFeature (funcinfo input)
 
void setIsFeatureValid (funccheck input)
 
bool * getListOfLostFeature () const
 
CvPoint2D32f * getFeatures () const
 
long * getFeaturesId () const
 
CvPoint2D32f * getPrevFeatures () const
 
long * getPrevFeaturesId () const
 
int getNbFeatures () const
 
int getNbPrevFeatures () const
 
int getMaxFeatures () const
 
void getFeature (int index, int &id, float &x, float &y) const
 
void getPrevFeature (int index, int &id, float &x, float &y) const
 
void addFeature (const int &id, const float &x, const float &y)
 
void suppressFeature (int index)
 

Static Public Member Functions

static void display (const vpImage< unsigned char > &I, const CvPoint2D32f *features_list, const int &nbFeatures, vpColor color=vpColor::green, unsigned int thickness=1)
 
static void display (const vpImage< unsigned char > &I, const CvPoint2D32f *features_list, const long *featuresid_list, const int &nbFeatures, vpColor color=vpColor::green, unsigned int thickness=1)
 

Detailed Description

Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented with OpenCV.

The following example shows how to use the main functions of the class:

#include <visp/vpConfig.h>
#include <visp/vpImage.h>
#include <visp/vpDisplay.h>
#include <visp/vpKltOpencv.h>
#include <visp/vpImageConvert.h>
int main()
{
#if VISP_HAVE_OPENCV_VERSION >= 0x010100 // KLT only available since OpenCV-1.1.0
IplImage* Icv = NULL;
//First grab the initial image I
//Convert the image I to the IplImage format.
//Initialise the tracking on the whole image.
klt.initTracking(Icv, NULL);
while(true)
{
// Grab a new image and convert it to the OpenCV format.
// Track the features on the current image.
klt.track(Icv);
// Display the features tracked at the current iteration.
klt.display(I);
}
cvReleaseImage(&Icv);
#else
std::cout << "vpKltOpencv requires ViSP with OpenCV." << std::endl;
#endif
return(0);
}
Examples:
trackKltOpencv.cpp.

Definition at line 141 of file vpKltOpencv.h.

Constructor & Destructor Documentation

vpKltOpencv::vpKltOpencv ( )

Definition at line 102 of file vpKltOpencv.cpp.

vpKltOpencv::vpKltOpencv ( const vpKltOpencv copy)

Definition at line 148 of file vpKltOpencv.cpp.

vpKltOpencv::~vpKltOpencv ( )
virtual

Definition at line 259 of file vpKltOpencv.cpp.

Member Function Documentation

void vpKltOpencv::addFeature ( const int &  id,
const float &  x,
const float &  y 
)

Add at the end of the feauture list.

If there is no space left, the feature is not added (just return)

Definition at line 496 of file vpKltOpencv.cpp.

References vpERROR_TRACE.

void vpKltOpencv::display ( const vpImage< unsigned char > &  I,
vpColor  color = vpColor::red 
)
void vpKltOpencv::display ( const vpImage< unsigned char > &  I,
const CvPoint2D32f *  features_list,
const int &  nbFeatures,
vpColor  color = vpColor::green,
unsigned int  thickness = 1 
)
static

Display of vpKLTOpenCV features list

Parameters
I: The image used as background.
features_list: List of features
nbFeatures: Number of features
color: Color used to display the points.
thickness: Thickness of the points.

Definition at line 543 of file vpKltOpencv.cpp.

References vpDisplay::displayCross(), vpMath::round(), vpImagePoint::set_u(), and vpImagePoint::set_v().

void vpKltOpencv::display ( const vpImage< unsigned char > &  I,
const CvPoint2D32f *  features_list,
const long *  featuresid_list,
const int &  nbFeatures,
vpColor  color = vpColor::green,
unsigned int  thickness = 1 
)
static

Display of vpKLTOpenCV features list with ids

Parameters
I: The image used as background.
features_list: List of features
featuresid_list: List of ids corresponding to the features list
nbFeatures: Number of features
color: Color used to display the points.
thickness: Thickness of the points

Definition at line 571 of file vpKltOpencv.cpp.

References vpDisplay::displayCharString(), vpDisplay::displayCross(), vpMath::round(), vpImagePoint::set_u(), and vpImagePoint::set_v().

void vpKltOpencv::getFeature ( int  index,
int &  id,
float &  x,
float &  y 
) const

Get the 'index'th feature image coordinates. Beware that getFeature(i,...) may not represent the same feature before and after a tracking iteration (if a feature is lost, features are shifted in the array).

Definition at line 456 of file vpKltOpencv.cpp.

References vpException::memoryAllocationError, and vpERROR_TRACE.

CvPoint2D32f* vpKltOpencv::getFeatures ( ) const
inline

Get the list of features.

Definition at line 278 of file vpKltOpencv.h.

long* vpKltOpencv::getFeaturesId ( ) const
inline

Get the list of features id.

Definition at line 280 of file vpKltOpencv.h.

bool* vpKltOpencv::getListOfLostFeature ( ) const
inline

Get the list of lost feature.

Definition at line 276 of file vpKltOpencv.h.

int vpKltOpencv::getMaxFeatures ( ) const
inline

Get Max number of features.

Definition at line 290 of file vpKltOpencv.h.

int vpKltOpencv::getNbFeatures ( ) const
inline

Get the current number of features.

Definition at line 286 of file vpKltOpencv.h.

int vpKltOpencv::getNbPrevFeatures ( ) const
inline

Get the previous number of features.

Definition at line 288 of file vpKltOpencv.h.

void vpKltOpencv::getPrevFeature ( int  index,
int &  id,
float &  x,
float &  y 
) const

Get the 'index'th previous feature image coordinates. Beware that getPrevFeature(i,...) may not represent the same feature before and after a tracking iteration (if a feature is lost, features are shifted in the array).

Definition at line 477 of file vpKltOpencv.cpp.

References vpException::memoryAllocationError, and vpERROR_TRACE.

CvPoint2D32f* vpKltOpencv::getPrevFeatures ( ) const
inline

Get the list of features.

Definition at line 282 of file vpKltOpencv.h.

long* vpKltOpencv::getPrevFeaturesId ( ) const
inline

Get the list of features id.

Definition at line 284 of file vpKltOpencv.h.

void vpKltOpencv::initTracking ( const IplImage *  I,
const IplImage *  mask = NULL 
)
Examples:
trackKltOpencv.cpp.

Definition at line 290 of file vpKltOpencv.cpp.

References vpTrackingException::initializationError.

void vpKltOpencv::setBlockSize ( const int  input)
inline

Set the size of the averaging block used to track the features.

Warning
The input is a signed integer to be compatible with OpenCV. However, it must be a positive integer.
Parameters
input: The new size of the block.
Examples:
trackKltOpencv.cpp.

Definition at line 248 of file vpKltOpencv.h.

void vpKltOpencv::setHarrisFreeParameter ( double  input)
inline

Set the Harris parameter (The k value).

Warning
The tracker must be re-initialised using the method initTracking().
Parameters
input: The new Harris parameter.
Examples:
trackKltOpencv.cpp.

Definition at line 238 of file vpKltOpencv.h.

void vpKltOpencv::setIsFeatureValid ( funccheck  input)
inline

Definition at line 273 of file vpKltOpencv.h.

void vpKltOpencv::setMaxFeatures ( const int  input)

Set the maximum number of features to track in the image.

Warning
The tracker must be re-initialised using the method initTracking().
Parameters
input: The new number of maximum features.
Examples:
trackKltOpencv.cpp.

Definition at line 271 of file vpKltOpencv.cpp.

void vpKltOpencv::setMinDistance ( double  input)
inline

Set the minimal distance between two points during the initialisation.

Warning
The tracker must be re-initialised using the method initTracking().
Parameters
input: The new minimal distance between two points.
Examples:
trackKltOpencv.cpp.

Definition at line 229 of file vpKltOpencv.h.

void vpKltOpencv::setOnFeatureLost ( funcinfo  input)
inline

Definition at line 267 of file vpKltOpencv.h.

void vpKltOpencv::setOnInitialize ( funcevent  input)
inline

Definition at line 265 of file vpKltOpencv.h.

void vpKltOpencv::setOnMeasureFeature ( funcinfo  input)
inline

Definition at line 271 of file vpKltOpencv.h.

void vpKltOpencv::setOnNewFeature ( funcinfo  input)
inline

Definition at line 269 of file vpKltOpencv.h.

void vpKltOpencv::setPyramidLevels ( const int  input)
inline

Set the maximal pyramid level. If the level is zero, then no pyramid is computed for the optical flow.

Warning
The tracker must be re-initialised using the method initTracking().
Parameters
input: The new maximal pyramid level.
Examples:
trackKltOpencv.cpp.

Definition at line 259 of file vpKltOpencv.h.

void vpKltOpencv::setQuality ( double  input)
inline
Examples:
trackKltOpencv.cpp.

Definition at line 220 of file vpKltOpencv.h.

void vpKltOpencv::setTrackerId ( int  tid)
inline
Examples:
trackKltOpencv.cpp.

Definition at line 260 of file vpKltOpencv.h.

void vpKltOpencv::setUseHarris ( const int  input)
inline
Examples:
trackKltOpencv.cpp.

Definition at line 249 of file vpKltOpencv.h.

void vpKltOpencv::setWindowSize ( const int  input)
inline

Set the window size for the sub-pixel computation.

Warning
The tracker must be re-initialised using the method initTracking().
Parameters
input: The new number of maximum features.
Examples:
trackKltOpencv.cpp.

Definition at line 219 of file vpKltOpencv.h.

void vpKltOpencv::suppressFeature ( int  index)

Definition at line 513 of file vpKltOpencv.cpp.

References vpException::memoryAllocationError, and vpERROR_TRACE.

void vpKltOpencv::track ( const IplImage *  I)
Examples:
trackKltOpencv.cpp.

Definition at line 365 of file vpKltOpencv.cpp.

References vpTrackingException::initializationError, and vpERROR_TRACE.