ViSP  2.9.0

#include <vpKltOpencv.h>

Public Member Functions

 vpKltOpencv ()
 
 vpKltOpencv (const vpKltOpencv &copy)
 
virtual ~vpKltOpencv ()
 
void addFeature (const int &id, const float &x, const float &y)
 
void display (const vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1)
 
int getBlockSize () const
 
void getFeature (int index, int &id, float &x, float &y) const
 
CvPoint2D32f * getFeatures () const
 
long * getFeaturesId () const
 
double getHarrisFreeParameter () const
 
bool * getListOfLostFeature () const
 
int getMaxFeatures () const
 
double getMinDistance () const
 
int getNbFeatures () const
 
int getNbPrevFeatures () const
 
void getPrevFeature (int index, int &id, float &x, float &y) const
 
CvPoint2D32f * getPrevFeatures () const
 
long * getPrevFeaturesId () const
 
int getPyramidLevels () const
 
double getQuality () const
 
int getWindowSize () const
 
void initTracking (const IplImage *I, const IplImage *mask=NULL)
 
vpKltOpencvoperator= (const vpKltOpencv &copy)
 
void track (const IplImage *I)
 
void setBlockSize (const int input)
 
void setHarrisFreeParameter (double input)
 
void setInitialGuess (CvPoint2D32f **guess_pts)
 
void setIsFeatureValid (funccheck input)
 
void setMaxFeatures (const int input)
 
void setMinDistance (double input)
 
void setOnInitialize (funcevent input)
 
void setOnFeatureLost (funcinfo input)
 
void setOnNewFeature (funcinfo input)
 
void setOnMeasureFeature (funcinfo input)
 
void setPyramidLevels (const int input)
 
void setQuality (double input)
 
void setTrackerId (int tid)
 
void setUseHarris (const int input)
 
void setWindowSize (const int input)
 
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< vpRGBa > &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)
 
static void display (const vpImage< vpRGBa > &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 in OpenCV.

The following example available in tutorial-klt-tracker.cpp shows how to use the main functions of the class.

#include <visp/vpImageConvert.h>
#include <visp/vpKltOpencv.h>
#include <visp/vpDisplayOpenCV.h>
#include <visp/vpVideoReader.h>
int main()
{
#if (VISP_HAVE_OPENCV_VERSION >= 0x010100) && defined(VISP_HAVE_FFMPEG)
try {
vpVideoReader reader;
reader.setFileName("video-postcard.mpeg");
reader.acquire(I);
IplImage * cvI = NULL;
// Display initialisation
vpDisplayOpenCV d(I, 0, 0, "Klt tracking");
vpKltOpencv tracker;
// Set tracker parameters
tracker.setMaxFeatures(200);
tracker.setWindowSize(10);
tracker.setQuality(0.01);
tracker.setMinDistance(15);
tracker.setHarrisFreeParameter(0.04);
tracker.setBlockSize(9);
tracker.setUseHarris(1);
tracker.setPyramidLevels(3);
// Initialise the tracking
tracker.initTracking(cvI);
while ( ! reader.end() )
{
reader.acquire(I);
tracker.track(cvI);
tracker.display(I, vpColor::red);
}
cvReleaseImage(&cvI);
return 0;
}
catch(vpException e) {
std::cout << "Catch an exception: " << e << std::endl;
}
#endif
}

A line by line explanation is provided in Tutorial: Keypoint tracking.

Examples:
mbtEdgeKltTracking.cpp, mbtKltTracking.cpp, trackKltOpencv.cpp, tutorial-klt-tracker.cpp, tutorial-mb-hybrid-tracker.cpp, and tutorial-mb-klt-tracker.cpp.

Definition at line 103 of file vpKltOpencv.h.

Constructor & Destructor Documentation

vpKltOpencv::vpKltOpencv ( )

Default constructor.

Definition at line 105 of file vpKltOpencv.cpp.

vpKltOpencv::vpKltOpencv ( const vpKltOpencv copy)

Copy constructor.

Definition at line 125 of file vpKltOpencv.cpp.

vpKltOpencv::~vpKltOpencv ( )
virtual

Definition at line 247 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 542 of file vpKltOpencv.cpp.

References vpERROR_TRACE.

void vpKltOpencv::display ( const vpImage< unsigned char > &  I,
vpColor  color = vpColor::red,
unsigned int  thickness = 1 
)

Display features position and id.

Parameters
I: Image used as background. Display should be initialized on it.
color: Color used to display the features.
thickness: Thickness of the drawings.
Examples:
trackKltOpencv.cpp, and tutorial-klt-tracker.cpp.

Definition at line 450 of file vpKltOpencv.cpp.

References vpImage< Type >::bitmap, vpException::memoryAllocationError, and vpERROR_TRACE.

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 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 589 of file vpKltOpencv.cpp.

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

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

Display 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 614 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 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 642 of file vpKltOpencv.cpp.

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

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

Display 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 676 of file vpKltOpencv.cpp.

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

int vpKltOpencv::getBlockSize ( ) const
inline

Get the block size.

Definition at line 172 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::setKltOpencv().

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).

