44 #include <visp/vpDebug.h>
45 #include <visp/vpMbEdgeKltTracker.h>
46 #include <visp/vpTrackingException.h>
47 #include <visp/vpVelocityTwistMatrix.h>
49 #if (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
52 : compute_interaction(true), lambda(0.8), thresholdKLT(2.), thresholdMBT(2.), maxIter(200)
87 unsigned int i = (
unsigned int)
scales.size();
117 if((*it)->meline != NULL){
118 delete (*it)->meline;
119 (*it)->meline = NULL;
127 if((*it)->meline1 != NULL){
128 delete (*it)->meline1;
129 (*it)->meline1 = NULL;
131 if((*it)->meline2 != NULL){
132 delete (*it)->meline2;
133 (*it)->meline2 = NULL;
141 if((*it)->meEllipse != NULL){
142 delete (*it)->meEllipse;
143 (*it)->meEllipse = NULL;
150 unsigned int i = (
unsigned int)
scales.size();
185 unsigned int nbrow = 0;
186 for(std::list<vpMbtDistanceLine*>::iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
192 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
198 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[lvl].begin(); it!=
circles[lvl].end(); ++it){
291 #ifdef VISP_HAVE_XML2
310 std::cout <<
" *********** Parsing XML for Mb Edge Tracker ************ " << std::endl;
311 xmlp.
parse(configFile);
336 xmlp.
getMe(meParser);
348 vpTRACE(
"You need the libXML2 to read the config file %s", configFile);
357 const unsigned int lvl)
367 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
375 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
382 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[lvl].begin(); it!=
circles[lvl].end(); ++it){
420 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
424 std::list<vpMeSite>::iterator itListLine;
427 for (
unsigned int i=0 ; i < l->
nbFeature ; i++){
454 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
457 std::list<vpMeSite>::iterator itListCyl1;
458 std::list<vpMeSite>::iterator itListCyl2;
460 itListCyl1 = cy->
meline1->getMeList().begin();
461 itListCyl2 = cy->
meline2->getMeList().begin();
489 for(
unsigned int i=cy->
nbFeaturel1 ; i < cy->nbFeature ; i++){
520 std::list<vpMeSite>::iterator itListCir;
523 itListCir = ci->
meEllipse->getMeList().begin();
527 for(
unsigned int i=0 ; i < ci->
nbFeature ; i++){
569 if(nbrow < 4 && nbInfos < 4){
577 double residu_1 = -1;
578 unsigned int iter = 0;
595 L_klt.
resize(2*nbInfos,6);
601 vpRobust robust_mbt(0), robust_klt(0);
606 double factorMBT = 1.0;
607 double factorKLT = 1.0;
620 double residuMBT = 0;
621 double residuKLT = 0;
625 while( ((
int)((residu - residu_1)*1e8) !=0 ) && (iter<
maxIter) ){
633 unsigned int shift = 0;
661 robust_klt.
resize(2*nbInfos);
664 w_true.
resize(nbrow + 2*nbInfos);
670 for(
unsigned int i = 0; i < R_mbt.
getRows(); i++)
671 residuMBT += fabs(R_mbt[i]);
674 robust_mbt.setIteration(iter);
683 for(
unsigned int i = 0; i < R_klt.
getRows(); i++)
684 residuKLT += fabs(R_klt[i]);
695 unsigned int cpt = 0;
696 while(cpt< (nbrow+2*nbInfos)){
697 if(cpt<(
unsigned)nbrow){
698 m_w[cpt] = ((w_mbt[cpt] * factor[cpt]) * factorMBT) ;
701 m_w[cpt] = (w_klt[cpt-nbrow] * factorKLT);
711 LVJ_true = ((*L)*cVo*
oJo);
719 for (
unsigned int i = 0; i < static_cast<unsigned int>(R->
getRows()); i++){
726 for (
unsigned int j = 0; j < 6; j += 1){
727 (*L)[i][j] *=
m_w[i];
732 residu = sqrt(num/den);
784 unsigned int nbInfos = 0;
785 unsigned int nbFaceUsed = 0;
810 unsigned int i = (
unsigned int)
scales.size();
847 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
853 int index = *itindex;
864 std::list<vpMeSite>::const_iterator itListLine;
866 itListLine = l->
meline->getMeList().begin();
868 for (
unsigned int i=0 ; i < l->
nbFeature ; i++){
877 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
882 std::list<vpMeSite>::const_iterator itCyl1;
883 std::list<vpMeSite>::const_iterator itCyl2;
885 itCyl1 = cy->
meline1->getMeList().begin();
886 itCyl2 = cy->
meline2->getMeList().begin();
889 for(
unsigned int i=0 ; i < cy->
nbFeature ; i++){
892 if(i<cy->nbFeaturel1) {
911 std::list<vpMeSite>::const_iterator itCir;
913 itCir = ci->
meEllipse->getMeList().begin();
916 for(
unsigned int i=0 ; i < ci->
nbFeature ; i++){
938 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
941 for (
unsigned int i=0 ; i < l->
nbFeature ; i++){
942 for (
unsigned int j=0; j < 6 ; j++){
943 L[n+i][j] = l->
L[i][j];
944 error[n+i] = l->
error[i];
950 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
953 for(
unsigned int i=0 ; i < cy->
nbFeature ; i++){
954 for(
unsigned int j=0; j < 6 ; j++){
955 L[n+i][j] = cy->
L[i][j];
956 error[n+i] = cy->
error[i];
964 for(
unsigned int i=0 ; i < ci->
nbFeature ; i++){
965 for(
unsigned int j=0; j < 6 ; j++){
966 L[n+i][j] = ci->
L[i][j];
967 error[n+i] = ci->
error[i];
1025 const int idFace,
const std::string &name)
1042 const std::string &name)
1059 const vpColor& col,
const unsigned int thickness,
const bool displayFullModel)
1061 for (
unsigned int i = 0; i <
scales.size(); i += 1){
1064 (*it)->display(I,cMo_, camera, col, thickness, displayFullModel);
1068 (*it)->display(I, cMo_, camera, col, thickness, displayFullModel);
1072 (*it)->display(I, cMo_, camera, col, thickness, displayFullModel);
1080 for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=
kltPolygons.begin(); it!=
kltPolygons.end(); ++it){
1087 #ifdef VISP_HAVE_OGRE
1105 const vpColor& col ,
const unsigned int thickness,
const bool displayFullModel)
1107 for (
unsigned int i = 0; i <
scales.size(); i += 1){
1110 (*it)->display(I,cMo_, camera, col, thickness, displayFullModel);
1114 (*it)->display(I, cMo_, camera, col, thickness, displayFullModel);
1118 (*it)->display(I, cMo_, camera, col, thickness, displayFullModel);
1126 for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=
kltPolygons.begin(); it!=
kltPolygons.end(); ++it){
1133 #ifdef VISP_HAVE_OGRE
1172 #endif //VISP_HAVE_OPENCV
void setWindowName(const Ogre::String &n)
void trackSecondLoop(const vpImage< unsigned char > &I, vpMatrix &L, vpColVector &_error, vpHomogeneousMatrix &cMo, const unsigned int lvl=0)
virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, const double r, const int idFace=0, const std::string &name="")
std::list< vpMbtDistanceKltPoints * > kltPolygons
Vector of the cylinders used here only to display the full model.
double lambda
The gain of the virtual visual servoing stage.
unsigned int getMaskBorder() const
void setQuality(const double &q)
void postTrackingMbt(vpColVector &w, const unsigned int level=0)
Definition of the vpMatrix class.
void displayMovingEdges(const vpImage< unsigned char > &I)
void setMovingEdge(const vpMe &me)
double getHarrisParam() const
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
Parse an Xml file to extract configuration parameters of a mbtConfig object.Data parser for the model...
unsigned int nbFeature
The number of moving edges.
void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
void upScale(const unsigned int _scale)
void parse(const char *filename)
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Compute the weights according a residue vector and a PsiFunction.
void setHarrisFreeParameter(double harris_k)
bool isAppearing(const unsigned int i)
void getCameraParameters(vpCameraParameters &_cam) const
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
bool Reinit
Indicates if the line has to be reinitialized.
void setMeanWeight2(const double wmean)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
unsigned int scaleLevel
Current scale level used. This attribute must not be modified outside of the downScale() and upScale(...
std::list< int > Lindex_polygon
Index of the faces which contain the line.
vpMatrix L
The interaction matrix.
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
std::vector< std::list< vpMbtDistanceCircle * > > circles
Vector of the tracked circles.
Class to define colors available for display functionnalities.
void setMaxFeatures(const int maxCount)
vpHomogeneousMatrix cMo
The current pose.
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w)
unsigned int getBlockSize() const
bool hasEnoughPoints() const
void displayMovingEdges(const vpImage< unsigned char > &I)
double getNearClippingDistance() const
double thresholdKLT
The threshold used in the robust estimation of KLT.
vpColVector error
The error vector.
void getMe(vpMe &_ecm) const
void setMinDistance(double minDistance)
error that can be emited by ViSP classes.
void computeJTR(const vpMatrix &J, const vpColVector &R, vpMatrix &JTR)
vpMbtMeEllipse * meEllipse
Polygon describing the circle bbox.
Manage a cylinder used in the model-based tracker.
Contains predetermined masks for sites and holds moving edges tracking parameters.
unsigned int getMaxFeatures() const
Manage the line of a polygon used in the model-based tracker.
unsigned int nbFeature
The number of moving edges.
virtual void setClipping(const unsigned int &flags)
std::vector< const vpImage< unsigned char > * > Ipyramid
Pyramid of image associated to the current image. This pyramid is computed in the init() and in the t...
bool useOgre
Use Ogre3d for visibility tests.
virtual void setCameraParameters(const vpCameraParameters &camera)
void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
Definition of the vpSubMatrix vpSubMatrix class provides a mask on a vpMatrix all properties of vpMat...
bool computeCovariance
Flag used to specify if the covariance matrix has to be computed or not.
vpMe me
The moving edges parameters.
void updateMovingEdge(const vpImage< unsigned char > &I)
std::vector< std::list< vpMbtDistanceLine * > > lines
Vector of list of all the lines tracked (each line is linked to a list of moving edges). Each element of the vector is for a scale (element 0 = level 0 = no subsampling).
void initInteractionMatrixError()
virtual void reinit(const vpImage< unsigned char > &I)
virtual void setFarClippingDistance(const double &dist)
virtual ~vpMbEdgeKltTracker()
unsigned int nbFeature
The number of moving edges.
void downScale(const unsigned int _scale)
Implementation of a polygon of the model containing points of interest. It is used by the model-based...
bool hasNearClippingDistance() const
Class that defines what is a point.
vpMatrix L
The interaction matrix.
vpMeSiteState getState() const
vpCameraParameters cam
The camera parameters.
void setQuality(double qualityLevel)
virtual void init(const vpImage< unsigned char > &I)
vpHomogeneousMatrix ctTc0
The estimated displacement of the pose between the current instant and the initial position...
double getFarClippingDistance() const
unsigned int nbFeaturel1
The number of moving edges on line 1.
bool hasFarClippingDistance() const
This class aims to compute the homography wrt.two images.
vpAROgre * getOgreContext()
void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
void setPyramidLevels(const unsigned int &pL)
Manage a circle used in the model-based tracker.
vpMatrix oJo
The Degrees of Freedom to estimate.
std::vector< bool > scales
Vector of scale level to use for the multi-scale tracking.
bool Reinit
Indicates if the circle has to be reinitialized.
unsigned int getWindowSize() const
Error that can be emited by the vpTracker class and its derivates.
double getAngleDisappear() const
Implementation of a polygon of the model used by the model-based tracker.
void initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &_cMo)
void displayPrimitive(const vpImage< unsigned char > &_I)
void setWindowSize(const unsigned int &w)
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double sqr(double x)
void setAngleDisappear(const double &adisappear)
vpColVector error
The error vector.
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
vpColVector m_error
Error s-s*.
virtual void track(const vpImage< unsigned char > &I)
Definition of the vpSubColVector vpSubColVector class provides a mask on a vpColVector all properties...
unsigned int maskBorder
Erosion of the mask.
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)
Generic class defining intrinsic camera parameters.
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo)
void initPyramid(const vpImage< unsigned char > &_I, std::vector< const vpImage< unsigned char > * > &_pyramid)
void cleanPyramid(std::vector< const vpImage< unsigned char > * > &_pyramid)
vpMbtMeLine * meline1
The moving edge containers (first line of the cylinder)
bool compute_interaction
If true, compute the interaction matrix at each iteration of the minimization. Otherwise, compute it only on the first iteration.
void setHarrisParam(const double &hp)
Class that consider the particular case of twist transformation matrix that allows to transform a vel...
void setMinDistance(const double &mD)
void loadConfigFile(const char *configFile)
void setCameraParameters(const vpCameraParameters &_cam)
double angleAppears
Angle used to detect a face appearance.
vpKltOpencv tracker
Points tracker.
virtual bool isVisible(const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo=false, const vpCameraParameters &cam=vpCameraParameters(), const vpImage< unsigned char > &I=vpImage< unsigned char >())
void stackMatrices(const vpMatrix &A)
void setPyramidLevels(const int pyrMaxLevel)
void setState(const vpMeSiteState &flag)
void reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &_cMo)
void displayMovingEdges(const vpImage< unsigned char > &I)
static double rad(double deg)
void setMeanWeight1(const double wmean)
virtual void setCameraParameters(const vpCameraParameters &cam)
virtual void setMaxIter(const unsigned int max)
void diag(const vpColVector &A)
void preTracking(const vpImage< unsigned char > &I, unsigned int &nbInfos, unsigned int &nbFaceUsed)
void computeCovarianceMatrix(const vpHomogeneousMatrix &cMoPrev, const vpColVector &deltaS, const vpMatrix &Ls, const vpMatrix &W)
virtual void initFaceFromLines(vpMbtPolygon &polygon)
unsigned int maxIter
The maximum iteration of the virtual visual servoing stage.
void setMaxFeatures(const unsigned int &mF)
void computeHomography(const vpHomogeneousMatrix &_cTc0, vpHomography &cHc0)
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, const double radius, const int idFace=0, const std::string &name="")
bool closeToImageBorder(const vpImage< unsigned char > &I, const unsigned int threshold)
void setWindowSize(const int winSize)
double getQuality() const
static double deg(double rad)
void initInteractionMatrixError()
bool displayFeatures
If true, the features are displayed.
virtual void initCylinder(const vpPoint &, const vpPoint &, const double r, const int idFace, const std::string &name="")
void setCameraParameters(const vpCameraParameters &cam)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
std::vector< std::list< vpMbtDistanceCylinder * > > cylinders
Vector of the tracked cylinders.
void setAngleAppear(const double &aappear)
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo)
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, const double radius, const int idFace=0, const std::string &name="")
unsigned int initMbtTracking(const unsigned int level=0)
vpHomogeneousMatrix inverse() const
unsigned int trackFirstLoop(const vpImage< unsigned char > &I, vpColVector &factor, const unsigned int lvl=0)
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
void setBlockSize(const int blockSize)
static vpHomogeneousMatrix direct(const vpColVector &v)
void setMeanWeight(const double _wmean)
Contains an M-Estimator and various influence function.
double angleDisappears
Angle used to detect a face disappearance.
virtual void initFaceFromLines(vpMbtPolygon &polygon)
vpMbtPolygon * polygon
Pointer to the polygon that define a face.
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w_mbt, vpColVector &w_klt, const unsigned int lvl=0)
void setMeanWeight(const double w_mean)
vpColVector error
The error vector.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
bool Reinit
Indicates if the line has to be reinitialized.
virtual void init(const vpImage< unsigned char > &I)
void setBlockSize(const unsigned int &bs)
unsigned int clippingFlag
Flags specifying which clipping to used.
void trackMovingEdge(const vpImage< unsigned char > &I)
void displayOgre(const vpHomogeneousMatrix &cMo)
double getAngleAppear() const
unsigned int nbFeaturel2
The number of moving edges on line 2.
virtual void initFaceFromLines(vpMbtPolygon &polygon)
unsigned int getCurrentNumberPoints() const
void setThreshold(const double noise_threshold)
unsigned int getRows() const
Return the number of rows of the matrix.
double getMinDistance() const
void resize(unsigned int n_data)
Resize containers for sort methods.
vpMbtMeLine * meline2
The moving edge containers (second line of the cylinder)
bool getFovClipping() const
void setIteration(const unsigned int iter)
Set iteration.
vpMatrix L
The interaction matrix.
void computeVVS(const unsigned int &nbInfos, vpColVector &w)
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo, const vpImage< unsigned char > &I)
void initInteractionMatrixError()
void setMovingEdge(const vpMe &_ecm)
bool isoJoIdentity
Boolean to know if oJo is identity (for fast computation)
void setMaskBorder(const unsigned int &mb)
void computeInteractionMatrixAndResidu(vpColVector &_R, vpMatrix &_J)
vpMbtMeLine * meline
The moving edge container.
unsigned int getPyramidLevels() const
double thresholdMBT
The threshold used in the robust estimation of MBT.
virtual void setNearClippingDistance(const double &dist)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
void resize(const unsigned int i, const bool flagNullify=true)
vpColVector m_w
Weights used in the robust scheme.
void computeVVS(const vpImage< unsigned char > &I, const unsigned int &nbInfos, vpColVector &w_mbt, vpColVector &w_klt, const unsigned int lvl=0)