Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpMbKltTracker.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See https://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Model based tracker using only KLT
33 *
34*****************************************************************************/
40#ifndef _vpMbKltTracker_h_
41#define _vpMbKltTracker_h_
42
43#include <visp3/core/vpConfig.h>
44
45#if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
46
47#include <visp3/core/vpExponentialMap.h>
48#include <visp3/core/vpMeterPixelConversion.h>
49#include <visp3/core/vpPixelMeterConversion.h>
50#include <visp3/core/vpSubColVector.h>
51#include <visp3/core/vpSubMatrix.h>
52#include <visp3/klt/vpKltOpencv.h>
53#include <visp3/mbt/vpMbTracker.h>
54#include <visp3/mbt/vpMbtDistanceCircle.h>
55#include <visp3/mbt/vpMbtDistanceKltCylinder.h>
56#include <visp3/mbt/vpMbtDistanceKltPoints.h>
57#include <visp3/vision/vpHomography.h>
58
206class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker
207{
208protected:
210 cv::Mat cur;
217 unsigned int maskBorder;
230 std::list<vpMbtDistanceKltPoints *> kltPolygons;
232 std::list<vpMbtDistanceKltCylinder *> kltCylinders;
234 std::list<vpMbtDistanceCircle *> circles_disp;
236 unsigned int m_nbInfos;
238 unsigned int m_nbFaceUsed;
250 std::vector<std::vector<double> > m_featuresToBeDisplayedKlt;
251
252public:
254 virtual ~vpMbKltTracker();
255
258
259 void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, double r, const std::string &name = "");
260 virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
261 const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false);
262 virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
263 const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false);
264
266 virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle() { return circles_disp; }
268 virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder() { return kltCylinders; }
270 virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt() { return kltPolygons; }
271
277 inline std::vector<cv::Point2f> getKltPoints() const { return tracker.getFeatures(); }
278
279 std::vector<vpImagePoint> getKltImagePoints() const;
280
281 std::map<int, vpImagePoint> getKltImagePointsWithId() const;
282
288 inline vpKltOpencv getKltOpencv() const { return tracker; }
289
295 inline unsigned int getKltMaskBorder() const { return maskBorder; }
296
302 inline int getKltNbPoints() const { return tracker.getNbFeatures(); }
303
310 inline double getKltThresholdAcceptation() const { return threshold_outlier; }
311
312 virtual inline vpColVector getError() const { return m_error_klt; }
313
314 virtual inline vpColVector getRobustWeights() const { return m_w_klt; }
315
316 virtual std::vector<std::vector<double> > getModelForDisplay(unsigned int width, unsigned int height,
317 const vpHomogeneousMatrix &cMo,
318 const vpCameraParameters &cam,
319 bool displayFullModel = false);
320
321 virtual void loadConfigFile(const std::string &configFile, bool verbose = true);
322
323 virtual void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo,
324 bool verbose = false, const vpHomogeneousMatrix &T = vpHomogeneousMatrix());
325 void resetTracker();
326
328
334 inline void setKltMaskBorder(const unsigned int &e)
335 {
336 maskBorder = e;
337 // if(useScanLine)
338 faces.getMbScanLineRenderer().setMaskBorder(maskBorder);
339 }
340
341 virtual void setKltOpencv(const vpKltOpencv &t);
342
348 inline void setKltThresholdAcceptation(double th) { threshold_outlier = th; }
349
358 virtual void setOgreVisibilityTest(const bool &v)
359 {
361#ifdef VISP_HAVE_OGRE
362 faces.getOgreContext()->setWindowName("MBT Klt");
363#endif
364 }
365
371 virtual void setScanLineVisibilityTest(const bool &v)
372 {
374
375 for (std::list<vpMbtDistanceKltPoints *>::const_iterator it = kltPolygons.begin(); it != kltPolygons.end(); ++it)
376 (*it)->useScanLine = v;
377 }
378
379 virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cdMo);
380 virtual void setPose(const vpImage<vpRGBa> &I_color, const vpHomogeneousMatrix &cdMo);
381
388 virtual void setProjectionErrorComputation(const bool &flag)
389 {
390 if (flag)
391 std::cerr << "This option is not yet implemented in vpMbKltTracker, "
392 "projection error computation set to false."
393 << std::endl;
394 }
395
396 void setUseKltTracking(const std::string &name, const bool &useKltTracking);
397
398 virtual void testTracking();
399 virtual void track(const vpImage<unsigned char> &I);
400 virtual void track(const vpImage<vpRGBa> &I_color);
401
406
413 /* vp_deprecated */ inline unsigned int getMaskBorder() const { return maskBorder; }
420 /* vp_deprecated */ inline int getNbKltPoints() const { return tracker.getNbFeatures(); }
421
429 /* vp_deprecated */ inline double getThresholdAcceptation() const { return threshold_outlier; }
435 /* vp_deprecated */ inline void setMaskBorder(const unsigned int &e)
436 {
437 maskBorder = e;
438 // if(useScanLine)
439 faces.getMbScanLineRenderer().setMaskBorder(maskBorder);
440 }
441
448 /* vp_deprecated */ inline void setThresholdAcceptation(double th) { threshold_outlier = th; }
449
451
452protected:
455 void computeVVS();
456 virtual void computeVVSInit();
458
459 virtual std::vector<std::vector<double> > getFeaturesForDisplayKlt();
460
461 virtual void init(const vpImage<unsigned char> &I);
462 virtual void initFaceFromCorners(vpMbtPolygon &polygon);
463 virtual void initFaceFromLines(vpMbtPolygon &polygon);
464 virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, double, int, const std::string &name = "");
465 virtual void initCylinder(const vpPoint &, const vpPoint &, double, int, const std::string &name = "");
466
467 void preTracking(const vpImage<unsigned char> &I);
468 bool postTracking(const vpImage<unsigned char> &I, vpColVector &w);
469 virtual void reinit(const vpImage<unsigned char> &I);
470 virtual void setPose(const vpImage<unsigned char> *const I, const vpImage<vpRGBa> *const I_color,
471 const vpHomogeneousMatrix &cdMo);
473};
474
475#endif
476#endif // VISP_HAVE_OPENCV
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Class to define RGB colors available for display functionalities.
Definition vpColor.h:152
Implementation of an homogeneous matrix and operations on such kind of matrices.
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
int getNbFeatures() const
Get the number of current features.
std::vector< cv::Point2f > getFeatures() const
Get the list of current features.
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:152
Model based tracker using only KLT.
std::list< vpMbtDistanceKltCylinder * > kltCylinders
virtual std::list< vpMbtDistanceCircle * > & getFeaturesCircle()
vpColVector m_error_klt
(s - s*)
vpHomogeneousMatrix c0Mo
Initial pose.
virtual void setScanLineVisibilityTest(const bool &v)
void setMaskBorder(const unsigned int &e)
vpHomogeneousMatrix ctTc0
std::list< vpMbtDistanceKltPoints * > kltPolygons
double getKltThresholdAcceptation() const
cv::Mat cur
Temporary OpenCV image for fast conversion.
std::vector< cv::Point2f > getKltPoints() const
unsigned int getKltMaskBorder() const
std::list< vpMbtDistanceCircle * > circles_disp
Vector of the circles used here only to display the full model.
vpColVector m_weightedError_klt
Weighted error.
vpKltOpencv tracker
Points tracker.
virtual void setProjectionErrorComputation(const bool &flag)
unsigned int m_nbInfos
unsigned int getMaskBorder() const
vpKltOpencv getKltOpencv() const
void setKltThresholdAcceptation(double th)
void setThresholdAcceptation(double th)
vpRobust m_robust_klt
Robust.
int getKltNbPoints() const
virtual void setOgreVisibilityTest(const bool &v)
virtual std::list< vpMbtDistanceKltCylinder * > & getFeaturesKltCylinder()
double getThresholdAcceptation() const
virtual vpColVector getError() const
unsigned int maskBorder
Erosion of the mask.
unsigned int m_nbFaceUsed
vpColVector m_w_klt
Robust weights.
std::vector< std::vector< double > > m_featuresToBeDisplayedKlt
Display features.
vpMatrix m_L_klt
Interaction matrix.
void setKltMaskBorder(const unsigned int &e)
int getNbKltPoints() const
virtual std::list< vpMbtDistanceKltPoints * > & getFeaturesKlt()
virtual vpColVector getRobustWeights() const
Main methods for a model-based tracker.
virtual void track(const vpImage< unsigned char > &I)=0
virtual void resetTracker()=0
virtual void init(const vpImage< unsigned char > &I)=0
virtual void initFaceFromLines(vpMbtPolygon &polygon)=0
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace=0, const std::string &name="")=0
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace=0, const std::string &name="")=0
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)=0
virtual void setCameraParameters(const vpCameraParameters &cam)
virtual void setScanLineVisibilityTest(const bool &v)
virtual void setOgreVisibilityTest(const bool &v)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)=0
virtual void computeVVSInteractionMatrixAndResidu()=0
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)=0
virtual void computeVVSInit()=0
virtual void testTracking()=0
virtual void initFaceFromCorners(vpMbtPolygon &polygon)=0
virtual void loadConfigFile(const std::string &configFile, bool verbose=true)
Implementation of a polygon of the model used by the model-based tracker.
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:77
Contains an M-estimator and various influence function.
Definition vpRobust.h:83