Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpMbKltTracker.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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 * Model based tracker using only KLT
32 */
33
38
39#ifndef _vpMbKltTracker_h_
40#define _vpMbKltTracker_h_
41
42#include <visp3/core/vpConfig.h>
43
44#if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
45
46#include <visp3/core/vpExponentialMap.h>
47#include <visp3/core/vpMeterPixelConversion.h>
48#include <visp3/core/vpPixelMeterConversion.h>
49#include <visp3/core/vpSubColVector.h>
50#include <visp3/core/vpSubMatrix.h>
51#include <visp3/klt/vpKltOpencv.h>
52#include <visp3/mbt/vpMbTracker.h>
53#include <visp3/mbt/vpMbtDistanceCircle.h>
54#include <visp3/mbt/vpMbtDistanceKltCylinder.h>
55#include <visp3/mbt/vpMbtDistanceKltPoints.h>
56#include <visp3/vision/vpHomography.h>
57
231class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker
232{
233protected:
235 cv::Mat cur;
242 unsigned int maskBorder;
255 std::list<vpMbtDistanceKltPoints *> kltPolygons;
257 std::list<vpMbtDistanceKltCylinder *> kltCylinders;
259 std::list<vpMbtDistanceCircle *> circles_disp;
261 unsigned int m_nbInfos;
263 unsigned int m_nbFaceUsed;
275 std::vector<std::vector<double> > m_featuresToBeDisplayedKlt;
276
277public:
279 virtual ~vpMbKltTracker();
280
283
284 void addCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, const std::string &name = "");
285 virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
286 const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE;
287 virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
288 const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE;
289
291 virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle() { return circles_disp; }
293 virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder() { return kltCylinders; }
295 virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt() { return kltPolygons; }
296
302 inline std::vector<cv::Point2f> getKltPoints() const { return tracker.getFeatures(); }
303
304 std::vector<vpImagePoint> getKltImagePoints() const;
305
306 std::map<int, vpImagePoint> getKltImagePointsWithId() const;
307
313 inline vpKltOpencv getKltOpencv() const { return tracker; }
314
320 inline unsigned int getKltMaskBorder() const { return maskBorder; }
321
327 inline int getKltNbPoints() const { return tracker.getNbFeatures(); }
328
335 inline double getKltThresholdAcceptation() const { return threshold_outlier; }
336
337 virtual inline vpColVector getError() const VP_OVERRIDE { return m_error_klt; }
338
339 virtual inline vpColVector getRobustWeights() const VP_OVERRIDE { return m_w_klt; }
340
341 virtual std::vector<std::vector<double> > getModelForDisplay(unsigned int width, unsigned int height,
342 const vpHomogeneousMatrix &cMo,
343 const vpCameraParameters &cam,
344 bool displayFullModel = false) VP_OVERRIDE;
345
346 virtual void loadConfigFile(const std::string &configFile, bool verbose = true) VP_OVERRIDE;
347
348 virtual void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo,
349 bool verbose = false, const vpHomogeneousMatrix &T = vpHomogeneousMatrix());
350 void resetTracker() VP_OVERRIDE;
351
352 void setCameraParameters(const vpCameraParameters &cam) VP_OVERRIDE;
353
359 inline void setKltMaskBorder(const unsigned int &e)
360 {
361 maskBorder = e;
362 // if(useScanLine)
363 faces.getMbScanLineRenderer().setMaskBorder(maskBorder);
364 }
365
366 virtual void setKltOpencv(const vpKltOpencv &t);
367
373 inline void setKltThresholdAcceptation(double th) { threshold_outlier = th; }
374
383 virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE
384 {
386#ifdef VISP_HAVE_OGRE
387 faces.getOgreContext()->setWindowName("MBT Klt");
388#endif
389 }
390
396 virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE
397 {
399
400 for (std::list<vpMbtDistanceKltPoints *>::const_iterator it = kltPolygons.begin(); it != kltPolygons.end(); ++it)
401 (*it)->useScanLine = v;
402 }
403
404 virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE;
405 virtual void setPose(const vpImage<vpRGBa> &I_color, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE;
406
413 virtual void setProjectionErrorComputation(const bool &flag) VP_OVERRIDE
414 {
415 if (flag)
416 std::cerr << "This option is not yet implemented in vpMbKltTracker, "
417 "projection error computation set to false."
418 << std::endl;
419 }
420
421 void setUseKltTracking(const std::string &name, const bool &useKltTracking);
422
423 virtual void testTracking() VP_OVERRIDE;
424 virtual void track(const vpImage<unsigned char> &I) VP_OVERRIDE;
425 virtual void track(const vpImage<vpRGBa> &I_color) VP_OVERRIDE;
426
431
438 /* VP_DEPRECATED */ inline unsigned int getMaskBorder() const { return maskBorder; }
439
446 /* VP_DEPRECATED */ inline int getNbKltPoints() const { return tracker.getNbFeatures(); }
447
455 /* VP_DEPRECATED */ inline double getThresholdAcceptation() const { return threshold_outlier; }
456
462 /* VP_DEPRECATED */ inline void setMaskBorder(const unsigned int &e)
463 {
464 maskBorder = e;
465 // if(useScanLine)
466 faces.getMbScanLineRenderer().setMaskBorder(maskBorder);
467 }
468
475 /* VP_DEPRECATED */ inline void setThresholdAcceptation(double th) { threshold_outlier = th; }
476
478
479protected:
482 void computeVVS();
483 virtual void computeVVSInit() VP_OVERRIDE;
484 virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE;
485
486 virtual std::vector<std::vector<double> > getFeaturesForDisplayKlt();
487
488 virtual void init(const vpImage<unsigned char> &I) VP_OVERRIDE;
489 virtual void initFaceFromCorners(vpMbtPolygon &polygon) VP_OVERRIDE;
490 virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE;
491 virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, double, int, const std::string &name = "") VP_OVERRIDE;
492 virtual void initCylinder(const vpPoint &, const vpPoint &, double, int, const std::string &name = "") VP_OVERRIDE;
493
494 void preTracking(const vpImage<unsigned char> &I);
495 bool postTracking(const vpImage<unsigned char> &I, vpColVector &w);
496 virtual void reinit(const vpImage<unsigned char> &I);
497 virtual void setPose(const vpImage<unsigned char> *I, const vpImage<vpRGBa> *I_color,
498 const vpHomogeneousMatrix &cdMo);
500};
501END_VISP_NAMESPACE
502#endif
503#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:157
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
Definition vpKltOpencv.h:83
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
std::list< vpMbtDistanceKltCylinder * > kltCylinders
virtual std::list< vpMbtDistanceCircle * > & getFeaturesCircle()
vpColVector m_error_klt
(s - s*)
vpHomogeneousMatrix c0Mo
Initial pose.
void addCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, const std::string &name="")
void setMaskBorder(const unsigned int &e)
vpHomogeneousMatrix ctTc0
virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE
std::list< vpMbtDistanceKltPoints * > kltPolygons
double getKltThresholdAcceptation() const
virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE
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 vpColVector getError() const VP_OVERRIDE
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 std::list< vpMbtDistanceKltCylinder * > & getFeaturesKltCylinder()
virtual vpColVector getRobustWeights() const VP_OVERRIDE
double getThresholdAcceptation() 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.
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false) VP_OVERRIDE
void setKltMaskBorder(const unsigned int &e)
virtual void setProjectionErrorComputation(const bool &flag) VP_OVERRIDE
int getNbKltPoints() const
virtual std::list< vpMbtDistanceKltPoints * > & getFeaturesKlt()
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)=0
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
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 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
Manage a circle used in the model-based tracker.
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:79
Contains an M-estimator and various influence function.
Definition vpRobust.h:84