Visual Servoing Platform  version 3.3.1 under development (2020-04-08)
vpMbDepthDenseTracker.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Model-based tracker using depth dense features.
33  *
34  *****************************************************************************/
35 
36 #include <iostream>
37 
38 #include <visp3/core/vpConfig.h>
39 
40 #ifdef VISP_HAVE_PCL
41 #include <pcl/point_cloud.h>
42 #endif
43 
44 #include <visp3/core/vpDisplay.h>
45 #include <visp3/core/vpExponentialMap.h>
46 #include <visp3/core/vpTrackingException.h>
47 #include <visp3/mbt/vpMbDepthDenseTracker.h>
48 #include <visp3/mbt/vpMbtXmlGenericParser.h>
49 
50 #if DEBUG_DISPLAY_DEPTH_DENSE
51 #include <visp3/gui/vpDisplayGDI.h>
52 #include <visp3/gui/vpDisplayX.h>
53 #endif
54 
56  : m_depthDenseHiddenFacesDisplay(), m_depthDenseListOfActiveFaces(),
57  m_denseDepthNbFeatures(0), m_depthDenseFaces(), m_depthDenseSamplingStepX(2), m_depthDenseSamplingStepY(2),
58  m_error_depthDense(), m_L_depthDense(), m_robust_depthDense(), m_w_depthDense(), m_weightedError_depthDense()
59 #if DEBUG_DISPLAY_DEPTH_DENSE
60  ,
61  m_debugDisp_depthDense(NULL), m_debugImage_depthDense()
62 #endif
63 {
64 #ifdef VISP_HAVE_OGRE
65  faces.getOgreContext()->setWindowName("MBT Depth Dense");
66 #endif
67 
68 #if defined(VISP_HAVE_X11) && DEBUG_DISPLAY_DEPTH_DENSE
69  m_debugDisp_depthDense = new vpDisplayX;
70 #elif defined(VISP_HAVE_GDI) && DEBUG_DISPLAY_DEPTH_DENSE
71  m_debugDisp_depthDense = new vpDisplayGDI;
72 #endif
73 }
74 
76 {
77  for (size_t i = 0; i < m_depthDenseFaces.size(); i++) {
78  delete m_depthDenseFaces[i];
79  }
80 
81 #if DEBUG_DISPLAY_DEPTH_DENSE
82  delete m_debugDisp_depthDense;
83 #endif
84 }
85 
86 void vpMbDepthDenseTracker::addFace(vpMbtPolygon &polygon, bool alreadyClose)
87 {
88  if (polygon.nbpt < 3) {
89  return;
90  }
91 
92  // Copy hidden faces
94 
95  vpMbtFaceDepthDense *normal_face = new vpMbtFaceDepthDense;
96  normal_face->m_hiddenFace = &faces;
97  normal_face->m_polygon = &polygon;
98  normal_face->m_cam = m_cam;
99  normal_face->m_useScanLine = useScanLine;
100  normal_face->m_clippingFlag = clippingFlag;
101  normal_face->m_distNearClip = distNearClip;
102  normal_face->m_distFarClip = distFarClip;
103 
104  // Add lines that compose the face
105  unsigned int nbpt = polygon.getNbPoint();
106  if (nbpt > 0) {
107  for (unsigned int i = 0; i < nbpt - 1; i++) {
108  normal_face->addLine(polygon.p[i], polygon.p[i + 1], &m_depthDenseHiddenFacesDisplay, polygon.getIndex(),
109  polygon.getName());
110  }
111 
112  if (!alreadyClose) {
113  // Add last line that closes the face
114  normal_face->addLine(polygon.p[nbpt - 1], polygon.p[0], &m_depthDenseHiddenFacesDisplay, polygon.getIndex(),
115  polygon.getName());
116  }
117  }
118 
119  // Construct a vpPlane in object frame
120  vpPoint pts[3];
121  pts[0] = polygon.p[0];
122  pts[1] = polygon.p[1];
123  pts[2] = polygon.p[2];
124  normal_face->m_planeObject = vpPlane(pts[0], pts[1], pts[2], vpPlane::object_frame);
125 
126  m_depthDenseFaces.push_back(normal_face);
127 }
128 
129 void vpMbDepthDenseTracker::computeVisibility(unsigned int width, unsigned int height)
130 {
131  bool changed = false;
132  faces.setVisible(width, height, m_cam, m_cMo, angleAppears, angleDisappears, changed);
133 
134  if (useScanLine) {
135  // if (clippingFlag <= 2) {
136  // cam.computeFov(width, height);
137  // }
138 
140  faces.computeScanLineRender(m_cam, width, height);
141  }
142 
143  for (std::vector<vpMbtFaceDepthDense *>::const_iterator it = m_depthDenseFaces.begin();
144  it != m_depthDenseFaces.end(); ++it) {
145  vpMbtFaceDepthDense *face_normal = *it;
146  face_normal->computeVisibility();
147  }
148 }
149 
151 {
152  double normRes = 0;
153  double normRes_1 = -1;
154  unsigned int iter = 0;
155 
156  computeVVSInit();
157 
159  vpMatrix LTL;
160  vpColVector LTR, v;
161 
162  double mu = m_initialMu;
163  vpHomogeneousMatrix cMo_prev;
164 
165  bool isoJoIdentity_ = true;
167  vpMatrix L_true, LVJ_true;
168 
169  while (std::fabs(normRes_1 - normRes) > m_stopCriteriaEpsilon && (iter < m_maxIter)) {
171 
172  bool reStartFromLastIncrement = false;
173  computeVVSCheckLevenbergMarquardt(iter, m_error_depthDense, error_prev, cMo_prev, mu, reStartFromLastIncrement);
174 
175  if (!reStartFromLastIncrement) {
177 
178  if (computeCovariance) {
179  L_true = m_L_depthDense;
180  if (!isoJoIdentity_) {
181  cVo.buildFrom(m_cMo);
182  LVJ_true = (m_L_depthDense * cVo * oJo);
183  }
184  }
185 
186  // Compute DoF only once
187  if (iter == 0) {
188  isoJoIdentity_ = true;
189  oJo.eye();
190 
191  // If all the 6 dof should be estimated, we check if the interaction
192  // matrix is full rank. If not we remove automatically the dof that
193  // cannot be estimated This is particularly useful when consering
194  // circles (rank 5) and cylinders (rank 4)
195  if (isoJoIdentity_) {
196  cVo.buildFrom(m_cMo);
197 
198  vpMatrix K; // kernel
199  unsigned int rank = (m_L_depthDense * cVo).kernel(K);
200  if (rank == 0) {
201  throw vpException(vpException::fatalError, "Rank=0, cannot estimate the pose !");
202  }
203 
204  if (rank != 6) {
205  vpMatrix I; // Identity
206  I.eye(6);
207  oJo = I - K.AtA();
208 
209  isoJoIdentity_ = false;
210  }
211  }
212  }
213 
214  double num = 0.0, den = 0.0;
215  for (unsigned int i = 0; i < m_L_depthDense.getRows(); i++) {
216  // Compute weighted errors and stop criteria
218  num += m_w_depthDense[i] * vpMath::sqr(m_error_depthDense[i]);
219  den += m_w_depthDense[i];
220 
221  // weight interaction matrix
222  for (unsigned int j = 0; j < 6; j++) {
223  m_L_depthDense[i][j] *= m_w_depthDense[i];
224  }
225  }
226 
228  m_error_depthDense, error_prev, LTR, mu, v);
229 
230  cMo_prev = m_cMo;
232 
233  normRes_1 = normRes;
234  normRes = sqrt(num / den);
235  }
236 
237  iter++;
238  }
239 
240  computeCovarianceMatrixVVS(isoJoIdentity_, m_w_depthDense, cMo_prev, L_true, LVJ_true, m_error_depthDense);
241 }
242 
244 {
246 
247  for (std::vector<vpMbtFaceDepthDense *>::const_iterator it = m_depthDenseListOfActiveFaces.begin();
248  it != m_depthDenseListOfActiveFaces.end(); ++it) {
249  vpMbtFaceDepthDense *face = *it;
251  }
252 
253  m_L_depthDense.resize(m_denseDepthNbFeatures, 6, false, false);
256 
258  m_w_depthDense = 1;
259 }
260 
262 {
263  unsigned int start_index = 0;
264  for (std::vector<vpMbtFaceDepthDense *>::const_iterator it = m_depthDenseListOfActiveFaces.begin();
265  it != m_depthDenseListOfActiveFaces.end(); ++it) {
266  vpMbtFaceDepthDense *face = *it;
267 
268  vpMatrix L_face;
269  vpColVector error;
270 
271  face->computeInteractionMatrixAndResidu(m_cMo, L_face, error);
272 
273  m_error_depthDense.insert(start_index, error);
274  m_L_depthDense.insert(L_face, start_index, 0);
275 
276  start_index += error.getRows();
277  }
278 }
279 
281 {
283 }
284 
286  const vpCameraParameters &cam, const vpColor &col, unsigned int thickness,
287  bool displayFullModel)
288 {
289  std::vector<std::vector<double> > models = vpMbDepthDenseTracker::getModelForDisplay(I.getWidth(), I.getHeight(), cMo, cam, displayFullModel);
290 
291  for (size_t i = 0; i < models.size(); i++) {
292  if (vpMath::equal(models[i][0], 0)) {
293  vpImagePoint ip1(models[i][1], models[i][2]);
294  vpImagePoint ip2(models[i][3], models[i][4]);
295  vpDisplay::displayLine(I, ip1, ip2, col, thickness);
296  }
297  }
298 }
299 
301  const vpCameraParameters &cam, const vpColor &col, unsigned int thickness,
302  bool displayFullModel)
303 {
304  std::vector<std::vector<double> > models = vpMbDepthDenseTracker::getModelForDisplay(I.getWidth(), I.getHeight(), cMo, cam, displayFullModel);
305 
306  for (size_t i = 0; i < models.size(); i++) {
307  if (vpMath::equal(models[i][0], 0)) {
308  vpImagePoint ip1(models[i][1], models[i][2]);
309  vpImagePoint ip2(models[i][3], models[i][4]);
310  vpDisplay::displayLine(I, ip1, ip2, col, thickness);
311  }
312  }
313 }
314 
328 std::vector<std::vector<double> > vpMbDepthDenseTracker::getModelForDisplay(unsigned int width, unsigned int height,
329  const vpHomogeneousMatrix &cMo,
330  const vpCameraParameters &cam,
331  bool displayFullModel)
332 {
333  std::vector<std::vector<double> > models;
334 
335  vpCameraParameters c = cam;
336 
337  bool changed = false;
338  m_depthDenseHiddenFacesDisplay.setVisible(width, height, c, cMo, angleAppears, angleDisappears, changed);
339 
340  if (useScanLine) {
341  c.computeFov(width, height);
342 
345  }
346 
347  for (std::vector<vpMbtFaceDepthDense *>::const_iterator it = m_depthDenseFaces.begin();
348  it != m_depthDenseFaces.end(); ++it) {
349  vpMbtFaceDepthDense *face_dense = *it;
350  std::vector<std::vector<double> > modelLines = face_dense->getModelForDisplay(width, height, cMo, cam, displayFullModel);
351  models.insert(models.end(), modelLines.begin(), modelLines.end());
352  }
353 
354  return models;
355 }
356 
358 {
359  if (!modelInitialised) {
360  throw vpException(vpException::fatalError, "model not initialized");
361  }
362 
363  bool reInitialisation = false;
364  if (!useOgre) {
365  faces.setVisible(I.getWidth(), I.getHeight(), m_cam, m_cMo, angleAppears, angleDisappears, reInitialisation);
366  } else {
367 #ifdef VISP_HAVE_OGRE
368  if (!faces.isOgreInitialised()) {
372  // Turn off Ogre config dialog display for the next call to this
373  // function since settings are saved in the ogre.cfg file and used
374  // during the next call
375  ogreShowConfigDialog = false;
376  }
377 
379 #else
380  faces.setVisible(I.getWidth(), I.getHeight(), m_cam, m_cMo, angleAppears, angleDisappears, reInitialisation);
381 #endif
382  }
383 
384  if (useScanLine || clippingFlag > 3)
386 
388 }
389 
390 void vpMbDepthDenseTracker::loadConfigFile(const std::string &configFile)
391 {
392 #ifdef VISP_HAVE_PUGIXML
394 
398 
401 
402  try {
403  std::cout << " *********** Parsing XML for Mb Depth Dense Tracker ************ " << std::endl;
404  xmlp.parse(configFile);
405  } catch (const vpException &e) {
406  std::cerr << "Exception: " << e.what() << std::endl;
407  throw vpException(vpException::ioError, "Cannot open XML file \"%s\"", configFile.c_str());
408  }
409 
410  vpCameraParameters camera;
411  xmlp.getCameraParameters(camera);
412  setCameraParameters(camera);
413 
416 
417  if (xmlp.hasNearClippingDistance())
419 
420  if (xmlp.hasFarClippingDistance())
422 
423  if (xmlp.getFovClipping())
425 
427 #else
428  std::cerr << "pugixml third-party is not properly built to read config file: " << configFile << std::endl;
429 #endif
430 }
431 
432 void vpMbDepthDenseTracker::reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name,
433  const vpHomogeneousMatrix &cMo, bool verbose)
434 {
435  m_cMo.eye();
436 
437  for (size_t i = 0; i < m_depthDenseFaces.size(); i++) {
438  delete m_depthDenseFaces[i];
439  m_depthDenseFaces[i] = NULL;
440  }
441 
442  m_depthDenseFaces.clear();
443 
444  loadModel(cad_name, verbose);
445  initFromPose(I, cMo);
446 }
447 
448 #if defined(VISP_HAVE_PCL)
449 void vpMbDepthDenseTracker::reInitModel(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud,
450  const std::string &cad_name, const vpHomogeneousMatrix &cMo,
451  bool verbose)
452 {
453  vpImage<unsigned char> I_dummy(point_cloud->height, point_cloud->width);
454  reInitModel(I_dummy, cad_name, cMo, verbose);
455 }
456 
457 #endif
458 
460 {
461  m_cMo.eye();
462 
463  for (std::vector<vpMbtFaceDepthDense *>::iterator it = m_depthDenseFaces.begin();
464  it != m_depthDenseFaces.end(); ++it) {
465  vpMbtFaceDepthDense *normal_face = *it;
466  delete normal_face;
467  normal_face = NULL;
468  }
469 
470  m_depthDenseFaces.clear();
471 
472  m_computeInteraction = true;
473  computeCovariance = false;
474 
477 
479 
480  m_lambda = 1.0;
481  m_maxIter = 30;
482 
483  faces.reset();
484 
486 
487  useScanLine = false;
488 
489 #ifdef VISP_HAVE_OGRE
490  useOgre = false;
491 #endif
492 
494 }
495 
497 {
498  m_cam = cam;
499 
500  for (std::vector<vpMbtFaceDepthDense *>::const_iterator it = m_depthDenseFaces.begin();
501  it != m_depthDenseFaces.end(); ++it) {
502  (*it)->setCameraParameters(cam);
503  }
504 }
505 
507 {
508  for (std::vector<vpMbtFaceDepthDense *>::const_iterator it = m_depthDenseFaces.begin();
509  it != m_depthDenseFaces.end(); ++it) {
510  (*it)->setDepthDenseFilteringMaxDistance(maxDistance);
511  }
512 }
513 
515 {
516  for (std::vector<vpMbtFaceDepthDense *>::const_iterator it = m_depthDenseFaces.begin();
517  it != m_depthDenseFaces.end(); ++it) {
518  (*it)->setDepthDenseFilteringMethod(method);
519  }
520 }
521 
523 {
524  for (std::vector<vpMbtFaceDepthDense *>::const_iterator it = m_depthDenseFaces.begin();
525  it != m_depthDenseFaces.end(); ++it) {
526  (*it)->setDepthDenseFilteringMinDistance(minDistance);
527  }
528 }
529 
531 {
532  if (occupancyRatio < 0.0 || occupancyRatio > 1.0) {
533  std::cerr << "occupancyRatio < 0.0 || occupancyRatio > 1.0" << std::endl;
534  return;
535  }
536 
537  for (std::vector<vpMbtFaceDepthDense *>::const_iterator it = m_depthDenseFaces.begin();
538  it != m_depthDenseFaces.end(); ++it) {
539  (*it)->setDepthDenseFilteringOccupancyRatio(occupancyRatio);
540  }
541 }
542 
543 #ifdef VISP_HAVE_PCL
544 void vpMbDepthDenseTracker::segmentPointCloud(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud)
545 {
547 
548 #if DEBUG_DISPLAY_DEPTH_DENSE
549  if (!m_debugDisp_depthDense->isInitialised()) {
550  m_debugImage_depthDense.resize(point_cloud->height, point_cloud->width);
551  m_debugDisp_depthDense->init(m_debugImage_depthDense, 50, 0, "Debug display dense depth tracker");
552  }
553 
554  m_debugImage_depthDense = 0;
555  std::vector<std::vector<vpImagePoint> > roiPts_vec;
556 #endif
557 
558  for (std::vector<vpMbtFaceDepthDense *>::iterator it = m_depthDenseFaces.begin();
559  it != m_depthDenseFaces.end(); ++it) {
560  vpMbtFaceDepthDense *face = *it;
561 
562  if (face->isVisible() && face->isTracked()) {
563 #if DEBUG_DISPLAY_DEPTH_DENSE
564  std::vector<std::vector<vpImagePoint> > roiPts_vec_;
565 #endif
567 #if DEBUG_DISPLAY_DEPTH_DENSE
568  ,
569  m_debugImage_depthDense, roiPts_vec_
570 #endif
571  , m_mask
572  )) {
573  m_depthDenseListOfActiveFaces.push_back(*it);
574 
575 #if DEBUG_DISPLAY_DEPTH_DENSE
576  roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
577 #endif
578  }
579  }
580  }
581 
582 #if DEBUG_DISPLAY_DEPTH_DENSE
583  vpDisplay::display(m_debugImage_depthDense);
584 
585  for (size_t i = 0; i < roiPts_vec.size(); i++) {
586  if (roiPts_vec[i].empty())
587  continue;
588 
589  for (size_t j = 0; j < roiPts_vec[i].size() - 1; j++) {
590  vpDisplay::displayLine(m_debugImage_depthDense, roiPts_vec[i][j], roiPts_vec[i][j + 1], vpColor::red, 2);
591  }
592  vpDisplay::displayLine(m_debugImage_depthDense, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
593  vpColor::red, 2);
594  }
595 
596  vpDisplay::flush(m_debugImage_depthDense);
597 #endif
598 }
599 #endif
600 
601 void vpMbDepthDenseTracker::segmentPointCloud(const std::vector<vpColVector> &point_cloud, unsigned int width,
602  unsigned int height)
603 {
605 
606 #if DEBUG_DISPLAY_DEPTH_DENSE
607  if (!m_debugDisp_depthDense->isInitialised()) {
608  m_debugImage_depthDense.resize(height, width);
609  m_debugDisp_depthDense->init(m_debugImage_depthDense, 50, 0, "Debug display dense depth tracker");
610  }
611 
612  m_debugImage_depthDense = 0;
613  std::vector<std::vector<vpImagePoint> > roiPts_vec;
614 #endif
615 
616  for (std::vector<vpMbtFaceDepthDense *>::iterator it = m_depthDenseFaces.begin();
617  it != m_depthDenseFaces.end(); ++it) {
618  vpMbtFaceDepthDense *face = *it;
619 
620  if (face->isVisible() && face->isTracked()) {
621 #if DEBUG_DISPLAY_DEPTH_DENSE
622  std::vector<std::vector<vpImagePoint> > roiPts_vec_;
623 #endif
624  if (face->computeDesiredFeatures(m_cMo, width, height, point_cloud, m_depthDenseSamplingStepX,
626 #if DEBUG_DISPLAY_DEPTH_DENSE
627  ,
628  m_debugImage_depthDense, roiPts_vec_
629 #endif
630  , m_mask
631  )) {
632  m_depthDenseListOfActiveFaces.push_back(*it);
633 
634 #if DEBUG_DISPLAY_DEPTH_DENSE
635  roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
636 #endif
637  }
638  }
639  }
640 
641 #if DEBUG_DISPLAY_DEPTH_DENSE
642  vpDisplay::display(m_debugImage_depthDense);
643 
644  for (size_t i = 0; i < roiPts_vec.size(); i++) {
645  if (roiPts_vec[i].empty())
646  continue;
647 
648  for (size_t j = 0; j < roiPts_vec[i].size() - 1; j++) {
649  vpDisplay::displayLine(m_debugImage_depthDense, roiPts_vec[i][j], roiPts_vec[i][j + 1], vpColor::red, 2);
650  }
651  vpDisplay::displayLine(m_debugImage_depthDense, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
652  vpColor::red, 2);
653  }
654 
655  vpDisplay::flush(m_debugImage_depthDense);
656 #endif
657 }
658 
660 {
662 #ifdef VISP_HAVE_OGRE
663  faces.getOgreContext()->setWindowName("MBT Depth Dense");
664 #endif
665 }
666 
668 {
669  m_cMo = cdMo;
670  init(I);
671 }
672 
674 {
675  m_cMo = cdMo;
676  vpImageConvert::convert(I_color, m_I);
677  init(m_I);
678 }
679 
680 #if defined(VISP_HAVE_PCL)
681 void vpMbDepthDenseTracker::setPose(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud,
682  const vpHomogeneousMatrix &cdMo)
683 {
684  m_I.resize(point_cloud->height, point_cloud->width);
685  m_cMo = cdMo;
686  init(m_I);
687 }
688 #endif
689 
691 {
693 
694  for (std::vector<vpMbtFaceDepthDense *>::const_iterator it = m_depthDenseFaces.begin();
695  it != m_depthDenseFaces.end(); ++it) {
696  (*it)->setScanLineVisibilityTest(v);
697  }
698 }
699 
700 void vpMbDepthDenseTracker::setUseDepthDenseTracking(const std::string &name, const bool &useDepthDenseTracking)
701 {
702  for (std::vector<vpMbtFaceDepthDense *>::const_iterator it = m_depthDenseFaces.begin();
703  it != m_depthDenseFaces.end(); ++it) {
704  vpMbtFaceDepthDense *face = *it;
705  if (face->m_polygon->getName() == name) {
706  face->setTracked(useDepthDenseTracking);
707  }
708  }
709 }
710 
712 
714 {
715  throw vpException(vpException::fatalError, "Cannot track with a grayscale image!");
716 }
717 
719 {
720  throw vpException(vpException::fatalError, "Cannot track with a color image!");
721 }
722 
723 #ifdef VISP_HAVE_PCL
724 void vpMbDepthDenseTracker::track(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud)
725 {
726  segmentPointCloud(point_cloud);
727 
728  computeVVS();
729 
730  computeVisibility(point_cloud->width, point_cloud->height);
731 }
732 #endif
733 
734 void vpMbDepthDenseTracker::track(const std::vector<vpColVector> &point_cloud, unsigned int width,
735  unsigned int height)
736 {
737  segmentPointCloud(point_cloud, width, height);
738 
739  computeVVS();
740 
741  computeVisibility(width, height);
742 }
743 
744 void vpMbDepthDenseTracker::initCircle(const vpPoint & /*p1*/, const vpPoint & /*p2*/, const vpPoint & /*p3*/,
745  double /*radius*/, int /*idFace*/, const std::string & /*name*/)
746 {
747  throw vpException(vpException::fatalError, "vpMbDepthDenseTracker::initCircle() should not be called!");
748 }
749 
750 void vpMbDepthDenseTracker::initCylinder(const vpPoint & /*p1*/, const vpPoint & /*p2*/, double /*radius*/,
751  int /*idFace*/, const std::string & /*name*/)
752 {
753  throw vpException(vpException::fatalError, "vpMbDepthDenseTracker::initCylinder() should not be called!");
754 }
755 
757 
bool m_computeInteraction
Definition: vpMbTracker.h:185
void setWindowName(const Ogre::String &n)
Definition: vpAROgre.h:269
vpMbtTukeyEstimator< double > m_robust_depthDense
Tukey M-Estimator.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:164
double m_distNearClip
Distance for near clipping.
std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
virtual void setScanLineVisibilityTest(const bool &v)
vpMbHiddenFaces< vpMbtPolygon > m_depthDenseHiddenFacesDisplay
Set of faces describing the object used only for display with scan line.
vpCameraParameters m_cam
The camera parameters.
Definition: vpMbTracker.h:111
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:305
virtual void computeVVSCheckLevenbergMarquardt(unsigned int iter, vpColVector &error, const vpColVector &m_error_prev, const vpHomogeneousMatrix &cMoPrev, double &mu, bool &reStartFromLastIncrement, vpColVector *const w=NULL, const vpColVector *const m_w_prev=NULL)
int getIndex() const
Definition: vpMbtPolygon.h:101
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
vpCameraParameters m_cam
Camera intrinsic parameters.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void parse(const std::string &filename)
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
Definition: vpMbTracker.h:143
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition: vpImage.h:881
void getCameraParameters(vpCameraParameters &cam) const
vpColVector m_weightedError_depthDense
Weighted error.
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual void loadConfigFile(const std::string &configFile)
std::string getName() const
Definition: vpMbtPolygon.h:108
void segmentPointCloud(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud)
virtual void track(const vpImage< unsigned char > &)
vpMatrix AtA() const
Definition: vpMatrix.cpp:693
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:157
static bool equal(double x, double y, double s=0.001)
Definition: vpMath.h:296
bool m_useScanLine
Scan line visibility.
void setBackgroundSizeOgre(const unsigned int &h, const unsigned int &w)
vpColVector m_error_depthDense
(s - s*)
virtual void setDepthDenseFilteringMaxDistance(double maxDistance)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:150
bool modelInitialised
Definition: vpMbTracker.h:123
void setTracked(bool tracked)
error that can be emited by ViSP classes.
Definition: vpException.h:71
vpPoint * p
corners in the object frame
Definition: vpPolygon3D.h:81
unsigned int getRows() const
Definition: vpArray2D.h:289
vpHomogeneousMatrix inverse() const
bool useOgre
Use Ogre3d for visibility tests.
Definition: vpMbTracker.h:155
virtual void setDepthDenseFilteringOccupancyRatio(double occupancyRatio)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
bool computeCovariance
Flag used to specify if the covariance matrix has to be computed or not.
Definition: vpMbTracker.h:128
void addLine(vpPoint &p1, vpPoint &p2, vpMbHiddenFaces< vpMbtPolygon > *const faces, int polygon=-1, std::string name="")
void addFace(vpMbtPolygon &polygon, bool alreadyClose)
static void flush(const vpImage< unsigned char > &I)
unsigned int getDepthDenseSamplingStepY() const
unsigned int setVisibleOgre(unsigned int width, unsigned int height, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
static const vpColor red
Definition: vpColor.h:217
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:81
void computeClippedPolygons(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam)
vpMbtPolygon * m_polygon
Polygon defining the face.
vpPlane m_planeObject
Plane equation described in the object frame.
Parse an Xml file to extract configuration parameters of a mbtConfig object.Data parser for the model...
void initOgre(const vpCameraParameters &cam=vpCameraParameters())
double distFarClip
Distance for near clipping.
Definition: vpMbTracker.h:151
vpAROgre * getOgreContext()
unsigned int m_denseDepthNbFeatures
Nb features.
vpMatrix oJo
The Degrees of Freedom to estimate.
Definition: vpMbTracker.h:115
virtual void setDepthDenseFilteringMethod(int method)
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:66
void setAngleDisappear(const double &adisappear)
unsigned int m_clippingFlag
Flags specifying which clipping to used.
vpMatrix m_L_depthDense
Interaction matrix.
bool useScanLine
Use Scanline for visibility tests.
Definition: vpMbTracker.h:158
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double sqr(double x)
Definition: vpMath.h:114
void computeInteractionMatrixAndResidu(const vpHomogeneousMatrix &cMo, vpMatrix &L, vpColVector &error)
static void display(const vpImage< unsigned char > &I)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
double m_distFarClip
Distance for near clipping.
Generic class defining intrinsic camera parameters.
void setOgreShowConfigDialog(bool showConfigDialog)
unsigned int getNbPoint() const
Definition: vpPolygon3D.h:132
double m_initialMu
Initial Mu for Levenberg Marquardt optimization loop.
Definition: vpMbTracker.h:193
void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose=false)
double m_lambda
Gain of the virtual visual servoing stage.
Definition: vpMbTracker.h:187
unsigned int m_depthDenseSamplingStepX
Sampling step in x-direction.
void setDepthDenseSamplingStepY(unsigned int stepY)
vpMbtOptimizationMethod m_optimizationMethod
Optimization method used.
Definition: vpMbTracker.h:140
void computeVisibility(unsigned int width, unsigned int height)
double angleAppears
Angle used to detect a face appearance.
Definition: vpMbTracker.h:145
unsigned int getNbFeatures() const
unsigned int m_maxIter
Maximum number of iterations of the virtual visual servoing stage.
Definition: vpMbTracker.h:189
void setAngleAppear(const double &aappear)
const char * what() const
static double rad(double deg)
Definition: vpMath.h:108
void setDepthDenseSamplingStep(unsigned int stepX, unsigned int stepY)
void setDepthDenseSamplingStepX(unsigned int stepX)
virtual void setOgreVisibilityTest(const bool &v)
void insert(unsigned int i, const vpColVector &v)
void setUseDepthDenseTracking(const std::string &name, const bool &useDepthDenseTracking)
const vpImage< bool > * m_mask
Mask used to disable tracking on a part of image.
Definition: vpMbTracker.h:221
void resize(unsigned int i, bool flagNullify=true)
Definition: vpColVector.h:310
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
virtual void computeVVSPoseEstimation(const bool isoJoIdentity_, unsigned int iter, vpMatrix &L, vpMatrix &LTL, vpColVector &R, const vpColVector &error, vpColVector &error_prev, vpColVector &LTR, double &mu, vpColVector &v, const vpColVector *const w=NULL, vpColVector *const m_w_prev=NULL)
unsigned int nbpt
Number of points used to define the polygon.
Definition: vpPolygon3D.h:76
double m_stopCriteriaEpsilon
Epsilon threshold to stop the VVS optimization loop.
Definition: vpMbTracker.h:191
static double deg(double rad)
Definition: vpMath.h:101
virtual void setOgreVisibilityTest(const bool &v)
unsigned int getHeight() const
Definition: vpImage.h:188
bool ogreShowConfigDialog
Definition: vpMbTracker.h:156
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace=0, const std::string &name="")
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
bool computeDesiredFeatures(const vpHomogeneousMatrix &cMo, const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud, unsigned int stepX, unsigned int stepY, const vpImage< bool > *mask=NULL)
vpColVector m_w_depthDense
Robust weights.
static vpHomogeneousMatrix direct(const vpColVector &v)
std::vector< vpMbtFaceDepthDense * > m_depthDenseFaces
List of faces.
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
virtual void computeCovarianceMatrixVVS(const bool isoJoIdentity_, const vpColVector &w_true, const vpHomogeneousMatrix &cMoPrev, const vpMatrix &L_true, const vpMatrix &LVJ_true, const vpColVector &error)
double angleDisappears
Angle used to detect a face disappearance.
Definition: vpMbTracker.h:147
unsigned int getDepthDenseSamplingStepX() const
virtual void computeVVSInteractionMatrixAndResidu()
virtual void setScanLineVisibilityTest(const bool &v)
Definition: vpMbTracker.h:597
virtual void setClipping(const unsigned int &flags)
virtual void init(const vpImage< unsigned char > &I)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
This class defines the container for a plane geometrical structure.
Definition: vpPlane.h:58
unsigned int clippingFlag
Flags specifying which clipping to used.
Definition: vpMbTracker.h:153
void insert(const vpMatrix &A, unsigned int r, unsigned int c)
Definition: vpMatrix.cpp:4909
vpMbHiddenFaces< vpMbtPolygon > * m_hiddenFace
Pointer to the list of faces.
virtual void initFaceFromLines(vpMbtPolygon &polygon)
virtual void setFarClippingDistance(const double &dist)
void setCameraParameters(const vpCameraParameters &cam)
virtual void setCameraParameters(const vpCameraParameters &camera)
vpImage< unsigned char > m_I
Grayscale image buffer, used when passing color images.
Definition: vpMbTracker.h:223
unsigned int getWidth() const
Definition: vpImage.h:246
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace=0, const std::string &name="")
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
double distNearClip
Distance for near clipping.
Definition: vpMbTracker.h:149
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
void computeScanLineRender(const vpCameraParameters &cam, const unsigned int &w, const unsigned int &h)
vpHomogeneousMatrix m_cMo
The current pose.
Definition: vpMbTracker.h:113
void eye()
Definition: vpMatrix.cpp:492
virtual void setDepthDenseFilteringMinDistance(double minDistance)
unsigned int setVisible(unsigned int width, unsigned int height, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angle, bool &changed)
unsigned int m_depthDenseSamplingStepY
Sampling step in y-direction.
virtual void setNearClippingDistance(const double &dist)
void computeFov(const unsigned int &w, const unsigned int &h)
std::vector< vpMbtFaceDepthDense * > m_depthDenseListOfActiveFaces
List of current active (visible and features extracted) faces.