Visual Servoing Platform
version 3.0.1
|
#include <visp3/klt/vpKltOpencv.h>
Public Member Functions | |
vpKltOpencv () | |
vpKltOpencv (const vpKltOpencv ©) | |
virtual | ~vpKltOpencv () |
void | addFeature (const float &x, const float &y) |
void | addFeature (const long &id, const float &x, const float &y) |
void | addFeature (const cv::Point2f &f) |
void | display (const vpImage< unsigned char > &I, const vpColor &color=vpColor::red, unsigned int thickness=1) |
int | getBlockSize () const |
void | getFeature (const int &index, long &id, float &x, float &y) const |
std::vector< cv::Point2f > | getFeatures () const |
std::vector< long > | getFeaturesId () const |
double | getHarrisFreeParameter () const |
int | getMaxFeatures () const |
double | getMinDistance () const |
int | getNbFeatures () const |
int | getNbPrevFeatures () const |
std::vector< cv::Point2f > | getPrevFeatures () const |
int | getPyramidLevels () const |
double | getQuality () const |
int | getWindowSize () const |
void | initTracking (const cv::Mat &I, const cv::Mat &mask=cv::Mat()) |
void | initTracking (const cv::Mat &I, const std::vector< cv::Point2f > &pts) |
void | initTracking (const cv::Mat &I, const std::vector< cv::Point2f > &pts, const std::vector< long > &ids) |
vpKltOpencv & | operator= (const vpKltOpencv ©) |
void | track (const cv::Mat &I) |
void | setBlockSize (const int blockSize) |
void | setHarrisFreeParameter (double harris_k) |
void | setInitialGuess (const std::vector< cv::Point2f > &guess_pts) |
void | setInitialGuess (const std::vector< cv::Point2f > &init_pts, const std::vector< cv::Point2f > &guess_pts, const std::vector< long > &fid) |
void | setMaxFeatures (const int maxCount) |
void | setMinDistance (double minDistance) |
void | setMinEigThreshold (double minEigThreshold) |
void | setPyramidLevels (const int pyrMaxLevel) |
void | setQuality (double qualityLevel) |
void | setTrackerId (int tid) |
void | setUseHarris (const int useHarrisDetector) |
void | setWindowSize (const int winSize) |
void | suppressFeature (const int &index) |
Static Public Member Functions | |
static void | display (const vpImage< unsigned char > &I, const std::vector< cv::Point2f > &features, const vpColor &color=vpColor::green, unsigned int thickness=1) |
static void | display (const vpImage< vpRGBa > &I, const std::vector< cv::Point2f > &features, const vpColor &color=vpColor::green, unsigned int thickness=1) |
static void | display (const vpImage< unsigned char > &I, const std::vector< cv::Point2f > &features, const std::vector< long > &featuresid, const vpColor &color=vpColor::green, unsigned int thickness=1) |
static void | display (const vpImage< vpRGBa > &I, const std::vector< cv::Point2f > &features, const std::vector< long > &featuresid, const vpColor &color=vpColor::green, unsigned int thickness=1) |
Protected Attributes | |
cv::Mat | m_gray |
cv::Mat | m_prevGray |
std::vector< cv::Point2f > | m_points [2] |
std::vector< long > | m_points_id |
int | m_maxCount |
cv::TermCriteria | m_termcrit |
int | m_winSize |
double | m_qualityLevel |
double | m_minDistance |
double | m_minEigThreshold |
double | m_harris_k |
int | m_blockSize |
int | m_useHarrisDetector |
int | m_pyrMaxLevel |
long | m_next_points_id |
bool | m_initial_guess |
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this class OpenCV should be installed. Installation instructions are provided here https://visp.inria.fr/3rd_opencv.
The following example available in tutorial-klt-tracker.cpp shows how to use the main functions of the class.
A line by line explanation is provided in Tutorial: Keypoint tracking.
Definition at line 76 of file vpKltOpencv.h.
vpKltOpencv::vpKltOpencv | ( | ) |
vpKltOpencv::vpKltOpencv | ( | const vpKltOpencv & | copy | ) |
Copy constructor.
Definition at line 72 of file vpKltOpencv.cpp.
|
virtual |
Definition at line 106 of file vpKltOpencv.cpp.
void vpKltOpencv::addFeature | ( | const float & | x, |
const float & | y | ||
) |
Add a keypoint at the end of the feature list. The id of the feature is set to ensure that it is unique.
x,y | : Coordinates of the feature in the image. |
Definition at line 536 of file vpKltOpencv.cpp.
References m_next_points_id, m_points, and m_points_id.
void vpKltOpencv::addFeature | ( | const long & | id, |
const float & | x, | ||
const float & | y | ||
) |
Add a keypoint at the end of the feature list.
id | : Feature id. Should be unique |
x,y | : Coordinates of the feature in the image. |
Definition at line 554 of file vpKltOpencv.cpp.
References m_next_points_id, m_points, and m_points_id.
void vpKltOpencv::addFeature | ( | const cv::Point2f & | f | ) |
Add a keypoint at the end of the feature list. The id of the feature is set to ensure that it is unique.
f | : Coordinates of the feature in the image. |
Definition at line 569 of file vpKltOpencv.cpp.
References m_next_points_id, m_points, and m_points_id.
void vpKltOpencv::display | ( | const vpImage< unsigned char > & | I, |
const vpColor & | color = vpColor::red , |
||
unsigned int | thickness = 1 |
||
) |
Display features position and id.
I | : Image used as background. Display should be initialized on it. |
color | : Color used to display the features. |
thickness | : Thickness of the drawings. |
Definition at line 219 of file vpKltOpencv.cpp.
References m_points, and m_points_id.
|
static |
Display features list.
I | : The image used as background. |
features | : Vector of features. |
color | : Color used to display the points. |
thickness | : Thickness of the points. |
Definition at line 237 of file vpKltOpencv.cpp.
References vpDisplay::displayCross(), vpMath::round(), vpImagePoint::set_u(), and vpImagePoint::set_v().
|
static |
Display features list.
I | : The image used as background. |
features | : Vector of features. |
color | : Color used to display the points. |
thickness | : Thickness of the points. |
Definition at line 260 of file vpKltOpencv.cpp.
References vpDisplay::displayCross(), vpMath::round(), vpImagePoint::set_u(), and vpImagePoint::set_v().
|
static |
Display features list with ids.
I | : The image used as background. |
features | : Vector of features. |
featuresid | : Vector of ids corresponding to the features. |
color | : Color used to display the points. |
thickness | : Thickness of the points |
Definition at line 285 of file vpKltOpencv.cpp.
References vpDisplay::displayCross(), vpDisplay::displayText(), vpMath::round(), vpImagePoint::set_u(), and vpImagePoint::set_v().
|
static |
Display features list with ids.
I | : The image used as background. |
features | : Vector of features. |
featuresid | : Vector of ids corresponding to the features. |
color | : Color used to display the points. |
thickness | : Thickness of the points |
Definition at line 316 of file vpKltOpencv.cpp.
References vpDisplay::displayCross(), vpDisplay::displayText(), vpMath::round(), vpImagePoint::set_u(), and vpImagePoint::set_v().
|
inline |
Get the size of the averaging block used to track the features.
Definition at line 101 of file vpKltOpencv.h.
Referenced by vpMbKltTracker::setKltOpencv().
void vpKltOpencv::getFeature | ( | const int & | index, |
long & | 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).
index | : Index of feature. |
id | : id of the feature. |
x | : x coordinate. |
y | : y coordinate. |
Definition at line 201 of file vpKltOpencv.cpp.
References vpException::badValue, m_points, and m_points_id.
Referenced by vpMbtDistanceKltPoints::computeNbDetectedCurrent(), vpMbtDistanceKltCylinder::computeNbDetectedCurrent(), vpMbKltTracker::getKltImagePoints(), vpMbKltTracker::getKltImagePointsWithId(), vpMbtDistanceKltPoints::init(), and vpMbtDistanceKltCylinder::init().
|
inline |
Get the list of current features.
Definition at line 104 of file vpKltOpencv.h.
Referenced by vpMbKltTracker::getKltPoints().
|
inline |
Get the unique id of each feature.
Definition at line 107 of file vpKltOpencv.h.
|
inline |
Get the free parameter of the Harris detector.
Definition at line 110 of file vpKltOpencv.h.
Referenced by vpMbKltTracker::setKltOpencv().
|
inline |
Get the list of lost feature.
Get the maximum number of features to track in the image.
Definition at line 114 of file vpKltOpencv.h.
Referenced by vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::setPose().
|
inline |
Get the minimal Euclidean distance between detected corners during initialization.
Definition at line 116 of file vpKltOpencv.h.
Referenced by vpMbKltTracker::setKltOpencv().
|
inline |
Get the number of current features.
Definition at line 118 of file vpKltOpencv.h.
Referenced by vpMbtDistanceKltPoints::computeNbDetectedCurrent(), vpMbtDistanceKltCylinder::computeNbDetectedCurrent(), vpMbKltTracker::getKltImagePoints(), vpMbKltTracker::getKltImagePointsWithId(), vpMbKltTracker::getNbKltPoints(), vpMbtDistanceKltPoints::init(), and vpMbtDistanceKltCylinder::init().
|
inline |
Get the number of previous features.
Definition at line 120 of file vpKltOpencv.h.
|
inline |
Get the list of previous features.
Definition at line 123 of file vpKltOpencv.h.
|
inline |
Get the list of features id.
Get the maximal pyramid level.
Definition at line 128 of file vpKltOpencv.h.
Referenced by vpMbKltTracker::setKltOpencv().
|
inline |
Get the parameter characterizing the minimal accepted quality of image corners.
Definition at line 130 of file vpKltOpencv.h.
Referenced by vpMbKltTracker::setKltOpencv().
|
inline |
Get the window size used to refine the corner locations.
Definition at line 132 of file vpKltOpencv.h.
Referenced by vpMbKltTracker::setKltOpencv().
void vpKltOpencv::initTracking | ( | const cv::Mat & | I, |
const cv::Mat & | mask = cv::Mat() |
||
) |
Initialise the tracking by extracting KLT keypoints on the provided image.
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. |
vpTrackingException::initializationError | : If the image I is not initialized, or if the image or the mask have bad coding format. |
Definition at line 120 of file vpKltOpencv.cpp.
References m_blockSize, m_gray, m_harris_k, m_maxCount, m_minDistance, m_next_points_id, m_points, m_points_id, m_qualityLevel, m_termcrit, and m_winSize.
Referenced by vpMbKltTracker::reinit().
void vpKltOpencv::initTracking | ( | const cv::Mat & | I, |
const std::vector< cv::Point2f > & | pts | ||
) |
Set the points that will be used as initialization during the next call to track().
I | : Input image. |
pts | : Vector of points that should be tracked. |
Definition at line 493 of file vpKltOpencv.cpp.
References m_gray, m_initial_guess, m_next_points_id, m_points, and m_points_id.
void vpKltOpencv::initTracking | ( | const cv::Mat & | I, |
const std::vector< cv::Point2f > & | pts, | ||
const std::vector< long > & | ids | ||
) |
Definition at line 507 of file vpKltOpencv.cpp.
References m_gray, m_initial_guess, m_next_points_id, m_points, and m_points_id.
vpKltOpencv & vpKltOpencv::operator= | ( | const vpKltOpencv & | copy | ) |
Copy operator.
Definition at line 83 of file vpKltOpencv.cpp.
References m_blockSize, m_gray, m_harris_k, m_initial_guess, m_maxCount, m_minDistance, m_minEigThreshold, m_next_points_id, m_points, m_points_id, m_prevGray, m_pyrMaxLevel, m_qualityLevel, m_termcrit, m_useHarrisDetector, and m_winSize.
void vpKltOpencv::setBlockSize | ( | const int | blockSize | ) |
Set the size of the averaging block used to track the features.
blockSize | : Size of an average block for computing a derivative covariation matrix over each pixel neighborhood. Default value is set to 3. |
Definition at line 416 of file vpKltOpencv.cpp.
References m_blockSize.
Referenced by vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().
void vpKltOpencv::setHarrisFreeParameter | ( | double | harris_k | ) |
Set the free parameter of the Harris detector.
harris_k | : Free parameter of the Harris detector. Default value is set to 0.04. |
Definition at line 372 of file vpKltOpencv.cpp.
References m_harris_k.
Referenced by vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().
void vpKltOpencv::setInitialGuess | ( | const std::vector< cv::Point2f > & | guess_pts | ) |
Set the points that will be used as initial guess during the next call to track(). A typical usage of this function is to predict the position of the features before the next call to track().
guess_pts | : Vector of points that should be tracked. The size of this vector should be the same as the one returned by getFeatures(). If this is not the case, an exception is returned. Note also that the id of the points is not modified. |
Definition at line 445 of file vpKltOpencv.cpp.
References vpException::badValue, m_initial_guess, and m_points.
Referenced by vpMbKltTracker::setPose().
void vpKltOpencv::setInitialGuess | ( | const std::vector< cv::Point2f > & | init_pts, |
const std::vector< cv::Point2f > & | guess_pts, | ||
const std::vector< long > & | fid | ||
) |
Set the points that will be used as initial guess during the next call to track(). A typical usage of this function is to predict the position of the features before the next call to track().
init_pts | : Initial points (could be obtained from getPrevFeatures() or getFeatures()). |
guess_pts | : Prediction of the new position of the initial points. The size of this vector must be the same as the size of the vector of initial points. |
fid | : Identifiers of the initial points. |
Definition at line 471 of file vpKltOpencv.cpp.
References vpException::badValue, m_initial_guess, m_points, and m_points_id.
void vpKltOpencv::setMaxFeatures | ( | const int | maxCount | ) |
Set the maximum number of features to track in the image.
maxCount | : Maximum number of features to detect and track. Default value is set to 500. |
Definition at line 338 of file vpKltOpencv.cpp.
References m_maxCount.
Referenced by vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().
void vpKltOpencv::setMinDistance | ( | double | minDistance | ) |
Set the minimal Euclidean distance between detected corners during initialization.
minDistance | : Minimal possible Euclidean distance between the detected corners. Default value is set to 15. |
Definition at line 393 of file vpKltOpencv.cpp.
References m_minDistance.
Referenced by vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().
void vpKltOpencv::setMinEigThreshold | ( | double | minEigThreshold | ) |
Set the minimal eigen value threshold used to reject a point during the tracking.
minEigThreshold | : Minimal eigen value threshold. Default value is set to 1e-4. |
Definition at line 402 of file vpKltOpencv.cpp.
References m_minEigThreshold.
void vpKltOpencv::setPyramidLevels | ( | const int | pyrMaxLevel | ) |
Set the maximal pyramid level. If the level is zero, then no pyramid is computed for the optical flow.
pyrMaxLevel | : 0-based maximal pyramid level number; if set to 0, pyramids are not used (single level), if set to 1, two levels are used, and so on. Default value is set to 3. |
Definition at line 428 of file vpKltOpencv.cpp.
References m_pyrMaxLevel.
Referenced by vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().
void vpKltOpencv::setQuality | ( | double | qualityLevel | ) |
Set the parameter characterizing the minimal accepted quality of image corners.
qualityLevel | : Quality level parameter. Default value is set to 0.01. The parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue or the Harris function response. The corners with the quality measure less than the product are rejected. For example, if the best corner has the quality measure = 1500, and the qualityLevel=0.01, then all the corners with the quality measure less than 15 are rejected. |
Definition at line 362 of file vpKltOpencv.cpp.
References m_qualityLevel.
Referenced by vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().
|
inline |
Does nothing. Just here for compat with previous releases that use OpenCV C api to do the tracking.
Definition at line 150 of file vpKltOpencv.h.
Referenced by vpMbKltTracker::resetTracker(), and vpMbKltTracker::vpMbKltTracker().
void vpKltOpencv::setUseHarris | ( | const int | useHarrisDetector | ) |
Set the parameter indicating whether to use a Harris detector or the minimal eigenvalue of gradient matrices for corner detection.
useHarrisDetector | : If 1 (default value), use the Harris detector. If 0 use the eigenvalue. |
Definition at line 382 of file vpKltOpencv.cpp.
References m_useHarrisDetector.
Referenced by vpMbKltTracker::resetTracker(), and vpMbKltTracker::vpMbKltTracker().
void vpKltOpencv::setWindowSize | ( | const int | winSize | ) |
Set the window size used to refine the corner locations.
winSize | : Half of the side length of the search window. Default value is set to 10. For example, if winSize=5 , then a 5*2+1 5*2+1 = 11 11 search window is used. |
Definition at line 349 of file vpKltOpencv.cpp.
References m_winSize.
Referenced by vpMbEdgeKltTracker::loadConfigFile(), vpMbKltTracker::loadConfigFile(), vpMbKltTracker::resetTracker(), vpMbKltTracker::setKltOpencv(), and vpMbKltTracker::vpMbKltTracker().
void vpKltOpencv::suppressFeature | ( | const int & | index | ) |
Remove the feature with the given index as parameter.
index | : Index of the feature to remove. |
Definition at line 579 of file vpKltOpencv.cpp.
References vpException::badValue, m_points, and m_points_id.
void vpKltOpencv::track | ( | const cv::Mat & | I | ) |
Track KLT keypoints using the iterative Lucas-Kanade method with pyramids.
I | : Input image. |
Definition at line 148 of file vpKltOpencv.cpp.
References vpTrackingException::fatalError, m_gray, m_initial_guess, m_minEigThreshold, m_points, m_points_id, m_prevGray, m_pyrMaxLevel, m_termcrit, and m_winSize.
Referenced by vpMbKltTracker::preTracking().
|
protected |
Definition at line 166 of file vpKltOpencv.h.
Referenced by initTracking(), operator=(), and setBlockSize().
|
protected |
Definition at line 156 of file vpKltOpencv.h.
Referenced by initTracking(), operator=(), and track().
|
protected |
Definition at line 165 of file vpKltOpencv.h.
Referenced by initTracking(), operator=(), and setHarrisFreeParameter().
|
protected |
Definition at line 170 of file vpKltOpencv.h.
Referenced by initTracking(), operator=(), setInitialGuess(), and track().
|
protected |
Definition at line 159 of file vpKltOpencv.h.
Referenced by initTracking(), operator=(), and setMaxFeatures().
|
protected |
Definition at line 163 of file vpKltOpencv.h.
Referenced by initTracking(), operator=(), and setMinDistance().
|
protected |
Definition at line 164 of file vpKltOpencv.h.
Referenced by operator=(), setMinEigThreshold(), and track().
|
protected |
Definition at line 169 of file vpKltOpencv.h.
Referenced by addFeature(), initTracking(), and operator=().
|
protected |
Previous [0] and current [1] keypoint location.
Definition at line 157 of file vpKltOpencv.h.
Referenced by addFeature(), display(), getFeature(), initTracking(), operator=(), setInitialGuess(), suppressFeature(), and track().
|
protected |
Keypoint id.
Definition at line 158 of file vpKltOpencv.h.
Referenced by addFeature(), display(), getFeature(), initTracking(), operator=(), setInitialGuess(), suppressFeature(), and track().
|
protected |
Definition at line 156 of file vpKltOpencv.h.
Referenced by operator=(), and track().
|
protected |
Definition at line 168 of file vpKltOpencv.h.
Referenced by operator=(), setPyramidLevels(), and track().
|
protected |
Definition at line 162 of file vpKltOpencv.h.
Referenced by initTracking(), operator=(), and setQuality().
|
protected |
Definition at line 160 of file vpKltOpencv.h.
Referenced by initTracking(), operator=(), track(), and vpKltOpencv().
|
protected |
Definition at line 167 of file vpKltOpencv.h.
Referenced by operator=(), and setUseHarris().
|
protected |
Definition at line 161 of file vpKltOpencv.h.
Referenced by initTracking(), operator=(), setWindowSize(), and track().