38 #include <visp3/core/vpConfig.h> 41 #include <pcl/point_cloud.h> 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> 50 #if DEBUG_DISPLAY_DEPTH_DENSE 51 #include <visp3/gui/vpDisplayGDI.h> 52 #include <visp3/gui/vpDisplayX.h> 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
61 m_debugDisp_depthDense(NULL), m_debugImage_depthDense()
68 #if defined(VISP_HAVE_X11) && DEBUG_DISPLAY_DEPTH_DENSE 70 #elif defined(VISP_HAVE_GDI) && DEBUG_DISPLAY_DEPTH_DENSE 81 #if DEBUG_DISPLAY_DEPTH_DENSE 82 delete m_debugDisp_depthDense;
88 if (polygon.
nbpt < 3) {
107 for (
unsigned int i = 0; i < nbpt - 1; i++) {
121 pts[0] = polygon.
p[0];
122 pts[1] = polygon.
p[1];
123 pts[2] = polygon.
p[2];
131 bool changed =
false;
143 for (std::vector<vpMbtFaceDepthDense *>::const_iterator it =
m_depthDenseFaces.begin();
153 double normRes_1 = -1;
154 unsigned int iter = 0;
165 bool isoJoIdentity_ =
true;
172 bool reStartFromLastIncrement =
false;
175 if (!reStartFromLastIncrement) {
180 if (!isoJoIdentity_) {
188 isoJoIdentity_ =
true;
195 if (isoJoIdentity_) {
209 isoJoIdentity_ =
false;
214 double num = 0.0, den = 0.0;
222 for (
unsigned int j = 0; j < 6; j++) {
234 normRes = sqrt(num / den);
263 unsigned int start_index = 0;
276 start_index += error.
getRows();
287 bool displayFullModel)
291 for (
size_t i = 0; i < models.size(); i++) {
302 bool displayFullModel)
306 for (
size_t i = 0; i < models.size(); i++) {
332 bool displayFullModel)
334 std::vector<std::vector<double> > models;
338 bool changed =
false;
348 for (std::vector<vpMbtFaceDepthDense *>::const_iterator it =
m_depthDenseFaces.begin();
351 std::vector<std::vector<double> > modelLines = face_dense->
getModelForDisplay(width, height, cMo, cam, displayFullModel);
352 models.insert(models.end(), modelLines.begin(), modelLines.end());
364 bool reInitialisation =
false;
368 #ifdef VISP_HAVE_OGRE 404 std::cout <<
" *********** Parsing XML for Mb Depth Dense Tracker ************ " << std::endl;
406 xmlp.
parse(configFile);
408 std::cerr <<
"Exception: " << e.
what() << std::endl;
447 #if defined(VISP_HAVE_PCL) 462 for (std::vector<vpMbtFaceDepthDense *>::iterator it =
m_depthDenseFaces.begin();
488 #ifdef VISP_HAVE_OGRE 499 for (std::vector<vpMbtFaceDepthDense *>::const_iterator it =
m_depthDenseFaces.begin();
501 (*it)->setCameraParameters(cam);
507 for (std::vector<vpMbtFaceDepthDense *>::const_iterator it =
m_depthDenseFaces.begin();
509 (*it)->setDepthDenseFilteringMaxDistance(maxDistance);
515 for (std::vector<vpMbtFaceDepthDense *>::const_iterator it =
m_depthDenseFaces.begin();
517 (*it)->setDepthDenseFilteringMethod(method);
523 for (std::vector<vpMbtFaceDepthDense *>::const_iterator it =
m_depthDenseFaces.begin();
525 (*it)->setDepthDenseFilteringMinDistance(minDistance);
531 if (occupancyRatio < 0.0 || occupancyRatio > 1.0) {
532 std::cerr <<
"occupancyRatio < 0.0 || occupancyRatio > 1.0" << std::endl;
536 for (std::vector<vpMbtFaceDepthDense *>::const_iterator it =
m_depthDenseFaces.begin();
538 (*it)->setDepthDenseFilteringOccupancyRatio(occupancyRatio);
547 #if DEBUG_DISPLAY_DEPTH_DENSE 548 if (!m_debugDisp_depthDense->isInitialised()) {
549 m_debugImage_depthDense.resize(point_cloud->height, point_cloud->width);
550 m_debugDisp_depthDense->init(m_debugImage_depthDense, 50, 0,
"Debug display dense depth tracker");
553 m_debugImage_depthDense = 0;
554 std::vector<std::vector<vpImagePoint> > roiPts_vec;
557 for (std::vector<vpMbtFaceDepthDense *>::iterator it =
m_depthDenseFaces.begin();
562 #if DEBUG_DISPLAY_DEPTH_DENSE 563 std::vector<std::vector<vpImagePoint> > roiPts_vec_;
566 #
if DEBUG_DISPLAY_DEPTH_DENSE
568 m_debugImage_depthDense, roiPts_vec_
574 #if DEBUG_DISPLAY_DEPTH_DENSE 575 roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
581 #if DEBUG_DISPLAY_DEPTH_DENSE 584 for (
size_t i = 0; i < roiPts_vec.size(); i++) {
585 if (roiPts_vec[i].empty())
588 for (
size_t j = 0; j < roiPts_vec[i].size() - 1; j++) {
591 vpDisplay::displayLine(m_debugImage_depthDense, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
605 #if DEBUG_DISPLAY_DEPTH_DENSE 606 if (!m_debugDisp_depthDense->isInitialised()) {
607 m_debugImage_depthDense.resize(height, width);
608 m_debugDisp_depthDense->init(m_debugImage_depthDense, 50, 0,
"Debug display dense depth tracker");
611 m_debugImage_depthDense = 0;
612 std::vector<std::vector<vpImagePoint> > roiPts_vec;
615 for (std::vector<vpMbtFaceDepthDense *>::iterator it =
m_depthDenseFaces.begin();
620 #if DEBUG_DISPLAY_DEPTH_DENSE 621 std::vector<std::vector<vpImagePoint> > roiPts_vec_;
625 #
if DEBUG_DISPLAY_DEPTH_DENSE
627 m_debugImage_depthDense, roiPts_vec_
633 #if DEBUG_DISPLAY_DEPTH_DENSE 634 roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
640 #if DEBUG_DISPLAY_DEPTH_DENSE 643 for (
size_t i = 0; i < roiPts_vec.size(); i++) {
644 if (roiPts_vec[i].empty())
647 for (
size_t j = 0; j < roiPts_vec[i].size() - 1; j++) {
650 vpDisplay::displayLine(m_debugImage_depthDense, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
661 #ifdef VISP_HAVE_OGRE 679 #if defined(VISP_HAVE_PCL) 683 m_I.
resize(point_cloud->height, point_cloud->width);
693 for (std::vector<vpMbtFaceDepthDense *>::const_iterator it =
m_depthDenseFaces.begin();
695 (*it)->setScanLineVisibilityTest(v);
701 for (std::vector<vpMbtFaceDepthDense *>::const_iterator it =
m_depthDenseFaces.begin();
744 double ,
int ,
const std::string & )
750 int ,
const std::string & )
bool m_computeInteraction
void setWindowName(const Ogre::String &n)
vpMbtTukeyEstimator< double > m_robust_depthDense
Tukey M-Estimator.
Implementation of a matrix and operations on matrices.
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.
virtual void computeVVSWeights()
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
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)
void setVerbose(bool verbose)
bool hasFarClippingDistance() const
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)
virtual void loadConfigFile(const std::string &configFile, bool verbose=true)
void parse(const std::string &filename)
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
void getCameraParameters(vpCameraParameters &cam) const
vpColVector m_weightedError_depthDense
Weighted error.
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual ~vpMbDepthDenseTracker()
std::string getName() const
void segmentPointCloud(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud)
virtual void track(const vpImage< unsigned char > &)
Display for windows using GDI (available on any windows 32 platform).
Class to define RGB colors available for display functionnalities.
static bool equal(double x, double y, double s=0.001)
bool m_useScanLine
Scan line visibility.
void setBackgroundSizeOgre(const unsigned int &h, const unsigned int &w)
double getFarClippingDistance() const
void addLine(vpPoint &p1, vpPoint &p2, vpMbHiddenFaces< vpMbtPolygon > *const faces, vpUniRand &rand_gen, int polygon=-1, std::string name="")
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...
void setTracked(bool tracked)
error that can be emited by ViSP classes.
vpPoint * p
corners in the object frame
unsigned int getRows() const
vpHomogeneousMatrix inverse() const
bool useOgre
Use Ogre3d for visibility tests.
double getNearClippingDistance() const
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.
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)
double getAngleAppear() const
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
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.
vpAROgre * getOgreContext()
unsigned int m_denseDepthNbFeatures
Nb features.
vpMatrix oJo
The Degrees of Freedom to estimate.
virtual void setDepthDenseFilteringMethod(int method)
Implementation of a polygon of the model used by the model-based tracker.
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.
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double sqr(double x)
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 getAngleDisappear() const
double m_distFarClip
Distance for near clipping.
bool getFovClipping() const
Generic class defining intrinsic camera parameters.
void setOgreShowConfigDialog(bool showConfigDialog)
unsigned int getNbPoint() const
double m_initialMu
Initial Mu for Levenberg Marquardt optimization loop.
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.
unsigned int m_depthDenseSamplingStepX
Sampling step in x-direction.
void setDepthDenseSamplingStepY(unsigned int stepY)
vpMbtOptimizationMethod m_optimizationMethod
Optimization method used.
void computeVisibility(unsigned int width, unsigned int height)
double angleAppears
Angle used to detect a face appearance.
unsigned int getNbFeatures() const
unsigned int m_maxIter
Maximum number of iterations of the virtual visual servoing stage.
virtual void testTracking()
void setAngleAppear(const double &aappear)
const char * what() const
static double rad(double deg)
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)
virtual void computeVVSInit()
virtual void resetTracker()
const vpImage< bool > * m_mask
Mask used to disable tracking on a part of image.
void resize(unsigned int i, bool flagNullify=true)
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
virtual void computeVVSPoseEstimation(const bool isoJoIdentity_, unsigned int iter, vpMatrix &L, vpMatrix <L, vpColVector &R, const vpColVector &error, vpColVector &error_prev, vpColVector <R, 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.
double m_stopCriteriaEpsilon
Epsilon threshold to stop the VVS optimization loop.
static double deg(double rad)
virtual void setOgreVisibilityTest(const bool &v)
unsigned int getHeight() const
bool ogreShowConfigDialog
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace=0, const std::string &name="")
bool hasNearClippingDistance() const
Implementation of column vector and the associated operations.
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.
unsigned int getDepthDenseSamplingStepX() const
virtual void computeVVSInteractionMatrixAndResidu()
virtual void setScanLineVisibilityTest(const bool &v)
virtual void setClipping(const unsigned int &flags)
vpUniRand m_rand
Random number generator used in vpMbtDistanceLine::buildFrom()
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 ...
This class defines the container for a plane geometrical structure.
unsigned int clippingFlag
Flags specifying which clipping to used.
void insert(const vpMatrix &A, unsigned int r, unsigned int c)
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.
unsigned int getWidth() const
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.
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.
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.