LucasKanadeTracker.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //*****************************************************************
  2. // File: LucasKanadeTracker.h
  3. // Author: Juan José Gómez Rodríguez (jjgomez96@hotmail.com)
  4. // Date: 01/05/2019
  5. // Coms: Header file of the Lucas-Kanade optical flow algorithm
  6. //*****************************************************************
  7. #ifndef KLT_H
  8. #define KLT_H
  9. #include<opencv2/core/core.hpp>
  10. #include "opencv2/opencv.hpp"
  11. class LucasKanadeTracker {
  12. public:
  13. /*
  14. * Default constructor
  15. */
  16. LucasKanadeTracker();
  17. /*
  18. * Constructor with parameters
  19. */
  20. LucasKanadeTracker(const cv::Size _winSize, const int _maxLevel, const int _maxIters,
  21. const float _epsilon, const float _minEigThreshold);
  22. /*
  23. *
  24. */
  25. void SetReferenceImage(cv::Mat &refIm, std::vector<cv::Point2f> &refPts);
  26. int PRE_Track(cv::Mat &newIm,
  27. std::vector<cv::Point2f> &nextPts, std::vector<bool> &status, const bool bInitialFlow,
  28. const bool bCheckLength);
  29. void DeleteRefPt(const int idx);
  30. cv::Point2f GetPrevPoint(const int idx);
  31. private:
  32. //-------------------------------
  33. // KLT parameters
  34. //-------------------------------
  35. cv::Size winSize; //size of the integration window of the Lucas-Kanade algorithm
  36. int maxLevel; //max level of the image pyramids
  37. int maxIters; //max number of iterations of the optical flow algorithm
  38. float epsilon; //minimum optical flow imposed displacement. If lower, we stop computing
  39. float minEigThreshold; //min eigen threshold value for the Spatial Gradient matrix
  40. //-------------------------------
  41. // Pre computed stuff
  42. //-------------------------------
  43. std::vector<cv::Point2f> prevPts; //Original coordinates of the points to track
  44. std::vector<cv::Mat> refPyr; //Reference pyramid
  45. std::vector<std::vector<float>> vMeanI; //Reference window mean intensities
  46. std::vector<std::vector<float>> vMeanI2; //Reference window mean sqared intensities
  47. std::vector<std::vector<cv::Mat>> Iref; //Reference windows
  48. std::vector<std::vector<cv::Mat>> Idref; //Reference derivative windows
  49. };
  50. #endif //KLT_H