42 #include <visp/vpMbEdgeKltTracker.h>
44 #ifdef VISP_HAVE_OPENCV
47 : compute_interaction(true), lambda(0.8), thresholdKLT(2.), thresholdMBT(2.), maxIter(200)
90 unsigned int i = (
unsigned int)
scales.size();
141 unsigned int i = (
unsigned int)
scales.size();
176 unsigned int nbrow = 0;
177 for(std::list<vpMbtDistanceLine*>::iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
183 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
276 #ifdef VISP_HAVE_XML2
295 std::cout <<
" *********** Parsing XML for Mb Edge Tracker ************ " << std::endl;
296 xmlp.
parse(configFile);
324 xmlp.
getMe(meParser);
336 vpTRACE(
"You need the libXML2 to read the config file %s", configFile);
361 const unsigned int lvl)
371 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
379 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
426 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
430 std::list<vpMeSite>::iterator itListLine;
433 for (
unsigned int i=0 ; i < l->
nbFeature ; i++){
460 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
463 std::list<vpMeSite>::iterator itListCyl1;
464 std::list<vpMeSite>::iterator itListCyl2;
495 for(
unsigned int i=cy->
nbFeaturel1 ; i < cy->nbFeature ; i++){
537 if(nbrow < 4 && nbInfos < 4){
545 double residu_1 = -1;
546 unsigned int iter = 0;
562 J_klt.
resize(2*nbInfos,6);
568 vpRobust robust_mbt(0), robust_klt(0);
573 double factorMBT = 1.0;
574 double factorKLT = 1.0;
582 double residuMBT = 0;
583 double residuKLT = 0;
585 while( ((
int)((residu - residu_1)*1e8) !=0 ) && (iter<
maxIter) ){
593 unsigned int shift = 0;
606 w.
resize(nbrow + 2*nbInfos);
615 robust_klt.
resize(2*nbInfos);
617 w_true.
resize(nbrow + 2*nbInfos);
623 for(
unsigned int i = 0; i < R_mbt.
getRows(); i++)
624 residuMBT += fabs(R_mbt[i]);
627 robust_mbt.setIteration(iter);
636 for(
unsigned int i = 0; i < R_klt.
getRows(); i++)
637 residuKLT += fabs(R_klt[i]);
648 unsigned int cpt = 0;
649 while(cpt< (nbrow+2*nbInfos)){
650 if(cpt<(
unsigned)nbrow){
651 w[cpt] = ((w_mbt[cpt] * factor[cpt]) * factorMBT) ;
654 w[cpt] = (w_klt[cpt-nbrow] * factorKLT);
667 for (
unsigned int i = 0; i < static_cast<unsigned int>(R->
getRows()); i++){
671 w_true[i] = w[i]*w[i];
674 for (
unsigned int j = 0; j < 6; j += 1){
680 residu = sqrt(num/den);
711 unsigned int nbInfos;
712 unsigned int nbFaceUsed;
745 unsigned int i = (
unsigned int)
scales.size();
781 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
787 int index = *itindex;
798 std::list<vpMeSite>::const_iterator itListLine;
802 for (
unsigned int i=0 ; i < l->
nbFeature ; i++){
811 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
816 std::list<vpMeSite>::const_iterator itCyl1;
817 std::list<vpMeSite>::const_iterator itCyl2;
823 for(
unsigned int i=0 ; i < cy->
nbFeature ; i++){
826 if(i<cy->nbFeaturel1) {
851 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
854 for (
unsigned int i=0 ; i < l->
nbFeature ; i++){
855 for (
unsigned int j=0; j < 6 ; j++){
856 L[n+i][j] = l->
L[i][j];
857 error[n+i] = l->
error[i];
863 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
866 for(
unsigned int i=0 ; i < cy->
nbFeature ; i++){
867 for(
unsigned int j=0; j < 6 ; j++){
868 L[n+i][j] = cy->
L[i][j];
869 error[n+i] = cy->
error[i];
931 const vpColor& col,
const unsigned int thickness,
const bool displayFullModel)
935 for (
unsigned int i = 0; i <
scales.size(); i += 1){
939 l->
display(I,cMo_, camera, col, thickness, displayFullModel);
943 (*it)->display(I, cMo_, camera, col, thickness);
956 #ifdef VISP_HAVE_OGRE
974 const vpColor& col ,
const unsigned int thickness,
const bool displayFullModel)
978 for (
unsigned int i = 0; i <
scales.size(); i += 1){
982 l->
display(I,cMo_, camera, col, thickness, displayFullModel);
986 (*it)->display(I, cMo_, camera, col, thickness);
999 #ifdef VISP_HAVE_OGRE
1005 #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)
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)
vpMatrix covarianceMatrix
Covariance matrix.
void setMovingEdge(const vpMe &me)
void setQuality(double input)
double getHarrisParam() const
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
virtual void initCylinder(const vpPoint &, const vpPoint &, const double, const unsigned int)
Parse an Xml file to extract configuration parameters of a mbtConfig object.Data parser for the model...
void upScale(const unsigned int _scale)
void parse(const char *filename)
unsigned int clippingFlag
Flags specifying which clipping to used.
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Compute the weights according a residue vector and a PsiFunction.
bool isAppearing(const unsigned int i)
void getCameraParameters(vpCameraParameters &_cam) const
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.
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
Class to define colors available for display functionnalities.
vpHomogeneousMatrix cMo
The current pose.
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w)
unsigned int getBlockSize() const
void displayMovingEdges(const vpImage< unsigned char > &I)
double getNearClippingDistance() const
double thresholdKLT
The threshold used in the robust estimation of KLT.
void getMe(vpMe &_ecm) const
error that can be emited by ViSP classes.
void computeJTR(const vpMatrix &J, const vpColVector &R, vpMatrix &JTR)
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.
void setPyramidLevels(const int input)
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...
void setBlockSize(const int input)
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, const double radius, const unsigned int indexCylinder=0)
virtual void setCameraParameters(const vpCameraParameters &camera)
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.
double angleDisappears
Angle used to detect a face disappearance.
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()
static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b)
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)
bool hasNearClippingDistance() const
Class that defines what is a point.
vpMatrix L
The interaction matrix.
vpMeSiteState getState() const
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)
vpCameraParameters cam
The camera parameters.
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 setPyramidLevels(const unsigned int &pL)
std::vector< bool > scales
Vector of scale level to use for the multi-scale tracking.
unsigned int getWindowSize() const
Error that can be emited by the vpTracker class and its derivates.
double getAngleDisappear() const
void initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &_cMo)
void setWindowSize(const int input)
void setWindowSize(const unsigned int &w)
static double sqr(double x)
void setAngleDisappear(const double &adisappear)
vpColVector error
The error vector.
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
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.
virtual void loadModel(const std::string &modelFile)
void initPyramid(const vpImage< unsigned char > &_I, std::vector< const vpImage< unsigned char > * > &_pyramid)
void cleanPyramid(std::vector< const vpImage< unsigned char > * > &_pyramid)
bool useOgre
Use Ogre3d for visibility tests.
vpMbHiddenFaces< vpMbtKltPolygon > faces
Set of faces describing the object.
virtual void initFaceFromCorners(const std::vector< vpPoint > &corners, const unsigned int indexFace=-1)
vpMbtMeLine * meline1
The moving edge containers (first line of the cylinder)
double angleAppears
Angle used to detect a face appearance.
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)
bool firstTrack
First track() called.
virtual void initFaceFromCorners(const std::vector< vpPoint > &_corners, const unsigned int _indexFace=-1)
std::list< vpMeSite > & getMeList()
void setMinDistance(const double &mD)
void loadConfigFile(const char *configFile)
void setCameraParameters(const vpCameraParameters &_cam)
vpKltOpencv tracker
Points tracker.
void stackMatrices(const vpMatrix &A)
void setState(const vpMeSiteState &flag)
void reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &_cMo)
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)
unsigned int size() const
unsigned int maxIter
The maximum iteration of the virtual visual servoing stage.
void setMaxFeatures(const unsigned int &mF)
bool closeToImageBorder(const vpImage< unsigned char > &I, const unsigned int threshold)
double getQuality() const
static double deg(double rad)
bool displayFeatures
If true, the features are displayed.
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)
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.
static vpHomogeneousMatrix direct(const vpColVector &v)
bool isVisible(const unsigned int i)
Contains an M-Estimator and various influence function.
virtual void initFaceFromCorners(const std::vector< vpPoint > &corners, const unsigned int indexFace=-1)
unsigned int nbvisiblepolygone
Number of polygon (face) currently visible.
double angleAppears
Angle used to detect a face appearance.
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.
virtual void setClipping(const unsigned int &flags)
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)
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
void setBlockSize(const unsigned int &bs)
void trackMovingEdge(const vpImage< unsigned char > &I)
void displayOgre(const vpHomogeneousMatrix &cMo)
unsigned int clippingFlag
Flags specifying which clipping to used.
double getAngleAppear() const
virtual void setClipping(const unsigned int &flags)
void setMaxFeatures(const int input)
unsigned int nbFeaturel2
The number of moving edges on line 2.
double angleDisappears
Angle used to detect a face disappearance.
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 setMinDistance(double input)
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)
void setMaskBorder(const unsigned int &mb)
vpMbtMeLine * meline
The moving edge container.
unsigned int getPyramidLevels() const
virtual void loadModel(const std::string &modelFile)
double thresholdMBT
The threshold used in the robust estimation of MBT.
void setHarrisFreeParameter(double input)
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)
void computeVVS(const vpImage< unsigned char > &I, const unsigned int &nbInfos, vpColVector &w_mbt, vpColVector &w_klt, const unsigned int lvl=0)