38 #include <visp3/core/vpConfig.h>
40 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
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>
57 : m_depthDenseHiddenFacesDisplay(), m_depthDenseListOfActiveFaces(), m_denseDepthNbFeatures(0), m_depthDenseFaces(),
58 m_depthDenseSamplingStepX(2), m_depthDenseSamplingStepY(2), m_error_depthDense(), m_L_depthDense(),
59 m_robust_depthDense(), m_w_depthDense(), m_weightedError_depthDense()
60 #if DEBUG_DISPLAY_DEPTH_DENSE
62 m_debugDisp_depthDense(nullptr), m_debugImage_depthDense()
69 #if defined(VISP_HAVE_X11) && DEBUG_DISPLAY_DEPTH_DENSE
70 m_debugDisp_depthDense =
new vpDisplayX;
71 #elif defined(VISP_HAVE_GDI) && DEBUG_DISPLAY_DEPTH_DENSE
82 #if DEBUG_DISPLAY_DEPTH_DENSE
83 delete m_debugDisp_depthDense;
89 if (polygon.
nbpt < 3) {
108 for (
unsigned int i = 0; i < nbpt - 1; i++) {
122 pts[0] = polygon.
p[0];
123 pts[1] = polygon.
p[1];
124 pts[2] = polygon.
p[2];
132 bool changed =
false;
154 double normRes_1 = -1;
155 unsigned int iter = 0;
176 bool reStartFromLastIncrement =
false;
179 if (!reStartFromLastIncrement) {
184 if (!isoJoIdentity) {
210 isoJoIdentity =
false;
215 double num = 0.0, den = 0.0;
223 for (
unsigned int j = 0; j < 6; j++) {
235 normRes = sqrt(num / den);
264 unsigned int start_index = 0;
277 start_index += error.
getRows();
288 bool displayFullModel)
290 std::vector<std::vector<double> > models =
293 for (
size_t i = 0; i < models.size(); i++) {
304 bool displayFullModel)
306 std::vector<std::vector<double> > models =
309 for (
size_t i = 0; i < models.size(); i++) {
336 bool displayFullModel)
338 std::vector<std::vector<double> > models;
342 bool changed =
false;
355 std::vector<std::vector<double> > modelLines =
357 models.insert(models.end(), modelLines.begin(), modelLines.end());
369 bool reInitialisation =
false;
374 #ifdef VISP_HAVE_OGRE
399 #if defined(VISP_HAVE_PUGIXML)
411 std::cout <<
" *********** Parsing XML for Mb Depth Dense Tracker ************ " << std::endl;
413 xmlp.
parse(configFile);
416 std::cerr <<
"Exception: " << e.
what() << std::endl;
460 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
478 normal_face =
nullptr;
500 #ifdef VISP_HAVE_OGRE
513 (*it)->setCameraParameters(cam);
521 (*it)->setDepthDenseFilteringMaxDistance(maxDistance);
529 (*it)->setDepthDenseFilteringMethod(method);
537 (*it)->setDepthDenseFilteringMinDistance(minDistance);
543 if (occupancyRatio < 0.0 || occupancyRatio > 1.0) {
544 std::cerr <<
"occupancyRatio < 0.0 || occupancyRatio > 1.0" << std::endl;
550 (*it)->setDepthDenseFilteringOccupancyRatio(occupancyRatio);
554 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
559 #if DEBUG_DISPLAY_DEPTH_DENSE
560 if (!m_debugDisp_depthDense->isInitialised()) {
561 m_debugImage_depthDense.resize(point_cloud->height, point_cloud->width);
562 m_debugDisp_depthDense->init(m_debugImage_depthDense, 50, 0,
"Debug display dense depth tracker");
565 m_debugImage_depthDense = 0;
566 std::vector<std::vector<vpImagePoint> > roiPts_vec;
574 #if DEBUG_DISPLAY_DEPTH_DENSE
575 std::vector<std::vector<vpImagePoint> > roiPts_vec_;
578 #
if DEBUG_DISPLAY_DEPTH_DENSE
580 m_debugImage_depthDense, roiPts_vec_
586 #if DEBUG_DISPLAY_DEPTH_DENSE
587 roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
593 #if DEBUG_DISPLAY_DEPTH_DENSE
596 for (
size_t i = 0; i < roiPts_vec.size(); i++) {
597 if (roiPts_vec[i].empty())
600 for (
size_t j = 0; j < roiPts_vec[i].size() - 1; j++) {
603 vpDisplay::displayLine(m_debugImage_depthDense, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
617 #if DEBUG_DISPLAY_DEPTH_DENSE
618 if (!m_debugDisp_depthDense->isInitialised()) {
619 m_debugImage_depthDense.resize(height, width);
620 m_debugDisp_depthDense->init(m_debugImage_depthDense, 50, 0,
"Debug display dense depth tracker");
623 m_debugImage_depthDense = 0;
624 std::vector<std::vector<vpImagePoint> > roiPts_vec;
632 #if DEBUG_DISPLAY_DEPTH_DENSE
633 std::vector<std::vector<vpImagePoint> > roiPts_vec_;
637 #
if DEBUG_DISPLAY_DEPTH_DENSE
639 m_debugImage_depthDense, roiPts_vec_
645 #if DEBUG_DISPLAY_DEPTH_DENSE
646 roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
652 #if DEBUG_DISPLAY_DEPTH_DENSE
655 for (
size_t i = 0; i < roiPts_vec.size(); i++) {
656 if (roiPts_vec[i].empty())
659 for (
size_t j = 0; j < roiPts_vec[i].size() - 1; j++) {
662 vpDisplay::displayLine(m_debugImage_depthDense, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
676 #if DEBUG_DISPLAY_DEPTH_DENSE
677 if (!m_debugDisp_depthDense->isInitialised()) {
678 m_debugImage_depthDense.resize(height, width);
679 m_debugDisp_depthDense->init(m_debugImage_depthDense, 50, 0,
"Debug display dense depth tracker");
682 m_debugImage_depthDense = 0;
683 std::vector<std::vector<vpImagePoint> > roiPts_vec;
691 #if DEBUG_DISPLAY_DEPTH_DENSE
692 std::vector<std::vector<vpImagePoint> > roiPts_vec_;
696 #
if DEBUG_DISPLAY_DEPTH_DENSE
698 m_debugImage_depthDense, roiPts_vec_
704 #if DEBUG_DISPLAY_DEPTH_DENSE
705 roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
711 #if DEBUG_DISPLAY_DEPTH_DENSE
714 for (
size_t i = 0; i < roiPts_vec.size(); i++) {
715 if (roiPts_vec[i].empty())
718 for (
size_t j = 0; j < roiPts_vec[i].size() - 1; j++) {
721 vpDisplay::displayLine(m_debugImage_depthDense, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
732 #ifdef VISP_HAVE_OGRE
750 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
754 m_I.
resize(point_cloud->height, point_cloud->width);
766 (*it)->setScanLineVisibilityTest(v);
793 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
814 double ,
int ,
const std::string & )
820 int ,
const std::string & )
void setWindowName(const Ogre::String &n)
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int getRows() const
Generic class defining intrinsic camera parameters.
void computeFov(const unsigned int &w, const unsigned int &h)
Implementation of column vector and the associated operations.
void insert(unsigned int i, const vpColVector &v)
void resize(unsigned int i, bool flagNullify=true)
Class to define RGB colors available for display functionalities.
Display for windows using GDI (available on any windows 32 platform).
static void display(const vpImage< unsigned char > &I)
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
const char * what() const
static vpHomogeneousMatrix direct(const vpColVector &v)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getHeight() const
static double rad(double deg)
static double sqr(double x)
static bool equal(double x, double y, double threshold=0.001)
static double deg(double rad)
Implementation of a matrix and operations on matrices.
void insert(const vpMatrix &A, unsigned int r, unsigned int c)
virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE
virtual void initFaceFromCorners(vpMbtPolygon &polygon) VP_OVERRIDE
void segmentPointCloud(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud)
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false) VP_OVERRIDE
vpMbtTukeyEstimator< double > m_robust_depthDense
Tukey M-Estimator.
virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE
virtual void setDepthDenseFilteringMaxDistance(double maxDistance)
void computeVisibility(unsigned int width, unsigned int height)
virtual void setCameraParameters(const vpCameraParameters &camera) VP_OVERRIDE
virtual void setDepthDenseFilteringMethod(int method)
virtual void init(const vpImage< unsigned char > &I) VP_OVERRIDE
void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose=false)
vpColVector m_weightedError_depthDense
Weighted error.
unsigned int m_depthDenseSamplingStepY
Sampling step in y-direction.
virtual ~vpMbDepthDenseTracker() VP_OVERRIDE
virtual void resetTracker() VP_OVERRIDE
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE
vpMbHiddenFaces< vpMbtPolygon > m_depthDenseHiddenFacesDisplay
Set of faces describing the object used only for display with scan line.
virtual void testTracking() VP_OVERRIDE
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false) VP_OVERRIDE
void setUseDepthDenseTracking(const std::string &name, const bool &useDepthDenseTracking)
unsigned int m_depthDenseSamplingStepX
Sampling step in x-direction.
virtual void computeVVSWeights()
vpColVector m_error_depthDense
(s - s*)
virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace=0, const std::string &name="") VP_OVERRIDE
vpMatrix m_L_depthDense
Interaction matrix.
std::vector< vpMbtFaceDepthDense * > m_depthDenseListOfActiveFaces
List of current active (visible and features extracted) faces.
virtual void computeVVSInit() VP_OVERRIDE
virtual void track(const vpImage< unsigned char > &) VP_OVERRIDE
void setDepthDenseSamplingStep(unsigned int stepX, unsigned int stepY)
void addFace(vpMbtPolygon &polygon, bool alreadyClose)
virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE
virtual void setDepthDenseFilteringMinDistance(double minDistance)
unsigned int m_denseDepthNbFeatures
Nb features.
vpColVector m_w_depthDense
Robust weights.
virtual void loadConfigFile(const std::string &configFile, bool verbose=true) VP_OVERRIDE
virtual void setDepthDenseFilteringOccupancyRatio(double occupancyRatio)
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace=0, const std::string &name="") VP_OVERRIDE
std::vector< vpMbtFaceDepthDense * > m_depthDenseFaces
List of faces.
vpAROgre * getOgreContext()
void computeClippedPolygons(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam)
unsigned int setVisibleOgre(unsigned int width, unsigned int height, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
void initOgre(const vpCameraParameters &cam=vpCameraParameters())
unsigned int setVisible(unsigned int width, unsigned int height, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angle, bool &changed)
void setBackgroundSizeOgre(const unsigned int &h, const unsigned int &w)
void computeScanLineRender(const vpCameraParameters &cam, const unsigned int &w, const unsigned int &h)
void setOgreShowConfigDialog(bool showConfigDialog)
double m_lambda
Gain of the virtual visual servoing stage.
vpImage< unsigned char > m_I
Grayscale image buffer, used when passing color images.
bool m_computeInteraction
vpMatrix oJo
The Degrees of Freedom to estimate.
vpUniRand m_rand
Random number generator used in vpMbtDistanceLine::buildFrom()
double m_initialMu
Initial Mu for Levenberg Marquardt optimization loop.
vpHomogeneousMatrix m_cMo
The current pose.
virtual void computeVVSCheckLevenbergMarquardt(unsigned int iter, vpColVector &error, const vpColVector &m_error_prev, const vpHomogeneousMatrix &cMoPrev, double &mu, bool &reStartFromLastIncrement, vpColVector *const w=nullptr, const vpColVector *const m_w_prev=nullptr)
vpCameraParameters m_cam
The camera parameters.
double m_stopCriteriaEpsilon
Epsilon threshold to stop the VVS optimization loop.
bool useOgre
Use Ogre3d for visibility tests.
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
virtual void setScanLineVisibilityTest(const bool &v)
virtual void setOgreVisibilityTest(const bool &v)
virtual void computeCovarianceMatrixVVS(const bool isoJoIdentity, const vpColVector &w_true, const vpHomogeneousMatrix &cMoPrev, const vpMatrix &L_true, const vpMatrix &LVJ_true, const vpColVector &error)
vpMbtOptimizationMethod m_optimizationMethod
Optimization method used.
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=nullptr, vpColVector *const m_w_prev=nullptr)
double angleDisappears
Angle used to detect a face disappearance.
virtual void setNearClippingDistance(const double &dist)
virtual void setFarClippingDistance(const double &dist)
double distFarClip
Distance for near clipping.
bool m_isoJoIdentity
Boolean to know if oJo is identity (for fast computation)
bool useScanLine
Use Scanline for visibility tests.
virtual void setClipping(const unsigned int &flags)
double angleAppears
Angle used to detect a face appearance.
const vpImage< bool > * m_mask
Mask used to disable tracking on a part of image.
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
bool computeCovariance
Flag used to specify if the covariance matrix has to be computed or not.
double distNearClip
Distance for near clipping.
unsigned int m_maxIter
Maximum number of iterations of the virtual visual servoing stage.
bool ogreShowConfigDialog
unsigned int clippingFlag
Flags specifying which clipping to used.
vpMbHiddenFaces< vpMbtPolygon > * m_hiddenFace
Pointer to the list of faces.
double m_distFarClip
Distance for near clipping.
vpPlane m_planeObject
Plane equation described in the object frame.
std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
unsigned int getNbFeatures() const
void setTracked(bool tracked)
void computeInteractionMatrixAndResidu(const vpHomogeneousMatrix &cMo, vpMatrix &L, vpColVector &error)
vpMbtPolygon * m_polygon
Polygon defining the face.
bool m_useScanLine
Scan line visibility.
bool computeDesiredFeatures(const vpHomogeneousMatrix &cMo, const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud, unsigned int stepX, unsigned int stepY, const vpImage< bool > *mask=nullptr)
unsigned int m_clippingFlag
Flags specifying which clipping to used.
vpCameraParameters m_cam
Camera intrinsic parameters.
double m_distNearClip
Distance for near clipping.
void addLine(vpPoint &p1, vpPoint &p2, vpMbHiddenFaces< vpMbtPolygon > *const faces, vpUniRand &rand_gen, int polygon=-1, std::string name="")
Implementation of a polygon of the model used by the model-based tracker.
std::string getName() const
Parse an Xml file to extract configuration parameters of a mbtConfig object.
void getCameraParameters(vpCameraParameters &cam) const
void setDepthDenseSamplingStepY(unsigned int stepY)
double getAngleAppear() const
void setAngleDisappear(const double &adisappear)
double getAngleDisappear() const
void setDepthDenseSamplingStepX(unsigned int stepX)
void setAngleAppear(const double &aappear)
unsigned int getDepthDenseSamplingStepY() const
void parse(const std::string &filename)
double getNearClippingDistance() const
bool hasNearClippingDistance() const
bool hasFarClippingDistance() const
unsigned int getDepthDenseSamplingStepX() const
void setCameraParameters(const vpCameraParameters &cam)
double getFarClippingDistance() const
bool getFovClipping() const
void setVerbose(bool verbose)
This class defines the container for a plane geometrical structure.
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
unsigned int nbpt
Number of points used to define the polygon.
unsigned int getNbPoint() const
vpPoint * p
corners in the object frame
vpVelocityTwistMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)