tracking.cpp
Go to the documentation of this file.
1 #include "ros/ros.h"
2 #include "cv.h"
3 #include "highgui.h"
4 #include "tracking.h"
5 #include <visp/vpImageConvert.h>
6 #include <visp/vpPixelMeterConversion.h>
7 #include <visp/vpImagePoint.h>
8 #include <visp/vpDisplayX.h>
9 #include <visp/vpPose.h>
10 #include <visp/vpMeterPixelConversion.h>
11 #include <visp/vpTrackingException.h>
12 #include <visp/vpImageIo.h>
13 #include <visp/vpRect.h>
14 #include <visp/vpMbKltTracker.h>
15 #include <visp/vpMbEdgeTracker.h>
16 
17 #include "logfilewriter.hpp"
18 
19 namespace tracking{
20 
21 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
22  Tracker_:: Tracker_(CmdLine& cmd, detectors::DetectorBase* detector,vpMbTracker* tracker,bool flush_display) :
23 #else
24  Tracker_:: Tracker_(CmdLine& cmd, vpDetectorBase* detector,vpMbTracker* tracker,bool flush_display) :
25 #endif
26  cmd(cmd),
27  iter_(0),
28  flashcode_center_(640/2,480/2),
29  detector_(detector),
30  tracker_(tracker),
31  flush_display_(flush_display){
32  std::cout << "starting tracker" << std::endl;
33  cvTrackingBox_init_ = false;
34  cvTrackingBox_.x = 0;
35  cvTrackingBox_.y = 0;
36  cvTrackingBox_.width = 0;
37  cvTrackingBox_.height = 0;
38 
39  // Retrieve camera parameters comming from camera_info message in order to update them after loadConfigFile()
40  tracker_->getCameraParameters(cam_); // init camera parameters
41 
42  points3D_inner_ = cmd.get_inner_points_3D();
43  points3D_outer_ = cmd.get_outer_points_3D();
44  outer_points_3D_bcp_ = cmd.get_outer_points_3D();
45  if(cmd.using_adhoc_recovery() || cmd.log_checkpoints()){
46  for(unsigned int i=0;i<points3D_outer_.size();i++){
47  vpPoint p;
48  p.setWorldCoordinates(
49  (points3D_outer_[i].get_oX()+points3D_inner_[i].get_oX())*cmd.get_adhoc_recovery_ratio(),
50  (points3D_outer_[i].get_oY()+points3D_inner_[i].get_oY())*cmd.get_adhoc_recovery_ratio(),
51  (points3D_outer_[i].get_oZ()+points3D_inner_[i].get_oZ())*cmd.get_adhoc_recovery_ratio()
52  );
53  points3D_middle_.push_back(p);
54  }
55  }
56  f_ = cmd.get_flashcode_points_3D();
57 
58  if(cmd.using_var_file()){
59  varfile_.open(cmd.get_var_file().c_str(),std::ios::out);
60  varfile_ << "#These are variances and other data from the model based tracker in gnuplot format" << std::endl;
61  if(cmd.using_hinkley())
62  varfile_ << "iteration\tvar_x\var_y\tvar_z\tvar_wx\tvar_wy\var_wz";
63  if(cmd.using_mbt_dynamic_range())
64  varfile_ << "\tmbt_range";
65  if(cmd.log_pose())
66  varfile_ << "\tpose_tx\tpose_ty\tpose_tz\tpose_rx\tpose_ry\tpose_rz";
67  if(cmd.log_checkpoints())
68  varfile_ << "\tcheckpoint_median";
69 
70  varfile_ << std::endl;
71  }
72 
73  if(cmd.using_hinkley()){
74  if(cmd.get_verbose())
75  std::cout << "Initialising hinkley with alpha=" << cmd.get_hinkley_alpha() << " and delta=" << cmd.get_hinkley_delta() << std::endl;
76  for(hinkley_array_t::iterator i = hink_.begin();i!=hink_.end();i++)
77  i->init(cmd.get_hinkley_alpha(),cmd.get_hinkley_delta());
78  }
79 
80  if(cmd.using_mbt_dynamic_range()){
81  vpMbEdgeTracker *tracker_me = dynamic_cast<vpMbEdgeTracker*>(tracker_);
82  if(tracker_me)
83  tracker_me->getMovingEdge(tracker_me_config_);
84  else
85  std::cout << "error: could not init moving edges on tracker that doesn't support them." << std::endl;
86  }
87 
88  tracker_->loadConfigFile(cmd.get_xml_file() ); // Load the configuration of the tracker
89  tracker_->loadModel(cmd.get_mbt_cad_file()); // load the 3d model, to read .wrl model the 3d party library coin is required, if coin is not installed .cao file can be used.
90  tracker_->setCameraParameters(cam_); // Set the good camera parameters coming from camera_info message
91  }
92 
93 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
95 #else
96  vpDetectorBase& Tracker_:: get_detector(){
97 #endif
98  return *detector_;
99  }
100 
101  vpMbTracker& Tracker_:: get_mbt(){
102  return *tracker_;
103  }
104 
105  std::vector<vpPoint>& Tracker_:: get_points3D_inner(){
106  return points3D_inner_;
107  }
108 
109  std::vector<vpPoint>& Tracker_:: get_points3D_outer(){
110  return points3D_outer_;
111 
112  }
113 
114  std::vector<vpPoint>& Tracker_:: get_points3D_middle(){
115  return points3D_middle_;
116  }
117 
118  std::vector<vpPoint>& Tracker_:: get_flashcode(){
119  return f_;
120  }
121 
122  vpImage<vpRGBa>& Tracker_:: get_I(){
123  return *I_;
124  }
125 
126  vpCameraParameters& Tracker_:: get_cam(){
127  return cam_;
128  }
129 
131  return cmd;
132  }
133 
134  template<>
135  const cv::Rect& Tracker_:: get_tracking_box<cv::Rect>(){
136  return cvTrackingBox_;
137  }
138 
139  template<>
140  const vpRect& Tracker_:: get_tracking_box<vpRect>(){
141  return vpTrackingBox_;
142  }
143 
145  return vpDisplay::getClick(evt.I,false);
146  }
147 
148 
150  return !input_selected(evt);
151  }
152 
154 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
155  //this->cam_ = evt.cam_;
156 
157  cv::Mat rgba = cv::Mat((int)evt.I.getRows(), (int)evt.I.getCols(), CV_8UC4, (void*)evt.I.bitmap);
158 
159  cv::Mat bgr = cv::Mat((int)evt.I.getRows(), (int)evt.I.getCols(), CV_8UC3);
160  cv::Mat alpha((int)evt.I.getRows(), (int)evt.I.getCols(), CV_8UC1);
161 
162  cv::Mat out[] = {bgr, alpha};
163  // rgba[0] -> bgr[2], rgba[1] -> bgr[1],
164  // rgba[2] -> bgr[0], rgba[3] -> alpha[0]
165  int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
166  cv::mixChannels(&rgba, 1, out, 2, from_to, 4);
167 
168  //vpImageConvert::convert(evt.I,bgr);
169 
170  return detector_->detect(bgr,cmd.get_dmx_timeout(),0,0);
171 #else
172  vpImageConvert::convert(evt.I, Igray_);
173  detector_->detect(Igray_);
174  if (detector_->getNbObjects()) {
175  if (cmd.get_code_message().empty()) {
176  cmd.set_code_message_index(0); // we retain the largest code at index 0
177  return true;
178  }
179  else {
180  for (size_t i=0; i<detector_->getNbObjects(); i++) {
181  if (detector_->getMessage(i) == cmd.get_code_message()) {
183  ROS_WARN_STREAM("Code with message \"" << cmd.get_code_message() << "\" found");
184  return true;
185  }
186  }
187  ROS_WARN_STREAM("Code with message \"" << cmd.get_code_message() << "\" not found");
188  return false;
189  }
190  }
191  return false;
192 #endif
193  }
194 
195  /*
196  * Detect flashcode in region delimited by the outer points of the model
197  * The timeout is the default timeout times the surface ratio
198  */
200 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
201  //this->cam_ = evt.cam_;
202 
203  //vpImageConvert::convert(evt.I,cvI);
204  cv::Mat rgba = cv::Mat((int)evt.I.getRows(), (int)evt.I.getCols(), CV_8UC4, (void*)evt.I.bitmap);
205 
206  cv::Mat bgr = cv::Mat((int)evt.I.getRows(), (int)evt.I.getCols(), CV_8UC3);
207  cv::Mat alpha((int)evt.I.getRows(), (int)evt.I.getCols(), CV_8UC1);
208 
209  cv::Mat out[] = {bgr, alpha};
210  // rgba[0] -> bgr[2], rgba[1] -> bgr[1],
211  // rgba[2] -> bgr[0], rgba[3] -> alpha[0]
212  int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
213  cv::mixChannels(&rgba, 1, out, 2, from_to, 4);
214 
216  {
217  cv::Mat subImage = cv::Mat(bgr,get_tracking_box<cv::Rect>()).clone();
218 
219  double timeout = cmd.get_dmx_timeout()*(double)(get_tracking_box<cv::Rect>().width*get_tracking_box<cv::Rect>().height)/(double)(bgr.cols*bgr.rows);
220  return detector_->detect(subImage,(unsigned int)timeout,get_tracking_box<cv::Rect>().x,get_tracking_box<cv::Rect>().y);
221  }
222  else
223  {
224  return detector_->detect(bgr,cmd.get_dmx_timeout(),0,0);
225  }
226 #else
227  // TODO, use boundig box as for ViSP < 2.10.0
228  vpImageConvert::convert(evt.I, Igray_);
229  detector_->detect(Igray_);
230  if (detector_->getNbObjects()) {
231  if (cmd.get_code_message().empty()) {
232  cmd.set_code_message_index(0); // we retain the largest code at index 0
233  return true;
234  }
235  else {
236  for (size_t i=0; i<detector_->getNbObjects(); i++) {
237  if (detector_->getMessage(i) == cmd.get_code_message()) {
239  ROS_WARN_STREAM("Code with message \"" << cmd.get_code_message() << "\" found");
240  return true;
241  }
242  }
243  ROS_WARN_STREAM("Code with message \"" << cmd.get_code_message() << "\" not found");
244  return false;
245  }
246  }
247  return false;
248 #endif
249  }
250 
252  this->cam_ = evt.cam_;
253 
254 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
255  std::vector<cv::Point> polygon = detector_->get_polygon();
256  double centerX = (double)(polygon[0].x+polygon[1].x+polygon[2].x+polygon[3].x)/4.;
257  double centerY = (double)(polygon[0].y+polygon[1].y+polygon[2].y+polygon[3].y)/4.;
258  vpPixelMeterConversion::convertPoint(cam_, flashcode_center_, centerX, centerY);
259 
260  for(unsigned int i=0;i<f_.size();i++){
261  double x=0, y=0;
262  vpImagePoint poly_pt(polygon[i].y,polygon[i].x);
263 
264  vpPixelMeterConversion::convertPoint(cam_, poly_pt, x, y);
265  f_[i].set_x(x);
266  f_[i].set_y(y);
267  }
268 #else
269  // TODO: add a parameter to be able to select the QRcode from it's message
270  // For the moment we get the position of the first code that is the largest in the image
271  std::vector< std::vector< vpImagePoint > > polygons = detector_->getPolygon();
272  std::vector< vpImagePoint > polygon(4);
273  if (polygons.size())
274  polygon = polygons[0];
275 
276  // TODO: remove flashcode_center_, centerX, centerY that are not used
277  //double centerX = cog.get_u();
278  //double centerY = cog.get_v();
279  //vpPixelMeterConversion::convertPoint(cam_, flashcode_center_, centerX, centerY);
280 
281  for(unsigned int i=0;i<f_.size();i++){
282  double x=0, y=0;
283 
284  vpPixelMeterConversion::convertPoint(cam_, polygon[i], x, y);
285  f_[i].set_x(x);
286  f_[i].set_y(y);
287  }
288 #endif
289 
290  I_ = _I = &(evt.I);
291  }
292 
293 
294  bool Tracker_:: model_detected(msm::front::none const&){
295  vpImageConvert::convert(*I_,Igray_);
296  vpPose pose;
297 
298  for(unsigned int i=0;i<f_.size();i++)
299  pose.addPoint(f_[i]);
300 
301  try {
302  vpHomogeneousMatrix cMo_dem;
303  vpHomogeneousMatrix cMo_lag;
304  pose.computePose(vpPose::DEMENTHON, cMo_dem);
305  pose.computePose(vpPose::LAGRANGE, cMo_lag);
306  double residual_dem = pose.computeResidual(cMo_dem);
307  double residual_lag = pose.computeResidual(cMo_lag);
308  if (residual_dem < residual_lag)
309  cMo_ = cMo_dem;
310  else
311  cMo_ = cMo_lag;
312  pose.computePose(vpPose::VIRTUAL_VS,cMo_);
313  //vpDisplay::displayFrame(*I_,cMo_,cam_,0.01,vpColor::none,2);
314  }
315  catch(vpException& e) {
316  std::cout << "Pose computation failed: " << e.getStringMessage() << std::endl;
317  return false;
318  }
319 
320  std::vector<vpImagePoint> model_inner_corner(4);
321  std::vector<vpImagePoint> model_outer_corner(4);
322  for(unsigned int i=0;i<4;i++){
323  points3D_outer_[i].project(cMo_);
324  points3D_inner_[i].project(cMo_);
326  points3D_middle_[i].project(cMo_);
327  vpMeterPixelConversion::convertPoint(cam_,points3D_outer_[i].get_x(),points3D_outer_[i].get_y(),model_outer_corner[i]);
328  vpMeterPixelConversion::convertPoint(cam_,points3D_inner_[i].get_x(),points3D_inner_[i].get_y(),model_inner_corner[i]);
329 
330  if(cmd.get_verbose()){
331  std::cout << "model inner corner: (" << model_inner_corner[i].get_i() << "," << model_inner_corner[i].get_j() << ")" << std::endl;
332  }
333  }
334 
335  try{
336  tracker_->resetTracker();
337  tracker_->loadConfigFile(cmd.get_xml_file() );
338  tracker_->loadModel(cmd.get_mbt_cad_file()); // load the 3d model, to read .wrl model the 3d party library coin is required, if coin is not installed .cao file can be used.
339  tracker_->setCameraParameters(cam_);
340  {
341  vpCameraParameters cam;
342  tracker_->getCameraParameters(cam);
343  if (cam.get_px() != 558) ROS_INFO_STREAM("detection Camera parameters: \n" << cam_);
344  }
345 
346  tracker_->initFromPose(Igray_,cMo_);
347 
348  tracker_->track(Igray_); // track the object on this image
349  tracker_->getPose(cMo_); // get the pose
350  tracker_->setCovarianceComputation(true);
351  for(int i=0;i<cmd.get_mbt_convergence_steps();i++){
352  tracker_->track(Igray_); // track the object on this image
353  tracker_->getPose(cMo_); // get the pose
354  }
355  }catch(vpException& e){
356  std::cout << "Tracking failed" << std::endl;
357  std::cout << e.getStringMessage() << std::endl;
358  return false;
359  }
360  return true;
361  }
362 
364  iter_ = evt.frame;
365  this->cam_ = evt.cam_;
366 
367  try{
368  LogFileWriter writer(varfile_); //the destructor of this class will act as a finally statement
369  vpImageConvert::convert(evt.I,Igray_);
370 
371  tracker_->track(Igray_); // track the object on this image
372  tracker_->getPose(cMo_);
373  covariance_ = tracker_->getCovarianceMatrix();
374  if(cmd.using_var_file()){
375  writer.write(iter_);
376  for(unsigned int i=0;i<covariance_.getRows();i++)
377  writer.write(covariance_[i][i]);
378  }
379  if(cmd.using_var_limit())
380  for(unsigned int i=0; i<6; i++)
381  if(covariance_[i][i]>cmd.get_var_limit())
382  return false;
383  if(cmd.using_hinkley())
384  for(unsigned int i=0; i<6; i++){
385  if(hink_[i].testDownUpwardJump(covariance_[i][i]) != vpHinkley::noJump){
386  writer.write(covariance_[i][i]);
387  if(cmd.get_verbose())
388  std::cout << "Hinkley:detected jump!" << std::endl;
389  return false;
390  }
391  }
393  writer.write(tracker_me_config_.getRange());
394 
395  for(unsigned int i=0;i<covariance_.getRows();i++) {
396  statistics.var(covariance_[i][i]);
397  }
398 
399  if(covariance_.getRows() == 6){ //if the covariance matrix is set
406  }
407 
408  if(cmd.using_var_file() && cmd.log_pose()){
409  vpPoseVector p(cMo_);
410  for(unsigned int i=0;i<p.getRows();i++)
411  writer.write(p[i]);
412  }
413 
415  for(unsigned int p=0;p<points3D_middle_.size();p++){
416  vpPoint& point3D = points3D_middle_[p];
417 
418  double _u=0.,_v=0.,_u_inner=0.,_v_inner=0.;
419  point3D.project(cMo_);
420  vpMeterPixelConversion::convertPoint(cam_,point3D.get_x(),point3D.get_y(),_u,_v);
421  vpMeterPixelConversion::convertPoint(cam_,points3D_inner_[p].get_x(),points3D_inner_[p].get_y(),_u_inner,_v_inner);
422 
423  boost::accumulators::accumulator_set<
424  unsigned char,
425  boost::accumulators::stats<
426  boost::accumulators::tag::median(boost::accumulators::with_p_square_quantile)
427  >
428  > acc;
429 
430  int region_width= std::max((int)(std::abs(_u-_u_inner)*cmd.get_adhoc_recovery_size()),1);
431  int region_height=std::max((int)(std::abs(_v-_v_inner)*cmd.get_adhoc_recovery_size()),1);
432  int u=(int)_u;
433  int v=(int)_v;
434  for(int i=std::max(u-region_width,0);
435  i<std::min(u+region_width,(int)evt.I.getWidth());
436  i++){
437  for(int j=std::max(v-region_height,0);
438  j<std::min(v+region_height,(int)evt.I.getHeight());
439  j++){
440  acc(Igray_[j][i]);
442  }
443  }
444  double checkpoints_median = boost::accumulators::median(acc);
446  writer.write(checkpoints_median);
447  if( cmd.using_adhoc_recovery() && (unsigned int)checkpoints_median>cmd.get_adhoc_recovery_treshold() )
448  return false;
449  }
450  }
451  }catch(vpException& e){
452  std::cout << "Tracking lost" << std::endl;
453  return false;
454  }
455  return true;
456  }
457 
459  this->cam_ = evt.cam_;
460 
461  std::vector<cv::Point> points;
462  I_ = _I = &(evt.I);
463  vpImageConvert::convert(evt.I,Igray_);
464 
465  boost::accumulators::accumulator_set<
466  double,
467  boost::accumulators::stats<
468  boost::accumulators::tag::mean
469  >
470  > acc;
471 
472  for(unsigned int i=0;i<points3D_outer_.size();i++){
473  points3D_outer_[i].project(cMo_);
474  points3D_inner_[i].project(cMo_);
475 
476  double u=0.,v=0.,u_inner=0.,v_inner=0;
477  vpMeterPixelConversion::convertPoint(cam_,points3D_outer_[i].get_x(),points3D_outer_[i].get_y(),u,v);
478  vpMeterPixelConversion::convertPoint(cam_,points3D_inner_[i].get_x(),points3D_inner_[i].get_y(),u_inner,v_inner);
479 
480  acc(std::abs(u-u_inner));
481  acc(std::abs(v-v_inner));
482 
483  // To avoid OpenCV exception that may occur when creating cv::boundingRect() from the points,
484  // we ensure that the coordinates of the points remain in the image.
485  u = std::max(u,0.);
486  u = std::min(u,(double)evt.I.getWidth()-1);
487  v = std::max(v,0.);
488  v = std::min(v,(double)evt.I.getHeight()-1);
489  points.push_back(cv::Point(u,v));
490  }
491 
493  int range = (const unsigned int)(boost::accumulators::mean(acc)*cmd.get_mbt_dynamic_range());
494 
495  vpMbEdgeTracker *tracker_me = dynamic_cast<vpMbEdgeTracker*>(tracker_);
496  if(tracker_me){
497  tracker_me->getMovingEdge(tracker_me_config_);
498  tracker_me_config_.setRange(range);
499  tracker_me->setMovingEdge(tracker_me_config_);
500  }else
501  std::cout << "error: could not init moving edges on tracker that doesn't support them." << std::endl;
502  }
503  cvTrackingBox_init_ = true;
504  cvTrackingBox_ = cv::boundingRect(cv::Mat(points));
505 
507  }
508 
510  return statistics;
511  }
512 
514  flush_display_ = val;
515  }
516 
518  return flush_display_;
519  }
520 
521  void
522  Tracker_::updateMovingEdgeSites(visp_tracker::MovingEdgeSitesPtr sites)
523  {
524  if (!sites)
525  return;
526 
527  std::list<vpMbtDistanceLine*> linesList;
528 
529  if(cmd.get_tracker_type() != CmdLine::KLT) // For mbt and hybrid
530  dynamic_cast<vpMbEdgeTracker*>(tracker_)->getLline(linesList, 0);
531 
532  std::list<vpMbtDistanceLine*>::iterator linesIterator = linesList.begin();
533  if (linesList.empty())
534  ROS_DEBUG_THROTTLE(10, "no distance lines");
535  bool noVisibleLine = true;
536  for (; linesIterator != linesList.end(); ++linesIterator)
537  {
538  vpMbtDistanceLine* line = *linesIterator;
539 
540 #if VISP_VERSION_INT >= VP_VERSION_INT(3,0,0) // ViSP >= 3.0.0
541  if (line && line->isVisible() && ! line->meline.empty())
542 #else
543  if (line && line->isVisible() && line->meline)
544 #endif
545  {
546 #if VISP_VERSION_INT >= VP_VERSION_INT(3,0,0) // ViSP >= 3.0.0
547  for(unsigned int a = 0 ; a < line->meline.size() ; a++)
548  {
549  if(line->meline[a] != NULL) {
550  std::list<vpMeSite>::const_iterator sitesIterator = line->meline[a]->getMeList().begin();
551  if (line->meline[a]->getMeList().empty())
552  ROS_DEBUG_THROTTLE(10, "no moving edge for a line");
553  for (; sitesIterator != line->meline[a]->getMeList().end(); ++sitesIterator)
554 #elif VISP_VERSION_INT >= VP_VERSION_INT(2,10,0) // ViSP >= 2.10.0
555  if (line->meline->getMeList().empty()) {
556  ROS_DEBUG_THROTTLE(10, "no moving edge for a line");
557  }
558  std::list<vpMeSite>::const_iterator sitesIterator = line->meline->getMeList().begin();
559 
560  for (; sitesIterator != line->meline->getMeList().end(); ++sitesIterator)
561 #else
562  if (line->meline->list.empty()) {
563  ROS_DEBUG_THROTTLE(10, "no moving edge for a line");
564  }
565  std::list<vpMeSite>::const_iterator sitesIterator = line->meline->list.begin();
566 
567  for (; sitesIterator != line->meline->list.end(); ++sitesIterator)
568 #endif
569  {
570  visp_tracker::MovingEdgeSite movingEdgeSite;
571  movingEdgeSite.x = sitesIterator->ifloat;
572  movingEdgeSite.y = sitesIterator->jfloat;
573 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)// ViSP < 2.10.0
574  movingEdgeSite.suppress = sitesIterator->suppress;
575 #endif
576  sites->moving_edge_sites.push_back (movingEdgeSite);
577  }
578  noVisibleLine = false;
579  }
580 #if VISP_VERSION_INT >= VP_VERSION_INT(3,0,0) // ViSP >= 3.0.0
581  }
582  }
583 #endif
584  }
585  if (noVisibleLine)
586  ROS_DEBUG_THROTTLE(10, "no distance lines");
587  }
588 
589  void
590  Tracker_::updateKltPoints(visp_tracker::KltPointsPtr klt)
591  {
592  if (!klt)
593  return;
594 
595 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)// ViSP < 2.10.0
596  vpMbHiddenFaces<vpMbtKltPolygon> *poly_lst;
597  std::map<int, vpImagePoint> *map_klt;
598 
599  if(cmd.get_tracker_type() != CmdLine::MBT) // For klt and hybrid
600  poly_lst = &dynamic_cast<vpMbKltTracker*>(tracker_)->getFaces();
601 
602  for(unsigned int i = 0 ; i < poly_lst->size() ; i++)
603  {
604  if((*poly_lst)[i])
605  {
606  map_klt = &((*poly_lst)[i]->getCurrentPoints());
607 
608  if(map_klt->size() > 3)
609  {
610  for (std::map<int, vpImagePoint>::iterator it=map_klt->begin(); it!=map_klt->end(); ++it)
611  {
612  visp_tracker::KltPoint kltPoint;
613  kltPoint.id = it->first;
614  kltPoint.i = it->second.get_i();
615  kltPoint.j = it->second.get_j();
616  klt->klt_points_positions.push_back (kltPoint);
617  }
618  }
619  }
620  }
621 #else // ViSP >= 2.10.0
622  std::list<vpMbtDistanceKltPoints*> *poly_lst;
623  std::map<int, vpImagePoint> *map_klt;
624 
625  if(cmd.get_tracker_type() != CmdLine::MBT) { // For klt and hybrid
626  poly_lst = &dynamic_cast<vpMbKltTracker*>(tracker_)->getFeaturesKlt();
627 
628  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=poly_lst->begin(); it!=poly_lst->end(); ++it){
629  map_klt = &((*it)->getCurrentPoints());
630 
631  if((*it)->polygon->isVisible()){
632  if(map_klt->size() > 3)
633  {
634  for (std::map<int, vpImagePoint>::iterator it=map_klt->begin(); it!=map_klt->end(); ++it)
635  {
636  visp_tracker::KltPoint kltPoint;
637  kltPoint.id = it->first;
638  kltPoint.i = it->second.get_i();
639  kltPoint.j = it->second.get_j();
640  klt->klt_points_positions.push_back (kltPoint);
641  }
642  }
643  }
644  }
645  }
646 #endif
647  }
648 }
649 
std::vector< vpPoint > & get_flashcode_points_3D()
Definition: cmd_line.cpp:295
std::string get_code_message() const
Definition: cmd_line.cpp:340
vpMbTracker * tracker_
Definition: tracking.h:73
bool log_pose() const
Definition: cmd_line.cpp:355
bool using_var_file() const
Definition: cmd_line.cpp:214
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
Definition: tracking.h:57
vpImage< vpRGBa > * _I
Definition: tracking.h:76
vpCameraParameters cam_
Definition: tracking.h:79
vpHomogeneousMatrix cMo_
Definition: tracking.h:77
bool input_selected(input_ready const &evt)
Definition: tracking.cpp:144
int get_dmx_timeout() const
Definition: cmd_line.cpp:242
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
bool get_flush_display()
Definition: tracking.cpp:517
std::vector< vpPoint > & get_points3D_middle()
Definition: tracking.cpp:114
double get_var_limit() const
Definition: cmd_line.cpp:202
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_x
Definition: tracking.h:57
bool get_verbose() const
Definition: cmd_line.cpp:238
bool model_detected(msm::front::none const &)
Definition: tracking.cpp:294
unsigned int get_adhoc_recovery_treshold() const
Definition: cmd_line.cpp:332
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_y
Definition: tracking.h:57
std::vector< vpPoint > & get_inner_points_3D()
Definition: cmd_line.cpp:299
std::vector< vpPoint > & get_flashcode()
Definition: tracking.cpp:118
std::string get_xml_file() const
Definition: cmd_line.cpp:279
CmdLine & get_cmd()
Definition: tracking.cpp:130
TFSIMD_FORCE_INLINE const tfScalar & y() const
vpImage< vpRGBa > & get_I()
Definition: tracking.cpp:122
vpImage< vpRGBa > * I_
Definition: tracking.h:75
bool using_adhoc_recovery() const
Definition: cmd_line.cpp:347
Tracker_(CmdLine &cmd, vpDetectorBase *detector, vpMbTracker *tracker_, bool flush_display=true)
Definition: tracking.cpp:24
double get_adhoc_recovery_ratio() const
Definition: cmd_line.cpp:328
void find_flashcode_pos(input_ready const &evt)
Definition: tracking.cpp:251
vpRect vpTrackingBox_
Definition: tracking.h:87
vpMbTracker & get_mbt()
Definition: tracking.cpp:101
vpImage< vpRGBa > & I
Definition: events.h:11
std::vector< vpPoint > points3D_inner_
Definition: tracking.h:83
bool using_hinkley() const
Definition: cmd_line.cpp:174
std::vector< vpPoint > & get_points3D_outer()
Definition: tracking.cpp:109
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_wz
Definition: tracking.h:57
vpDetectorBase & get_detector()
Definition: tracking.cpp:96
void track_model(input_ready const &evt)
Definition: tracking.cpp:458
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_wy
Definition: tracking.h:57
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_wx
Definition: tracking.h:57
std::vector< vpPoint > & get_points3D_inner()
Definition: tracking.cpp:105
bool using_mbt_dynamic_range()
Definition: cmd_line.cpp:198
statistics_t & get_statistics()
Definition: tracking.cpp:509
bool flashcode_redetected(input_ready const &evt)
Definition: tracking.cpp:199
bool mbt_success(input_ready const &evt)
Definition: tracking.cpp:363
bool log_checkpoints() const
Definition: cmd_line.cpp:351
TFSIMD_FORCE_INLINE const tfScalar & x() const
#define ROS_WARN_STREAM(args)
std::vector< vpPoint > f_
Definition: tracking.h:86
vpMatrix covariance_
Definition: tracking.h:78
std::ofstream varfile_
Definition: tracking.h:64
vpCameraParameters & get_cam()
Definition: tracking.cpp:126
hinkley_array_t hink_
Definition: tracking.h:71
void set_code_message_index(const size_t &index)
Definition: cmd_line.cpp:374
int get_mbt_convergence_steps() const
Definition: cmd_line.cpp:190
std::vector< vpPoint > points3D_middle_
Definition: tracking.h:85
#define ROS_INFO_STREAM(args)
statistics_t statistics
Definition: tracking.h:91
vpDetectorBase * detector_
Definition: tracking.h:68
bool no_input_selected(input_ready const &evt)
Definition: tracking.cpp:149
bool using_var_limit() const
Definition: cmd_line.cpp:206
bool flashcode_detected(input_ready const &evt)
Definition: tracking.cpp:153
double get_hinkley_alpha() const
Definition: cmd_line.cpp:178
vpImagePoint flashcode_center_
Definition: tracking.h:63
vpCameraParameters cam_
Definition: events.h:12
double get_mbt_dynamic_range() const
Definition: cmd_line.cpp:194
vpImage< unsigned char > Igray_
Definition: tracking.h:80
void updateKltPoints(visp_tracker::KltPointsPtr klt)
Definition: tracking.cpp:590
TRACKER_TYPE get_tracker_type() const
Definition: cmd_line.cpp:314
double get_hinkley_delta() const
Definition: cmd_line.cpp:184
cv::Rect cvTrackingBox_
Definition: tracking.h:88
double get_adhoc_recovery_size() const
Definition: cmd_line.cpp:324
void set_flush_display(bool val)
Definition: tracking.cpp:513
std::string get_var_file() const
Definition: cmd_line.cpp:210
std::vector< vpPoint > & get_outer_points_3D()
Definition: cmd_line.cpp:303
#define ROS_DEBUG_THROTTLE(period,...)
std::vector< vpPoint > points3D_outer_
Definition: tracking.h:84
void updateMovingEdgeSites(visp_tracker::MovingEdgeSitesPtr sites)
Definition: tracking.cpp:522
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 > > checkpoints
Definition: tracking.h:57
Definition: events.h:6
bool cvTrackingBox_init_
Definition: tracking.h:89
std::string get_mbt_cad_file() const
Definition: cmd_line.cpp:270


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