Parameters
index: index of feature
id: id of the feature
x: x coordinate
y: y coordinate

Definition at line 475 of file vpKltOpencv.cpp.

References vpException::memoryAllocationError, and vpERROR_TRACE.

Referenced by vpMbtKltPolygon::computeNbDetectedCurrent(), vpMbKltTracker::getKltImagePoints(), vpMbKltTracker::getKltImagePointsWithId(), and vpMbtKltPolygon::init().

CvPoint2D32f* vpKltOpencv::getFeatures ( ) const
inline

Get the list of features.

Definition at line 175 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::getKltPoints().

long* vpKltOpencv::getFeaturesId ( ) const
inline

Get the list of features id.

Definition at line 177 of file vpKltOpencv.h.

double vpKltOpencv::getHarrisFreeParameter ( ) const
inline

Get Harris free parameter.

Definition at line 179 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::setKltOpencv().

bool* vpKltOpencv::getListOfLostFeature ( ) const
inline

Get the list of lost feature.

Definition at line 181 of file vpKltOpencv.h.

int vpKltOpencv::getMaxFeatures ( ) const
inline

Get Max number of features.

Definition at line 183 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::setPose().

double vpKltOpencv::getMinDistance ( ) const
inline

Get Min Distance.

Definition at line 185 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::setKltOpencv().

int vpKltOpencv::getNbFeatures ( ) const
inline
int vpKltOpencv::getNbPrevFeatures ( ) const
inline

Get the previous number of features.

Definition at line 189 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 523 of file vpKltOpencv.cpp.

References vpException::memoryAllocationError, and vpERROR_TRACE.

CvPoint2D32f* vpKltOpencv::getPrevFeatures ( ) const
inline

Get the list of features.

Definition at line 192 of file vpKltOpencv.h.

long* vpKltOpencv::getPrevFeaturesId ( ) const
inline

Get the list of features id.

Definition at line 194 of file vpKltOpencv.h.

int vpKltOpencv::getPyramidLevels ( ) const
inline

Get the number of pyramid levels.

Definition at line 196 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::setKltOpencv().

double vpKltOpencv::getQuality ( ) const
inline

Get the quality of the tracker.

Definition at line 198 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::setKltOpencv().

int vpKltOpencv::getWindowSize ( ) const
inline

Get Max number of features.

Definition at line 200 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::setKltOpencv().

void vpKltOpencv::initTracking ( const IplImage *  I,
const IplImage *  mask = NULL 
)

Initialise the tracking by extracting KLT keypoints on the provided image.

