39 #include <visp/vpMbKltTracker.h>
41 #ifdef VISP_HAVE_OPENCV
98 bool reInitialisation =
false;
102 #ifdef VISP_HAVE_OGRE
126 IplImage* mask = cvCreateImage(cvSize((
int)I.
getWidth(), (int)I.
getHeight()), IPL_DEPTH_8U, 1);
129 for (
unsigned int i = 0; i <
faces.
size(); i += 1){
130 if(
faces[i]->isVisible())
136 for (
unsigned int i = 0; i <
faces.
size(); i += 1){
137 if(
faces[i]->isVisible()){
142 cvReleaseImage(&mask);
155 cvReleaseImage(&
cur);
187 #ifdef VISP_HAVE_OGRE
199 std::vector<vpImagePoint>
202 std::vector<vpImagePoint> kltPoints;
220 std::map<int, vpImagePoint>
223 std::map<int, vpImagePoint> kltPoints;
258 for (
unsigned int i = 0; i <
faces.
size(); i += 1){
259 faces[i]->setCameraParameters(cam);
276 #ifndef VISP_HAVE_OGRE
278 std::cout <<
"WARNING: ViSP dosen't have Ogre3D, basic visibility test will be used. setOgreVisibilityTest() set to false." << std::endl;
296 bool reInitialisation =
false;
300 #ifdef VISP_HAVE_OGRE
307 if(reInitialisation){
308 std::cout <<
"WARNING: Visibility changed, must reinitialise to update pose" << std::endl;
322 CvPoint2D32f* initial_guess = NULL;
323 initial_guess = (CvPoint2D32f*)cvAlloc((
unsigned int)
tracker.
getMaxFeatures()*
sizeof(initial_guess[0]));
325 for (
unsigned int i = 0; i <
faces.
size(); i += 1){
326 if(
faces[i]->isVisible() &&
faces[i]->hasEnoughPoints()){
334 float invDc = 1.0f / plan.
getD();
338 vpGEMM(cdtc, Nc, -invDc, cdRc, 1.0, cdHc, VP_GEMM_B_T);
345 std::map<int, vpImagePoint>::const_iterator iter =
faces[i]->getCurrentPoints().begin();
346 for( ; iter !=
faces[i]->getCurrentPoints().end(); iter++){
348 cdp[0] = iter->second.get_j(); cdp[1] = iter->second.get_i(); cdp[2] = 1.0;
350 double p_mu_t_2 = cdp[0] * cdGc[2][0] + cdp[1] * cdGc[2][1] + cdGc[2][2];
352 if( fabs(p_mu_t_2) < std::numeric_limits<double>::epsilon()){
358 cdp[0] = (cdp[0] * cdGc[0][0] + cdp[1] * cdGc[0][1] + cdGc[0][2]) / p_mu_t_2;
359 cdp[1] = (cdp[0] * cdGc[1][0] + cdp[1] * cdGc[1][1] + cdGc[1][2]) / p_mu_t_2;
362 initial_guess[(
faces[i]->getCurrentPointsInd())[iter->first]].x = (
float)cdp[0];
363 initial_guess[(
faces[i]->getCurrentPointsInd())[iter->first]].y = (
float)cdp[1];
370 if(initial_guess) cvFree(&initial_guess);
371 initial_guess = NULL;
387 if( corners.size() > 2){
392 for(
unsigned int j = 0; j < corners.size(); j++) {
421 for (
unsigned int i = 0; i <
faces.
size(); i += 1){
422 if(
faces[i]->isVisible()){
425 if(
faces[i]->hasEnoughPoints()){
426 nbInfos +=
faces[i]->getNbPointsCur();
441 bool reInitialisation =
false;
443 unsigned int initialNumber = 0;
444 unsigned int currentNumber = 0;
445 unsigned int shift = 0;
446 for (
unsigned int i = 0; i <
faces.
size(); i += 1){
447 if(
faces[i]->isVisible()){
448 initialNumber +=
faces[i]->getInitialNumberPoint();
449 if(
faces[i]->hasEnoughPoints()){
452 shift += 2*
faces[i]->getNbPointsCur();
454 currentNumber +=
faces[i]->getNbPointsCur();
464 double value =
percentGood * (double)initialNumber;
465 if((
double)currentNumber < value){
467 reInitialisation =
true;
473 #ifdef VISP_HAVE_OGRE
509 double normRes_1 = -1;
510 unsigned int iter = 0;
513 J.
resize(2*nbInfos, 6, 0);
515 while( ((
int)((normRes - normRes_1)*1e8) != 0 ) && (iter<
maxIter) ){
517 unsigned int shift = 0;
518 for (
unsigned int i = 0; i <
faces.
size(); i += 1){
519 if(
faces[i]->isVisible() &&
faces[i]->hasEnoughPoints()){
524 faces[i]->computeInteractionMatrixAndResidu(subR, subJ);
526 std::cerr <<
"exception while tracking face " << i << std::endl;
530 shift += 2*
faces[i]->getNbPointsCur();
551 for (
unsigned int i = 0; i < static_cast<unsigned int>(R.
getRows()); i += 1){
552 w_true = w[i] * w[i];
558 for(
unsigned int i=0; i<static_cast<unsigned int>(R.
getRows()); i++){
559 for(
unsigned int j=0; j<6; j++){
593 unsigned int nbInfos;
594 unsigned int nbFaceUsed;
597 if(nbInfos < 4 || nbFaceUsed == 0){
672 #ifdef VISP_HAVE_XML2
687 std::cout <<
" *********** Parsing XML for MBT KLT Tracker ************ " << std::endl;
689 xmlp.
parse(configFile);
711 vpTRACE(
"You need the libXML2 to read the config file %s", configFile);
727 const vpColor& col ,
const unsigned int thickness,
const bool displayFullModel)
729 for (
unsigned int i = 0; i <
faces.
size(); i += 1){
730 if(displayFullModel ||
faces[i]->isVisible())
732 faces[i]->changeFrame(cMo);
733 std::vector<vpImagePoint> roi =
faces[i]->getRoi(cam);
734 for (
unsigned int j = 0; j <
faces[i]->getNbPoint(); j += 1){
737 ip2 = roi[(j+1)%
faces[i]->getNbPoint()];
742 faces[i]->displayPrimitive(I);
749 #ifdef VISP_HAVE_OGRE
767 const vpColor& col ,
const unsigned int thickness,
const bool displayFullModel)
769 for (
unsigned int i = 0; i <
faces.
size(); i += 1){
770 if(displayFullModel ||
faces[i]->isVisible())
772 faces[i]->changeFrame(cMo);
773 std::vector<vpImagePoint> roi =
faces[i]->getRoi(cam);
774 for (
unsigned int j = 0; j <
faces[i]->getNbPoint(); j += 1){
777 ip2 = roi[(j+1)%
faces[i]->getNbPoint()];
782 faces[i]->displayPrimitive(I);
789 #ifdef VISP_HAVE_OGRE
806 unsigned int nbTotalPoints = 0;
807 for (
unsigned int i = 0; i <
faces.
size(); i += 1){
808 if(
faces[i]->isVisible()){
809 nbTotalPoints +=
faces[i]->getNbPointsCur();
813 if(nbTotalPoints < 10){
814 std::cerr <<
"test tracking failed (too few points to realise a good tracking)." << std::endl;
816 "test tracking failed (too few points to realise a good tracking).");
820 #endif //VISP_HAVE_OPENCV
void setKltOpencv(const vpKltOpencv &t)
bool compute_interaction
If true, compute the interaction matrix at each iteration of the minimisation. Otherwise, compute it only on the first iteration.
virtual void track(const vpImage< unsigned char > &I)
Implementation of a polygon of the model containing points of interest. It is used by the model-based...
vpMatrix get_K_inverse() const
void setWindowName(const Ogre::String &n)
int getPyramidLevels() const
Get the number of pyramid levels.
unsigned int getMaskBorder() const
void setQuality(const double &q)
Definition of the vpMatrix class.
vpMatrix covarianceMatrix
Covariance matrix.
virtual ~vpMbKltTracker()
void setQuality(double input)
double getHarrisParam() const
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
void track(const IplImage *I)
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Compute the weights according a residue vector and a PsiFunction.
int getMaxFeatures() const
Get Max number of features.
void parse(const char *filename)
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
unsigned int maxIter
The maximum iteration of the virtual visual servoing stage.
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
IplImage * cur
Temporary OpenCV image for fast conversion.
double getHarrisFreeParameter() const
Get Harris free parameter.
void setIdentity()
Basic initialisation (identity)
Class to define colors available for display functionnalities.
double percentGood
Percentage of good points, according to the initial number, that must have the tracker.
vpHomogeneousMatrix cMo
The current pose.
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w)
unsigned int getBlockSize() const
void setUseHarris(const int input)
bool modelInitialised
Flag used to ensure that the CAD model is loaded before the initialisation.
void getCameraParameters(vpCameraParameters &_cam) const
void initOgre(vpCameraParameters _cam=vpCameraParameters())
error that can be emited by ViSP classes.
void computeJTR(const vpMatrix &J, const vpColVector &R, vpMatrix &JTR)
double getAngleAppear() const
double getAngleDisappear() const
unsigned int getMaxFeatures() const
void setInitialGuess(CvPoint2D32f **guess_pts)
void setPyramidLevels(const int input)
void setBlockSize(const int input)
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.
bool firstInitialisation
Flag to specify whether the init method is called the first or not (specific calls to realise in this...
static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b)
virtual void reinit(const vpImage< unsigned char > &I)
virtual void testTracking()
virtual void loadConfigFile(const std::string &configFile)
vpCameraParameters cam
The camera parameters.
The vpRotationMatrix considers the particular case of a rotation matrix.
vpHomogeneousMatrix ctTc0
The estimated displacement of the pose between the current instant and the initial position...
unsigned int setVisibleOgre(const vpImage< unsigned char > &_I, const vpCameraParameters &_cam, const vpHomogeneousMatrix &_cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
This class aims to compute the homography wrt.two images.
void addPoint(const unsigned int n, const vpPoint &P)
vpAROgre * getOgreContext()
void setPyramidLevels(const unsigned int &pL)
Parse an Xml file to extract configuration parameters of a Mbt Klt object.Data parser for the KLT mod...
unsigned int getWindowSize() const
Error that can be emited by the vpTracker class and its derivates.
void getFeature(int index, int &id, float &x, float &y) const
void setWindowSize(const int input)
double getQuality() const
Get the quality of the tracker.
void changeFrame(const vpHomogeneousMatrix &cMo)
void setWindowSize(const unsigned int &w)
void setTrackerId(int tid)
Definition of the vpSubColVector vpSubColVector class provides a mask on a vpColVector all properties...
unsigned int maskBorder
Erosion of the mask.
Generic class defining intrinsic camera parameters.
int getBlockSize() const
Get the block size.
bool useOgre
Use Ogre3d for visibility tests.
vpMbHiddenFaces< vpMbtKltPolygon > faces
Set of faces describing the object.
void extract(vpRotationMatrix &R) const
void setAngleDisappear(const double &adisappear)
void setHarrisParam(const double &hp)
bool firstTrack
First track() called.
void setMinDistance(const double &mD)
void addPolygon(PolygonType *p)
unsigned int setVisible(const vpHomogeneousMatrix &_cMo)
vpKltOpencv tracker
Points tracker.
vpColVector getNormal() const
static double rad(double deg)
double threshold_outlier
Threshold below which the weight associated to a point to consider this one as an outlier...
void diag(const vpColVector &A)
void preTracking(const vpImage< unsigned char > &I, unsigned int &nbInfos, unsigned int &nbFaceUsed)
void setAngleAppear(const double &aappear)
double lambda
The gain of the virtual visual servoing stage.
void setMaxFeatures(const unsigned int &mF)
void initTracking(const IplImage *I, const IplImage *mask=NULL)
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...
virtual void setOgreVisibilityTest(const bool &v)
std::map< int, vpImagePoint > getKltImagePointsWithId()
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented with OpenCV.
vpHomogeneousMatrix inverse() const
static vpHomogeneousMatrix direct(const vpColVector &v)
int getNbFeatures() const
Get the current number of features.
Contains an M-Estimator and various influence function.
virtual void initFaceFromCorners(const std::vector< vpPoint > &corners, const unsigned int indexFace=-1)
double angleAppears
Angle used to detect a face apparition.
void displayOgre(const vpHomogeneousMatrix &_cMo)
unsigned int getHeight() const
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
virtual void init(const vpImage< unsigned char > &I)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
std::vector< vpImagePoint > getKltImagePoints()
void setBlockSize(const unsigned int &bs)
This class defines the container for a plane geometrical structure.
double getMinDistance() const
Get Min Distance.
void setMaxFeatures(const int input)
double angleDisappears
Angle used to detect a face disparition.
void setThreshold(const double noise_threshold)
unsigned int getRows() const
Return the number of rows of the matrix.
double getMinDistance() const
virtual void setNbPoint(const unsigned int nb)
vpColVector & normalize()
normalise the vector
void setMinDistance(double input)
void setIteration(const unsigned int iter)
Set iteration.
void computeVVS(const unsigned int &nbInfos, vpColVector &w)
Class that consider the case of a translation vector.
void setMaskBorder(const unsigned int &mb)
vpHomogeneousMatrix c0Mo
Initial pose.
int getWindowSize() const
Get Max number of features.
unsigned int getPyramidLevels() const
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)
void setHarrisFreeParameter(double input)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
void resize(const unsigned int i, const bool flagNullify=true)
std::vector< PolygonType * > & getPolygon()
virtual void setIndex(const int i)