36#include <visp3/core/vpConfig.h>
38#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
39#include <pcl/point_cloud.h>
42#include <visp3/core/vpDisplay.h>
43#include <visp3/core/vpExponentialMap.h>
44#include <visp3/core/vpTrackingException.h>
45#include <visp3/mbt/vpMbDepthNormalTracker.h>
46#include <visp3/mbt/vpMbtXmlGenericParser.h>
48#if DEBUG_DISPLAY_DEPTH_NORMAL
49#include <visp3/gui/vpDisplayGDI.h>
50#include <visp3/gui/vpDisplayX.h>
64#if DEBUG_DISPLAY_DEPTH_NORMAL
66 m_debugDisp_depthNormal(nullptr), m_debugImage_depthNormal()
70 faces.getOgreContext()->setWindowName(
"MBT Depth");
73#if defined(VISP_HAVE_X11) && DEBUG_DISPLAY_DEPTH_NORMAL
75#elif defined(VISP_HAVE_GDI) && DEBUG_DISPLAY_DEPTH_NORMAL
89 if (polygon.
nbpt < 3) {
112 for (
unsigned int i = 0; i < nbpt - 1; i++) {
126 pts[0] = polygon.
p[0];
127 pts[1] = polygon.
p[1];
128 pts[2] = polygon.
p[2];
136 bool changed =
false;
145 faces.computeScanLineRender(
m_cam, width, height);
148 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
158 double normRes_1 = -1;
159 unsigned int iter = 0;
181 bool reStartFromLastIncrement =
false;
184 if (!reStartFromLastIncrement) {
190 if (!isoJoIdentity) {
216 isoJoIdentity =
false;
221 double num = 0.0, den = 0.0;
229 for (
unsigned int j = 0; j < 6; j++) {
241 normRes = sqrt(num / den);
266 unsigned int cpt = 0;
272 (*it)->computeInteractionMatrix(
m_cMo, L_face, features_face);
293 bool displayFullModel)
295 std::vector<std::vector<double> > models =
298 for (
size_t i = 0; i < models.size(); i++) {
308 for (
size_t i = 0; i < features.size(); i++) {
309 vpImagePoint im_centroid(features[i][1], features[i][2]);
310 vpImagePoint im_extremity(features[i][3], features[i][4]);
319 bool displayFullModel)
321 std::vector<std::vector<double> > models =
324 for (
size_t i = 0; i < models.size(); i++) {
334 for (
size_t i = 0; i < features.size(); i++) {
335 vpImagePoint im_centroid(features[i][1], features[i][2]);
336 vpImagePoint im_extremity(features[i][3], features[i][4]);
345 std::vector<std::vector<double> > features;
347 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
351 features.insert(features.end(), currentFeatures.begin(), currentFeatures.end());
375 bool displayFullModel)
377 std::vector<std::vector<double> > models;
381 bool changed =
false;
391 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
394 std::vector<std::vector<double> > modelLines =
396 models.insert(models.end(), modelLines.begin(), modelLines.end());
408 bool reInitialisation =
false;
414 if (!
faces.isOgreInitialised()) {
415 faces.setBackgroundSizeOgre(I.getHeight(), I.getWidth());
431 m_cam.computeFov(I.getWidth(), I.getHeight());
438#if defined(VISP_HAVE_PUGIXML)
454 std::cout <<
" *********** Parsing XML for Mb Depth Tracker ************ " << std::endl;
456 xmlp.
parse(configFile);
459 std::cerr <<
"Exception: " << e.what() << std::endl;
507#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
525 normal_face =
nullptr;
558 faces.getOgreContext()->setWindowName(
"MBT Depth");
575#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
589 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
591 (*it)->setScanLineVisibilityTest(v);
597 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
608#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_SEGMENTATION) && defined(VISP_HAVE_PCL_FILTERS) && defined(VISP_HAVE_PCL_COMMON)
614#if DEBUG_DISPLAY_DEPTH_NORMAL
615 if (!m_debugDisp_depthNormal->isInitialised()) {
616 m_debugImage_depthNormal.resize(point_cloud->height, point_cloud->width);
617 m_debugDisp_depthNormal->init(m_debugImage_depthNormal, 50, 0,
"Debug display normal depth tracker");
620 m_debugImage_depthNormal = 0;
621 std::vector<std::vector<vpImagePoint> > roiPts_vec;
631#if DEBUG_DISPLAY_DEPTH_NORMAL
632 std::vector<std::vector<vpImagePoint> > roiPts_vec_;
636#
if DEBUG_DISPLAY_DEPTH_NORMAL
638 m_debugImage_depthNormal, roiPts_vec_
645#if DEBUG_DISPLAY_DEPTH_NORMAL
646 roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
652#if DEBUG_DISPLAY_DEPTH_NORMAL
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_depthNormal, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
677#if DEBUG_DISPLAY_DEPTH_NORMAL
678 if (!m_debugDisp_depthNormal->isInitialised()) {
679 m_debugImage_depthNormal.resize(height, width);
680 m_debugDisp_depthNormal->init(m_debugImage_depthNormal, 50, 0,
"Debug display normal depth tracker");
683 m_debugImage_depthNormal = 0;
684 std::vector<std::vector<vpImagePoint> > roiPts_vec;
694#if DEBUG_DISPLAY_DEPTH_NORMAL
695 std::vector<std::vector<vpImagePoint> > roiPts_vec_;
700#
if DEBUG_DISPLAY_DEPTH_NORMAL
702 m_debugImage_depthNormal, roiPts_vec_
709#if DEBUG_DISPLAY_DEPTH_NORMAL
710 roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
716#if DEBUG_DISPLAY_DEPTH_NORMAL
719 for (
size_t i = 0; i < roiPts_vec.size(); i++) {
720 if (roiPts_vec[i].empty())
723 for (
size_t j = 0; j < roiPts_vec[i].size() - 1; j++) {
726 vpDisplay::displayLine(m_debugImage_depthNormal, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
740#if DEBUG_DISPLAY_DEPTH_NORMAL
741 if (!m_debugDisp_depthNormal->isInitialised()) {
742 m_debugImage_depthNormal.resize(height, width);
743 m_debugDisp_depthNormal->init(m_debugImage_depthNormal, 50, 0,
"Debug display normal depth tracker");
746 m_debugImage_depthNormal = 0;
747 std::vector<std::vector<vpImagePoint> > roiPts_vec;
757#if DEBUG_DISPLAY_DEPTH_NORMAL
758 std::vector<std::vector<vpImagePoint> > roiPts_vec_;
763#
if DEBUG_DISPLAY_DEPTH_NORMAL
765 m_debugImage_depthNormal, roiPts_vec_
772#if DEBUG_DISPLAY_DEPTH_NORMAL
773 roiPts_vec.insert(roiPts_vec.end(), roiPts_vec_.begin(), roiPts_vec_.end());
779#if DEBUG_DISPLAY_DEPTH_NORMAL
782 for (
size_t i = 0; i < roiPts_vec.size(); i++) {
783 if (roiPts_vec[i].empty())
786 for (
size_t j = 0; j < roiPts_vec[i].size() - 1; j++) {
789 vpDisplay::displayLine(m_debugImage_depthNormal, roiPts_vec[i][0], roiPts_vec[i][roiPts_vec[i].size() - 1],
801 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
803 (*it)->setCameraParameters(cam);
809 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
811 (*it)->setFaceCentroidMethod(method);
820 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
822 (*it)->setFeatureEstimationMethod(method);
830 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
832 (*it)->setPclPlaneEstimationMethod(method);
840 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
842 (*it)->setPclPlaneEstimationRansacMaxIter(maxIter);
850 for (std::vector<vpMbtFaceDepthNormal *>::const_iterator it =
m_depthNormalFaces.begin();
852 (*it)->setPclPlaneEstimationRansacThreshold(threshold);
858 if (stepX == 0 || stepY == 0) {
859 std::cerr <<
"stepX and stepY must be greater than zero!" << std::endl;
881#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_SEGMENTATION) && defined(VISP_HAVE_PCL_FILTERS) && defined(VISP_HAVE_PCL_COMMON)
902 double ,
int ,
const std::string & )
908 int ,
const std::string & )
Generic class defining intrinsic camera parameters.
void computeFov(const unsigned int &w, const unsigned int &h)
Implementation of column vector and the associated operations.
Class to define RGB colors available for display functionalities.
static const vpColor blue
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
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)
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)
error that can be emitted by ViSP classes.
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 ...
Definition of the vpImage class member functions.
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.
virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE
void segmentPointCloud(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &point_cloud)
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace=0, const std::string &name="") 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
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace=0, const std::string &name="") VP_OVERRIDE
vpMatrix m_L_depthNormal
Interaction matrix.
vpRobust m_robust_depthNormal
Robust.
virtual void setDepthNormalSamplingStep(unsigned int stepX, unsigned int stepY)
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false) VP_OVERRIDE
vpMbtFaceDepthNormal::vpFeatureEstimationType m_depthNormalFeatureEstimationMethod
Method to estimate the desired features.
std::vector< vpMbtFaceDepthNormal * > m_depthNormalFaces
List of faces.
int m_depthNormalPclPlaneEstimationRansacMaxIter
PCL RANSAC maximum number of iterations.
unsigned int m_depthNormalSamplingStepY
Sampling step in y-direction.
virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE
double m_depthNormalPclPlaneEstimationRansacThreshold
PCL RANSAC threshold.
virtual void setDepthNormalPclPlaneEstimationRansacThreshold(double thresold)
virtual void resetTracker() VP_OVERRIDE
void addFace(vpMbtPolygon &polygon, bool alreadyClose)
bool m_depthNormalUseRobust
If true, use Tukey robust M-Estimator.
virtual void track(const vpImage< unsigned char > &) VP_OVERRIDE
void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose=false)
virtual std::vector< std::vector< double > > getFeaturesForDisplayDepthNormal()
vpColVector m_w_depthNormal
Robust weights.
virtual void init(const vpImage< unsigned char > &I) VP_OVERRIDE
vpColVector m_error_depthNormal
(s - s*)
vpColVector m_weightedError_depthNormal
Weighted error.
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE
virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE
std::vector< vpMbtFaceDepthNormal * > m_depthNormalListOfActiveFaces
List of current active (visible and with features extracted) faces.
virtual void loadConfigFile(const std::string &configFile, bool verbose=true) VP_OVERRIDE
virtual void initFaceFromCorners(vpMbtPolygon &polygon) VP_OVERRIDE
virtual void setCameraParameters(const vpCameraParameters &camera) VP_OVERRIDE
int m_depthNormalPclPlaneEstimationMethod
PCL plane estimation method.
virtual void setDepthNormalFaceCentroidMethod(const vpMbtFaceDepthNormal::vpFaceCentroidType &method)
virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE
virtual void setDepthNormalPclPlaneEstimationMethod(int method)
std::vector< vpColVector > m_depthNormalListOfDesiredFeatures
List of desired features.
virtual void computeVVSInit() VP_OVERRIDE
virtual void testTracking() VP_OVERRIDE
void setUseDepthNormalTracking(const std::string &name, const bool &useDepthNormalTracking)
void computeVisibility(unsigned int width, unsigned int height)
vpMbHiddenFaces< vpMbtPolygon > m_depthNormalHiddenFacesDisplay
Set of faces describing the object used only for display with scan line.
virtual void setDepthNormalFeatureEstimationMethod(const vpMbtFaceDepthNormal::vpFeatureEstimationType &method)
virtual void setDepthNormalPclPlaneEstimationRansacMaxIter(int maxIter)
virtual ~vpMbDepthNormalTracker() VP_OVERRIDE
std::vector< std::vector< double > > m_featuresToBeDisplayedDepthNormal
Display features.
unsigned int m_depthNormalSamplingStepX
Sampling step in x-direction.
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 global visibility tests.
virtual void computeVVSWeights(vpRobust &robust, const vpColVector &error, vpColVector &w)
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)
bool displayFeatures
If true, the features are displayed.
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &od_M_o=vpHomogeneousMatrix())
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 global 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)
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.
Manage depth normal features for a particular face.
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)
void addLine(vpPoint &p1, vpPoint &p2, vpMbHiddenFaces< vpMbtPolygon > *const faces, vpUniRand &rand_gen, int polygon=-1, std::string name="")
double m_distFarClip
Distance for near clipping.
vpMbHiddenFaces< vpMbtPolygon > * m_hiddenFace
Pointer to the list of faces.
std::vector< std::vector< double > > getFeaturesForDisplay(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double scale=0.05)
void setPclPlaneEstimationMethod(int method)
void setPclPlaneEstimationRansacThreshold(double threshold)
vpMbtPolygon * m_polygon
Polygon defining the face.
vpCameraParameters m_cam
Camera intrinsic parameters.
vpPlane m_planeObject
Plane equation described in the object frame.
unsigned int m_clippingFlag
Flags specifying which clipping to used.
void setTracked(bool tracked)
void setFeatureEstimationMethod(const vpFeatureEstimationType &method)
void setPclPlaneEstimationRansacMaxIter(int maxIter)
bool m_useScanLine
Scan line visibility.
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=nullptr)
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 setDepthNormalPclPlaneEstimationRansacMaxIter(int maxIter)
int getDepthNormalPclPlaneEstimationRansacMaxIter() const
unsigned int getDepthNormalSamplingStepX() const
void getCameraParameters(vpCameraParameters &cam) const
double getAngleAppear() const
unsigned int getDepthNormalSamplingStepY() const
void setDepthNormalFeatureEstimationMethod(const vpMbtFaceDepthNormal::vpFeatureEstimationType &method)
vpMbtFaceDepthNormal::vpFeatureEstimationType getDepthNormalFeatureEstimationMethod() const
void setDepthNormalPclPlaneEstimationMethod(int method)
void setDepthNormalSamplingStepX(unsigned int stepX)
void setAngleDisappear(const double &adisappear)
double getAngleDisappear() const
int getDepthNormalPclPlaneEstimationMethod() const
void setAngleAppear(const double &aappear)
double getDepthNormalPclPlaneEstimationRansacThreshold() const
void parse(const std::string &filename)
double getNearClippingDistance() const
bool hasNearClippingDistance() const
bool hasFarClippingDistance() const
void setDepthNormalPclPlaneEstimationRansacThreshold(double threshold)
void setCameraParameters(const vpCameraParameters &cam)
double getFarClippingDistance() const
bool getFovClipping() const
void setVerbose(bool verbose)
void setDepthNormalSamplingStepY(unsigned int stepY)
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)