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


visp_auto_tracker
Author(s): Filip Novotny
autogenerated on Wed Jul 3 2019 19:48:10