Parameters
I: Grey level image used as input. This image should have only 1 channel.
mask: Image mask used to restrict the keypoint detection area. If mask is NULL, all the image will be considered.
Exceptions
vpTrackingException::initializationError: If the image I is not initialized, or if the image or the mask have bad coding format.
Examples:
trackKltOpencv.cpp, and tutorial-klt-tracker.cpp.

Definition at line 288 of file vpKltOpencv.cpp.

References vpTrackingException::initializationError.

Referenced by vpMbKltTracker::reinit().

vpKltOpencv & vpKltOpencv::operator= ( const vpKltOpencv copy)

Copy operator.

Definition at line 140 of file vpKltOpencv.cpp.

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:
mbtEdgeKltTracking.cpp, mbtKltTracking.cpp, trackKltOpencv.cpp, tutorial-klt-tracker.cpp, tutorial-mb-hybrid-tracker.cpp, and tutorial-mb-klt-tracker.cpp.

Definition at line 219 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::loadConfigFile(), vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().

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:
mbtEdgeKltTracking.cpp, mbtKltTracking.cpp, trackKltOpencv.cpp, tutorial-klt-tracker.cpp, tutorial-mb-hybrid-tracker.cpp, and tutorial-mb-klt-tracker.cpp.

Definition at line 227 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::loadConfigFile(), vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().

void vpKltOpencv::setInitialGuess ( CvPoint2D32f **  guess_pts)

Set the points that will be used as initial guess during the next call to track().

Warning
Those points will be used just one time (next track()).
Parameters
guess_pts: Reference on an array of CvPoint2D32f allocated with cvAlloc().

Definition at line 497 of file vpKltOpencv.cpp.

Referenced by vpMbKltTracker::setPose().

void vpKltOpencv::setIsFeatureValid ( funccheck  input)
inline

Is a feature valid (e.g. : test if not too close to borders) -> event(id_tracker, x, y)

Definition at line 232 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:
mbtEdgeKltTracking.cpp, mbtKltTracking.cpp, trackKltOpencv.cpp, tutorial-klt-tracker.cpp, tutorial-mb-hybrid-tracker.cpp, and tutorial-mb-klt-tracker.cpp.

Definition at line 259 of file vpKltOpencv.cpp.

Referenced by vpMbKltTracker::loadConfigFile(), vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().

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:
mbtEdgeKltTracking.cpp, mbtKltTracking.cpp, trackKltOpencv.cpp, tutorial-klt-tracker.cpp, tutorial-mb-hybrid-tracker.cpp, and tutorial-mb-klt-tracker.cpp.

Definition at line 243 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::loadConfigFile(), vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().

void vpKltOpencv::setOnFeatureLost ( funcinfo  input)
inline

Definition at line 250 of file vpKltOpencv.h.

void vpKltOpencv::setOnInitialize ( funcevent  input)
inline

Definition at line 248 of file vpKltOpencv.h.

void vpKltOpencv::setOnMeasureFeature ( funcinfo  input)
inline

Definition at line 254 of file vpKltOpencv.h.

void vpKltOpencv::setOnNewFeature ( funcinfo  input)
inline

Definition at line 252 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:
mbtEdgeKltTracking.cpp, mbtKltTracking.cpp, trackKltOpencv.cpp, tutorial-klt-tracker.cpp, tutorial-mb-hybrid-tracker.cpp, and tutorial-mb-klt-tracker.cpp.

Definition at line 263 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::loadConfigFile(), vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().

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

Definition at line 265 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::resetTracker(), and vpMbKltTracker::vpMbKltTracker().

void vpKltOpencv::setUseHarris ( 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, and tutorial-klt-tracker.cpp.

Definition at line 273 of file vpKltOpencv.h.

Referenced by vpMbKltTracker::resetTracker(), and vpMbKltTracker::vpMbKltTracker().

void vpKltOpencv::suppressFeature ( int  index)

Definition at line 559 of file vpKltOpencv.cpp.

References vpException::memoryAllocationError, and vpERROR_TRACE.

void vpKltOpencv::track ( const IplImage *  I)