Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpKltOpencv.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented
32 * with opencv.
33 */
34
42#ifndef _vpKltOpencv_h_
43#define _vpKltOpencv_h_
44
45#include <visp3/core/vpColor.h>
46#include <visp3/core/vpConfig.h>
47#include <visp3/core/vpImage.h>
48
49#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
50
51#include <opencv2/highgui/highgui.hpp>
52#include <opencv2/imgproc/imgproc.hpp>
53#include <opencv2/video/tracking.hpp>
54
72class VISP_EXPORT vpKltOpencv
73{
74public:
82 vpKltOpencv(const vpKltOpencv &copy);
86 virtual ~vpKltOpencv();
87
93 void addFeature(const float &x, const float &y);
94
105 void addFeature(const long &id, const float &x, const float &y);
106
112 void addFeature(const cv::Point2f &f);
113
121 void display(const vpImage<unsigned char> &I, const vpColor &color = vpColor::red, unsigned int thickness = 1);
130 static void display(const vpImage<unsigned char> &I, const std::vector<cv::Point2f> &features,
131 const vpColor &color = vpColor::green, unsigned int thickness = 1);
140 static void display(const vpImage<vpRGBa> &I, const std::vector<cv::Point2f> &features,
141 const vpColor &color = vpColor::green, unsigned int thickness = 1);
151 static void display(const vpImage<unsigned char> &I, const std::vector<cv::Point2f> &features,
152 const std::vector<long> &featuresid, const vpColor &color = vpColor::green,
153 unsigned int thickness = 1);
163 static void display(const vpImage<vpRGBa> &I, const std::vector<cv::Point2f> &features,
164 const std::vector<long> &featuresid, const vpColor &color = vpColor::green,
165 unsigned int thickness = 1);
166
168 int getBlockSize() const { return m_blockSize; }
180 void getFeature(const int &index, long &id, float &x, float &y) const;
182 std::vector<cv::Point2f> getFeatures() const { return m_points[1]; }
183 // CvPoint2D32f* getFeatures() const {return features;}
185 std::vector<long> getFeaturesId() const { return m_points_id; }
186 // long* getFeaturesId() const {return featuresid;}
188 double getHarrisFreeParameter() const { return m_harris_k; }
190 // bool *getListOfLostFeature() const { return lostDuringTrack; }
192 int getMaxFeatures() const { return m_maxCount; }
195 double getMinDistance() const { return m_minDistance; }
197 int getNbFeatures() const { return (int)m_points[1].size(); }
199 int getNbPrevFeatures() const { return (int)m_points[0].size(); }
200 // void getPrevFeature(int index, int &id, float &x, float &y) const;
202 std::vector<cv::Point2f> getPrevFeatures() const { return m_points[0]; }
203 // CvPoint2D32f* getPrevFeatures() const {return prev_features;}
205 // long* getPrevFeaturesId() const {return prev_featuresid;}
207 int getPyramidLevels() const { return m_pyrMaxLevel; }
210 double getQuality() const { return m_qualityLevel; }
212 int getWindowSize() const { return m_winSize; }
213
224 void initTracking(const cv::Mat &I, const cv::Mat &mask = cv::Mat());
225
233 void initTracking(const cv::Mat &I, const std::vector<cv::Point2f> &pts);
234
243 void initTracking(const cv::Mat &I, const std::vector<cv::Point2f> &pts, const std::vector<long> &ids);
244
248 vpKltOpencv &operator=(const vpKltOpencv &copy);
249
255 void track(const cv::Mat &I);
256
266 void setBlockSize(int blockSize) { m_blockSize = blockSize; }
267
274 void setHarrisFreeParameter(double harris_k) { m_harris_k = harris_k; }
275
288 void setInitialGuess(const std::vector<cv::Point2f> &guess_pts);
289
306 void setInitialGuess(const std::vector<cv::Point2f> &init_pts, const std::vector<cv::Point2f> &guess_pts,
307 const std::vector<long> &fid);
314 void setMaxFeatures(int maxCount) { m_maxCount = maxCount; }
315
323 void setMinDistance(double minDistance) { m_minDistance = minDistance; }
324
332 void setMinEigThreshold(double minEigThreshold) { m_minEigThreshold = minEigThreshold; }
333
342 void setPyramidLevels(int pyrMaxLevel) { m_pyrMaxLevel = pyrMaxLevel; }
343
355 void setQuality(double qualityLevel) { m_qualityLevel = qualityLevel; }
356
359 void setTrackerId(int tid) { (void)tid; }
360
367 void setUseHarris(int useHarrisDetector) { m_useHarrisDetector = useHarrisDetector; }
368
376 void setWindowSize(int winSize) { m_winSize = winSize; }
377
383 void suppressFeature(const int &index);
384
385protected:
386 cv::Mat m_gray;
387 cv::Mat m_prevGray;
388 std::vector<cv::Point2f> m_points[2];
389 std::vector<long> m_points_id;
391 cv::TermCriteria m_termcrit;
396 double m_harris_k;
402};
403
404#endif
405#endif
Class to define RGB colors available for display functionalities.
Definition vpColor.h:152
static const vpColor red
Definition vpColor.h:211
static const vpColor green
Definition vpColor.h:214
Definition of the vpImage class member functions.
Definition vpImage.h:135
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
Definition vpKltOpencv.h:73
std::vector< long > m_points_id
Keypoint id.
int m_useHarrisDetector
true to use Harris detector
int m_maxCount
Max number of keypoints.
double getQuality() const
int getMaxFeatures() const
Get the list of lost feature.
void setBlockSize(int blockSize)
int m_blockSize
Block size.
void setQuality(double qualityLevel)
int getNbPrevFeatures() const
Get the number of previous features.
void setTrackerId(int tid)
int getWindowSize() const
Get the window size used to refine the corner locations.
double m_minDistance
Mins distance between keypoints.
int getNbFeatures() const
Get the number of current features.
cv::TermCriteria m_termcrit
Term criteria.
std::vector< cv::Point2f > getPrevFeatures() const
Get the list of previous features.
double m_minEigThreshold
Min eigen threshold.
void setHarrisFreeParameter(double harris_k)
int m_pyrMaxLevel
Pyramid max level.
double getHarrisFreeParameter() const
Get the free parameter of the Harris detector.
double m_qualityLevel
Quality level.
bool m_initial_guess
true when initial guess is provided
cv::Mat m_gray
Gray image.
void setMaxFeatures(int maxCount)
void setMinEigThreshold(double minEigThreshold)
std::vector< long > getFeaturesId() const
Get the unique id of each feature.
double m_harris_k
Harris parameter.
double getMinDistance() const
int m_winSize
Window criteria.
long m_next_points_id
Id for the newt keypoint.
cv::Mat m_prevGray
Previous gray image.
void setMinDistance(double minDistance)
int getBlockSize() const
Get the size of the averaging block used to track the features.
int getPyramidLevels() const
Get the list of features id.
void setUseHarris(int useHarrisDetector)
void setWindowSize(int winSize)
void setPyramidLevels(int pyrMaxLevel)
std::vector< cv::Point2f > getFeatures() const
Get the list of current features.