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/vpMbDepthNormalTracker.h> 48 #include <visp3/mbt/vpMbtXmlGenericParser.h> 50 #if DEBUG_DISPLAY_DEPTH_NORMAL 51 #include <visp3/gui/vpDisplayGDI.h> 52 #include <visp3/gui/vpDisplayX.h> 57 m_depthNormalHiddenFacesDisplay(), m_depthNormalListOfActiveFaces(),
58 m_depthNormalListOfDesiredFeatures(), m_depthNormalFaces(), m_depthNormalPclPlaneEstimationMethod(2),
59 m_depthNormalPclPlaneEstimationRansacMaxIter(200), m_depthNormalPclPlaneEstimationRansacThreshold(0.001),
60 m_depthNormalSamplingStepX(2), m_depthNormalSamplingStepY(2), m_depthNormalUseRobust(false), m_error_depthNormal(),
61 m_featuresToBeDisplayedDepthNormal(), m_L_depthNormal(), m_robust_depthNormal(), m_w_depthNormal(), m_weightedError_depthNormal()
62 #if DEBUG_DISPLAY_DEPTH_NORMAL
64 m_debugDisp_depthNormal(NULL), m_debugImage_depthNormal()
71 #if defined(VISP_HAVE_X11) && DEBUG_DISPLAY_DEPTH_NORMAL 73 #elif defined(VISP_HAVE_GDI) && DEBUG_DISPLAY_DEPTH_NORMAL 87 if (polygon.
nbpt < 3) {
110 for (
unsigned int i = 0; i < nbpt - 1; i++) {
124 pts[0] = polygon.
p[0];
125 pts[1] = polygon.
p[1];
126 pts[2] = polygon.
p[2];
134 bool changed =
false;
146 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
156 double normRes_1 = -1;
157 unsigned int iter = 0;
169 bool isoJoIdentity_ =
true;
176 bool reStartFromLastIncrement =
false;
179 if (!reStartFromLastIncrement) {
185 if (!isoJoIdentity_) {
193 isoJoIdentity_ =
true;
200 if (isoJoIdentity_) {
214 isoJoIdentity_ =
false;
219 double num = 0.0, den = 0.0;
227 for (
unsigned int j = 0; j < 6; j++) {
239 normRes = sqrt(num / den);
264 unsigned int cpt = 0;
269 (*it)->computeInteractionMatrix(
m_cMo, L_face, features_face);
282 bool displayFullModel)
286 for (
size_t i = 0; i < models.size(); i++) {
296 for (
size_t i = 0; i < features.size(); i++) {
297 vpImagePoint im_centroid(features[i][1], features[i][2]);
298 vpImagePoint im_extremity(features[i][3], features[i][4]);
307 bool displayFullModel)
311 for (
size_t i = 0; i < models.size(); i++) {
321 for (
size_t i = 0; i < features.size(); i++) {
322 vpImagePoint im_centroid(features[i][1], features[i][2]);
323 vpImagePoint im_extremity(features[i][3], features[i][4]);
331 std::vector<std::vector<double> > features;
333 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
337 features.insert(features.end(), currentFeatures.begin(), currentFeatures.end());
360 bool displayFullModel)
362 std::vector<std::vector<double> > models;
366 bool changed =
false;
376 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
379 std::vector<std::vector<double> > modelLines = face_normal->
getModelForDisplay(width, height, cMo, cam, displayFullModel);
380 models.insert(models.end(), modelLines.begin(), modelLines.end());
392 bool reInitialisation =
false;
396 #ifdef VISP_HAVE_OGRE 436 std::cout <<
" *********** Parsing XML for Mb Depth Tracker ************ " << std::endl;
438 xmlp.
parse(configFile);
440 std::cerr <<
"Exception: " << e.
what() << std::endl;
483 #if defined(VISP_HAVE_PCL) 523 #ifdef VISP_HAVE_OGRE 534 #ifdef VISP_HAVE_OGRE 552 #if defined(VISP_HAVE_PCL) 566 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
568 (*it)->setScanLineVisibilityTest(v);
574 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
591 #if DEBUG_DISPLAY_DEPTH_NORMAL 592 if (!m_debugDisp_depthNormal->isInitialised()) {
593 m_debugImage_depthNormal.resize(point_cloud->height, point_cloud->width);
594 m_debugDisp_depthNormal->init(m_debugImage_depthNormal, 50, 0,
"Debug display normal depth tracker");
597 m_debugImage_depthNormal = 0;
598 std::vector<std::vector<vpImagePoint> > roiPts_vec;
608 #if DEBUG_DISPLAY_DEPTH_NORMAL 609 std::vector<std::vector<vpImagePoint> > roiPts_vec_;
613 #
if DEBUG_DISPLAY_DEPTH_NORMAL
615 m_debugImage_depthNormal, roiPts_vec_
622 #if DEBUG_DISPLAY_DEPTH_NORMAL 623 roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
629 #if DEBUG_DISPLAY_DEPTH_NORMAL 632 for (
size_t i = 0; i < roiPts_vec.size(); i++) {
633 if (roiPts_vec[i].empty())
636 for (
size_t j = 0; j < roiPts_vec[i].size() - 1; j++) {
639 vpDisplay::displayLine(m_debugImage_depthNormal, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
654 #if DEBUG_DISPLAY_DEPTH_NORMAL 655 if (!m_debugDisp_depthNormal->isInitialised()) {
656 m_debugImage_depthNormal.resize(height, width);
657 m_debugDisp_depthNormal->init(m_debugImage_depthNormal, 50, 0,
"Debug display normal depth tracker");
660 m_debugImage_depthNormal = 0;
661 std::vector<std::vector<vpImagePoint> > roiPts_vec;
671 #if DEBUG_DISPLAY_DEPTH_NORMAL 672 std::vector<std::vector<vpImagePoint> > roiPts_vec_;
677 #
if DEBUG_DISPLAY_DEPTH_NORMAL
679 m_debugImage_depthNormal, roiPts_vec_
686 #if DEBUG_DISPLAY_DEPTH_NORMAL 687 roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
693 #if DEBUG_DISPLAY_DEPTH_NORMAL 696 for (
size_t i = 0; i < roiPts_vec.size(); i++) {
697 if (roiPts_vec[i].empty())
700 for (
size_t j = 0; j < roiPts_vec[i].size() - 1; j++) {
703 vpDisplay::displayLine(m_debugImage_depthNormal, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
715 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
717 (*it)->setCameraParameters(cam);
723 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
725 (*it)->setFaceCentroidMethod(method);
734 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
736 (*it)->setFeatureEstimationMethod(method);
744 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
746 (*it)->setPclPlaneEstimationMethod(method);
754 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
756 (*it)->setPclPlaneEstimationRansacMaxIter(maxIter);
764 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
766 (*it)->setPclPlaneEstimationRansacThreshold(threshold);
772 if (stepX == 0 || stepY == 0) {
773 std::cerr <<
"stepX and stepY must be greater than zero!" << std::endl;
817 double ,
int ,
const std::string & )
823 int ,
const std::string & )
bool m_computeInteraction
void setWindowName(const Ogre::String &n)
virtual void initFaceFromLines(vpMbtPolygon &polygon)
virtual void setDepthNormalSamplingStep(unsigned int stepX, unsigned int stepY)
void setPclPlaneEstimationRansacThreshold(double threshold)
Implementation of a matrix and operations on matrices.
vpMbtFaceDepthNormal::vpFeatureEstimationType m_depthNormalFeatureEstimationMethod
Method to estimate the desired features.
double getFarClippingDistance() const
vpCameraParameters m_cam
The camera parameters.
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
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)
bool m_depthNormalUseRobust
If true, use Tukey robust M-Estimator.
void addFace(vpMbtPolygon &polygon, bool alreadyClose)
void addLine(vpPoint &p1, vpPoint &p2, vpMbHiddenFaces< vpMbtPolygon > *const faces, vpUniRand &rand_gen, int polygon=-1, std::string name="")
vpColVector m_w_depthNormal
Robust weights.
void setVerbose(bool verbose)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
unsigned int getWidth() const
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.
double getNearClippingDistance() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace=0, const std::string &name="")
int m_depthNormalPclPlaneEstimationRansacMaxIter
PCL RANSAC maximum number of iterations.
void setDepthNormalSamplingStepY(unsigned int stepY)
bool hasNearClippingDistance() const
Display for windows using GDI (available on any windows 32 platform).
virtual void setDepthNormalFaceCentroidMethod(const vpMbtFaceDepthNormal::vpFaceCentroidType &method)
vpColVector m_error_depthNormal
(s - s*)
unsigned int m_clippingFlag
Flags specifying which clipping to used.
Class to define RGB colors available for display functionnalities.
static bool equal(double x, double y, double s=0.001)
double getAngleAppear() const
virtual std::vector< std::vector< double > > getFeaturesForDisplayDepthNormal()
void setBackgroundSizeOgre(const unsigned int &h, const unsigned int &w)
std::vector< vpColVector > m_depthNormalListOfDesiredFeatures
List of desired features.
virtual void track(const vpImage< unsigned char > &)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
virtual void resetTracker()
void getCameraParameters(vpCameraParameters &cam) const
error that can be emited by ViSP classes.
vpPoint * p
corners in the object frame
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
bool useOgre
Use Ogre3d for visibility tests.
double m_distNearClip
Distance for near clipping.
virtual void init(const vpImage< unsigned char > &I)
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.
virtual void setDepthNormalPclPlaneEstimationRansacThreshold(double thresold)
static void flush(const vpImage< unsigned char > &I)
unsigned int setVisibleOgre(unsigned int width, unsigned int height, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
bool m_useScanLine
Scan line visibility.
virtual void setDepthNormalPclPlaneEstimationRansacMaxIter(int maxIter)
virtual void computeVVSInit()
std::vector< std::vector< double > > getFeaturesForDisplay(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double scale=0.05)
vpCameraParameters m_cam
Camera intrinsic parameters.
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)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
vpColVector m_weightedError_depthNormal
Weighted error.
Parse an Xml file to extract configuration parameters of a mbtConfig object.Data parser for the model...
void initOgre(const vpCameraParameters &cam=vpCameraParameters())
void setUseDepthNormalTracking(const std::string &name, const bool &useDepthNormalTracking)
double distFarClip
Distance for near clipping.
virtual ~vpMbDepthNormalTracker()
vpMbtPolygon * m_polygon
Polygon defining the face.
vpAROgre * getOgreContext()
virtual void loadConfigFile(const std::string &configFile, bool verbose=true)
const char * what() const
void segmentPointCloud(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud)
bool hasFarClippingDistance() const
vpMatrix oJo
The Degrees of Freedom to estimate.
void computeVisibility(unsigned int width, unsigned int height)
unsigned int m_depthNormalSamplingStepX
Sampling step in x-direction.
Implementation of a polygon of the model used by the model-based tracker.
void setAngleDisappear(const double &adisappear)
std::string getName() const
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
double m_depthNormalPclPlaneEstimationRansacThreshold
PCL RANSAC threshold.
bool useScanLine
Use Scanline for visibility tests.
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double sqr(double x)
void setDepthNormalSamplingStepX(unsigned int stepX)
static void display(const vpImage< unsigned char > &I)
vpMbHiddenFaces< vpMbtPolygon > * m_hiddenFace
Pointer to the list of faces.
Generic class defining intrinsic camera parameters.
void setTracked(bool tracked)
void setOgreShowConfigDialog(bool showConfigDialog)
double getDepthNormalPclPlaneEstimationRansacThreshold() const
virtual void setOgreVisibilityTest(const bool &v)
virtual void testTracking()
double m_initialMu
Initial Mu for Levenberg Marquardt optimization loop.
double m_lambda
Gain of the virtual visual servoing stage.
virtual void computeVVSWeights(vpRobust &robust, const vpColVector &error, vpColVector &w)
vpMbtOptimizationMethod m_optimizationMethod
Optimization method used.
unsigned int m_depthNormalSamplingStepY
Sampling step in y-direction.
unsigned int getRows() const
double getAngleDisappear() const
double angleAppears
Angle used to detect a face appearance.
double m_distFarClip
Distance for near clipping.
unsigned int getDepthNormalSamplingStepX() const
unsigned int m_maxIter
Maximum number of iterations of the virtual visual servoing stage.
virtual void setScanLineVisibilityTest(const bool &v)
void setAngleAppear(const double &aappear)
static double rad(double deg)
virtual void computeVVSInteractionMatrixAndResidu()
void setFeatureEstimationMethod(const vpFeatureEstimationType &method)
void setDepthNormalPclPlaneEstimationRansacMaxIter(int maxIter)
void insert(unsigned int i, const vpColVector &v)
vpMatrix m_L_depthNormal
Interaction matrix.
vpRobust m_robust_depthNormal
Robust.
const vpImage< bool > * m_mask
Mask used to disable tracking on a part of image.
vpMbtFaceDepthNormal::vpFeatureEstimationType getDepthNormalFeatureEstimationMethod() const
void resize(unsigned int i, bool flagNullify=true)
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)
bool displayFeatures
If true, the features are displayed.
std::vector< vpMbtFaceDepthNormal * > m_depthNormalFaces
List of faces.
bool ogreShowConfigDialog
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace=0, const std::string &name="")
Implementation of column vector and the associated operations.
int m_depthNormalPclPlaneEstimationMethod
PCL plane estimation method.
std::vector< vpMbtFaceDepthNormal * > m_depthNormalListOfActiveFaces
List of current active (visible and with features extracted) faces.
vpHomogeneousMatrix inverse() const
static vpHomogeneousMatrix direct(const vpColVector &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)
double angleDisappears
Angle used to detect a face disappearance.
unsigned int getHeight() const
unsigned int getNbPoint() const
void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose=false)
bool getFovClipping() const
unsigned int getDepthNormalSamplingStepY() const
virtual void setScanLineVisibilityTest(const bool &v)
virtual void setClipping(const unsigned int &flags)
vpUniRand m_rand
Random number generator used in vpMbtDistanceLine::buildFrom()
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void setDepthNormalFeatureEstimationMethod(const vpMbtFaceDepthNormal::vpFeatureEstimationType &method)
This class defines the container for a plane geometrical structure.
unsigned int clippingFlag
Flags specifying which clipping to used.
void setMinMedianAbsoluteDeviation(double mad_min)
void insert(const vpMatrix &A, unsigned int r, unsigned int c)
virtual void setDepthNormalFeatureEstimationMethod(const vpMbtFaceDepthNormal::vpFeatureEstimationType &method)
vpPlane m_planeObject
Plane equation described in the object frame.
vpMbHiddenFaces< vpMbtPolygon > m_depthNormalHiddenFacesDisplay
Set of faces describing the object used only for display with scan line.
virtual void setFarClippingDistance(const double &dist)
void setCameraParameters(const vpCameraParameters &cam)
void setPclPlaneEstimationRansacMaxIter(int maxIter)
bool computeDesiredFeatures(const vpHomogeneousMatrix &cMo, unsigned int width, unsigned int height, const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud, vpColVector &desired_features, unsigned int stepX, unsigned int stepY, const vpImage< bool > *mask=NULL)
vpImage< unsigned char > m_I
Grayscale image buffer, used when passing color images.
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
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.
int getDepthNormalPclPlaneEstimationRansacMaxIter() const
void setDepthNormalPclPlaneEstimationRansacThreshold(double threshold)
void computeScanLineRender(const vpCameraParameters &cam, const unsigned int &w, const unsigned int &h)
int getDepthNormalPclPlaneEstimationMethod() const
vpHomogeneousMatrix m_cMo
The current pose.
void setDepthNormalPclPlaneEstimationMethod(int method)
virtual void setDepthNormalPclPlaneEstimationMethod(int method)
void setPclPlaneEstimationMethod(int method)
unsigned int setVisible(unsigned int width, unsigned int height, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angle, bool &changed)
static const vpColor blue
virtual void setCameraParameters(const vpCameraParameters &camera)
virtual void setNearClippingDistance(const double &dist)
void computeFov(const unsigned int &w, const unsigned int &h)