tracking.h
Go to the documentation of this file.
1 #ifndef __TRACKING_H__
2 #define __TRACKING_H__
3 #include <boost/accumulators/accumulators.hpp>
4 #include <boost/accumulators/statistics.hpp>
5 #include <boost/accumulators/statistics/median.hpp>
6 #include <boost/accumulators/statistics/p_square_quantile.hpp>
7 
8 #include <iostream>
9 // back-end
10 #include <boost/msm/back/state_machine.hpp>
11 //front-end
12 #include <boost/msm/front/state_machine_def.hpp>
13 #include <boost/array.hpp>
14 
15 #include <visp3/core/vpImage.h>
16 #include <visp3/core/vpRGBa.h>
17 #include <visp3/core/vpHomogeneousMatrix.h>
18 #include <visp3/core/vpCameraParameters.h>
19 
20 #include <visp3/core/vpDisplay.h>
21 #include <visp3/core/vpHinkley.h>
22 #include <visp3/me/vpMe.h>
23 #include <vector>
24 #include <fstream>
25 
26 #include "visp_tracker/MovingEdgeSites.h"
27 #include "visp_tracker/KltPoints.h"
28 
29 #include "cmd_line/cmd_line.h"
30 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
32 #else
33 # include <visp/vpDetectorBase.h>
34 #endif
35 
36 #include <visp/vpMbEdgeTracker.h>
37 #include "states.hpp"
38 #include "events.h"
39 
40 using namespace boost::accumulators;
41 namespace msm = boost::msm;
42 namespace mpl = boost::mpl;
43 namespace tracking{
44 
45  class Tracker_ : public msm::front::state_machine_def<Tracker_>{
46  public:
47  typedef struct {
48  boost::accumulators::accumulator_set<
49  double,
50  boost::accumulators::stats<
51  boost::accumulators::tag::median(boost::accumulators::with_p_square_quantile),
52  boost::accumulators::tag::max,
53  boost::accumulators::tag::mean
54  >
55  > var,var_x,var_y,var_z,var_wx,var_wy,var_wz,checkpoints;
56 
57  } statistics_t;
58  private:
60  int iter_;
61  vpImagePoint flashcode_center_;
62  std::ofstream varfile_;
63 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
64  detectors::DetectorBase* detector_;
65 #else
66  vpDetectorBase *detector_;
67 #endif
68  typedef boost::array<vpHinkley,6> hinkley_array_t;
69  hinkley_array_t hink_;
70 
71  vpMbTracker* tracker_; // Create a model based tracker.
73  vpImage<vpRGBa> *I_;
74  vpImage<vpRGBa> *_I;
75  vpHomogeneousMatrix cMo_; // Pose computed using the tracker.
76  vpMatrix covariance_; // Covariance associated to the pose estimation
77  vpCameraParameters cam_;
78  vpImage<unsigned char> Igray_;
79 
80  std::vector<vpPoint> outer_points_3D_bcp_;
81  std::vector<vpPoint> points3D_inner_;
82  std::vector<vpPoint> points3D_outer_;
83  std::vector<vpPoint> points3D_middle_;
84  std::vector<vpPoint> f_;
86  cv::Rect cvTrackingBox_;
88 
91 
92  public:
93  //getters to access useful members
94  void set_flush_display(bool val);
95  bool get_flush_display();
96 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
97  detectors::DetectorBase& get_detector();
98 #else
99  vpDetectorBase& get_detector();
100 #endif
101  vpMbTracker& get_mbt();
102  std::vector<vpPoint>& get_points3D_inner();
103  std::vector<vpPoint>& get_points3D_outer();
104  std::vector<vpPoint>& get_points3D_middle();
105  std::vector<vpPoint>& get_flashcode();
106 
107  //returns tracking box where to look for pattern (may be full image)
108  template<class T>
109  const T& get_tracking_box();
110  //returns currently treated image
111  vpImage<vpRGBa>& get_I();
112  //returns camera parameters
113  vpCameraParameters& get_cam();
114  //returns tracker configuration
115  CmdLine& get_cmd();
116 
117  //constructor
118  //inits tracker from a detector, a visp tracker
119 
120  Tracker_(CmdLine& cmd, vpDetectorBase* detector, vpMbTracker *tracker_, bool flush_display = true);
121 
122  typedef WaitingForInput initial_state; //initial state of our state machine tracker
123 
124  //Guards
125  bool input_selected(input_ready const& evt);
126  bool no_input_selected(input_ready const& evt);
127  bool flashcode_detected(input_ready const& evt);
128  bool flashcode_redetected(input_ready const& evt);
129  bool model_detected(msm::front::none const&);
130  bool mbt_success(input_ready const& evt);
131 
132  //actions
133  void find_flashcode_pos(input_ready const& evt);
134  void track_model(input_ready const& evt);
135 
136  //gets statistics about the last tracking experience
137  statistics_t& get_statistics();
138 
139  void updateMovingEdgeSites(visp_tracker::MovingEdgeSitesPtr sites);
140  void updateKltPoints(visp_tracker::KltPointsPtr klt);
141 
142  //here is how the tracker works
143  struct transition_table : mpl::vector<
144  // Start Event Target Action Guard
145  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
146  g_row< WaitingForInput , input_ready , WaitingForInput , &Tracker_::no_input_selected >,
147  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
148  g_row< WaitingForInput , input_ready , DetectFlashcode , &Tracker_::input_selected >,
149  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
150  _row< WaitingForInput , select_input , DetectFlashcode >,
151  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
152  _row< DetectFlashcode , input_ready , DetectFlashcode /* default behaviour */ >,
153  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
154  row< DetectFlashcode , input_ready , DetectModel , &Tracker_::find_flashcode_pos,&Tracker_::flashcode_detected >,
155  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
156  _row< DetectModel , msm::front::none , DetectFlashcode /* default behaviour */ >,
157  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
158  g_row< DetectModel , msm::front::none , TrackModel , &Tracker_::model_detected >,
159  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
160  _row< TrackModel , input_ready , ReDetectFlashcode /* default behaviour */ >,
161  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
162  row< TrackModel , input_ready , TrackModel , &Tracker_::track_model ,&Tracker_::mbt_success >,
163  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
164  _row< ReDetectFlashcode, input_ready , DetectFlashcode /* default behaviour */ >,
165  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
166  row< ReDetectFlashcode, input_ready , DetectModel , &Tracker_::find_flashcode_pos,&Tracker_::flashcode_redetected >,
167  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
168  //row< ReDetectFlashcode, input_ready , TrackModel , &Tracker_::track_model ,&Tracker_::mbt_success >,
169  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
170  _row< TrackModel , finished , Finished >,
171  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
172  _row< DetectModel , finished , Finished >,
173  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
174  _row< DetectFlashcode , finished , Finished >,
175  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
176  _row< ReDetectFlashcode, finished , Finished >
177  // +------------------+--------------------+-----------------------+------------------------------+------------------------------+
178  > {};
179 
180  };
181 
182  typedef msm::back::state_machine<Tracker_> Tracker;
183 
184 
185 }
186 #endif //__TRACKING_H__
vpMbTracker * tracker_
Definition: tracking.h:71
vpImage< vpRGBa > * _I
Definition: tracking.h:74
vpCameraParameters cam_
Definition: tracking.h:77
vpHomogeneousMatrix cMo_
Definition: tracking.h:75
boost::accumulators::accumulator_set< double, boost::accumulators::stats< boost::accumulators::tag::median(boost::accumulators::with_p_square_quantile), boost::accumulators::tag::max, boost::accumulators::tag::mean > > var_z
Definition: tracking.h:55
vpMe tracker_me_config_
Definition: tracking.h:72
std::vector< vpPoint > outer_points_3D_bcp_
Definition: tracking.h:80
msm::back::state_machine< Tracker_ > Tracker
Definition: tracking.h:182
vpImage< vpRGBa > * I_
Definition: tracking.h:73
vpRect vpTrackingBox_
Definition: tracking.h:85
std::vector< vpPoint > points3D_inner_
Definition: tracking.h:81
WaitingForInput initial_state
Definition: tracking.h:122
boost::array< vpHinkley, 6 > hinkley_array_t
Definition: tracking.h:68
std::vector< vpPoint > f_
Definition: tracking.h:84
vpMatrix covariance_
Definition: tracking.h:76
std::ofstream varfile_
Definition: tracking.h:62
hinkley_array_t hink_
Definition: tracking.h:69
std::vector< vpPoint > points3D_middle_
Definition: tracking.h:83
statistics_t statistics
Definition: tracking.h:89
vpDetectorBase * detector_
Definition: tracking.h:66
vpImagePoint flashcode_center_
Definition: tracking.h:61
vpImage< unsigned char > Igray_
Definition: tracking.h:78
cv::Rect cvTrackingBox_
Definition: tracking.h:86
std::vector< vpPoint > points3D_outer_
Definition: tracking.h:82
Definition: events.h:6
bool cvTrackingBox_init_
Definition: tracking.h:87


visp_auto_tracker
Author(s): Filip Novotny
autogenerated on Sat Mar 13 2021 03:20:08