42 #include <visp3/core/vpConfig.h>
44 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
48 #include <visp3/core/vpDisplay.h>
49 #include <visp3/core/vpTrackingException.h>
50 #include <visp3/klt/vpKltOpencv.h>
54 : m_gray(), m_prevGray(), m_points_id(), m_maxCount(500), m_termcrit(), m_winSize(10), m_qualityLevel(0.01),
55 m_minDistance(15), m_minEigThreshold(1e-4), m_harris_k(0.04), m_blockSize(3), m_useHarrisDetector(1),
56 m_pyrMaxLevel(3), m_next_points_id(0), m_initial_guess(false)
58 m_termcrit = cv::TermCriteria(cv::TermCriteria::COUNT | cv::TermCriteria::EPS, 20, 0.03);
62 : m_gray(), m_prevGray(), m_points_id(), m_maxCount(500), m_termcrit(), m_winSize(10), m_qualityLevel(0.01),
63 m_minDistance(15), m_minEigThreshold(1e-4), m_harris_k(0.04), m_blockSize(3), m_useHarrisDetector(1),
64 m_pyrMaxLevel(3), m_next_points_id(0), m_initial_guess(false)
101 for (
size_t i = 0; i < 2; i++) {
113 for (
size_t i = 0; i <
m_points[1].size(); i++)
123 std::vector<float> err;
129 flags |= cv::OPTFLOW_USE_INITIAL_FLOW;
143 std::vector<uchar> status;
149 for (
int i = (
int)status.size() - 1; i >= 0; i--) {
150 if (status[(
size_t)i] == 0) {
160 if ((
size_t)index >=
m_points[1].size()) {
175 const vpColor &color,
unsigned int thickness)
178 for (
size_t i = 0; i < features.size(); i++) {
186 unsigned int thickness)
189 for (
size_t i = 0; i < features.size(); i++) {
197 const std::vector<long> &featuresid,
const vpColor &color,
unsigned int thickness)
200 for (
size_t i = 0; i < features.size(); i++) {
205 std::ostringstream id;
213 const std::vector<long> &featuresid,
const vpColor &color,
unsigned int thickness)
216 for (
size_t i = 0; i < features.size(); i++) {
221 std::ostringstream id;
230 if (guess_pts.size() !=
m_points[1].size()) {
232 "Cannot set initial guess: size feature vector [%d] "
233 "and guess vector [%d] doesn't match",
234 m_points[1].size(), guess_pts.size()));
242 const std::vector<long> &fid)
244 if (guess_pts.size() != init_pts.size()) {
246 "Cannot set initial guess: size init vector [%d] and "
247 "guess vector [%d] doesn't match",
248 init_pts.size(), guess_pts.size()));
263 for (
size_t i = 0; i <
m_points[1].size(); i++) {
276 if (ids.size() != pts.size()) {
278 for (
size_t i = 0; i <
m_points[1].size(); i++)
283 for (
size_t i = 0; i <
m_points[1].size(); i++) {
318 if ((
size_t)index >=
m_points[1].size()) {
329 class VISP_EXPORT dummy_vpKltOpencv
332 dummy_vpKltOpencv() { };
335 #if !defined(VISP_BUILD_SHARED_LIBS)
337 void dummy_vpKltOpenCV_fct() { };
Class to define RGB colors available for display functionalities.
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
std::vector< long > m_points_id
Keypoint id.
void display(const vpImage< unsigned char > &I, const vpColor &color=vpColor::red, unsigned int thickness=1) const
int m_useHarrisDetector
true to use Harris detector
int m_maxCount
Max number of keypoints.
int m_blockSize
Block size.
void track(const cv::Mat &I)
double m_minDistance
Mins distance between keypoints.
vpKltOpencv & operator=(const vpKltOpencv ©)
cv::TermCriteria m_termcrit
Term criteria.
double m_minEigThreshold
Min eigen threshold.
void getFeature(const int &index, long &id, float &x, float &y) const
int m_pyrMaxLevel
Pyramid max level.
std::vector< cv::Point2f > m_points[2]
Previous [0] and current [1] keypoint location.
double m_qualityLevel
Quality level.
void suppressFeature(const int &index)
bool m_initial_guess
true when initial guess is provided
cv::Mat m_gray
Gray image.
void setInitialGuess(const std::vector< cv::Point2f > &guess_pts)
void addFeature(const float &x, const float &y)
double m_harris_k
Harris parameter.
void initTracking(const cv::Mat &I, const cv::Mat &mask=cv::Mat())
int m_winSize
Window criteria.
long m_next_points_id
Id for the newt keypoint.
cv::Mat m_prevGray
Previous gray image.
static int round(double x)
Error that can be emitted by the vpTracker class and its derivatives.
@ fatalError
Tracker fatal error.