ViSP  2.7.0
vpMbEdgeTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpMbEdgeTracker.h 4122 2013-02-08 10:45:54Z ayol $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Make the complete tracking of an object by using its CAD model
36  *
37  * Authors:
38  * Nicolas Melchior
39  * Romain Tallonneau
40  * Eric Marchand
41  *
42  *****************************************************************************/
43 
49 #ifndef vpMbEdgeTracker_HH
50 #define vpMbEdgeTracker_HH
51 
52 #include <visp/vpPoint.h>
53 #include <visp/vpMbTracker.h>
54 #include <visp/vpMe.h>
55 #include <visp/vpMbtMeLine.h>
56 #include <visp/vpMbtDistanceLine.h>
57 #include <visp/vpMbtDistanceCylinder.h>
58 #include <visp/vpXmlParser.h>
59 
60 #include <iostream>
61 #include <fstream>
62 #include <vector>
63 #include <list>
64 
65 #if defined(VISP_HAVE_COIN)
66 //Inventor includes
67 #include <Inventor/nodes/SoSeparator.h>
68 #include <Inventor/VRMLnodes/SoVRMLIndexedFaceSet.h>
69 #include <Inventor/VRMLnodes/SoVRMLIndexedLineSet.h>
70 #include <Inventor/VRMLnodes/SoVRMLCoordinate.h>
71 #include <Inventor/actions/SoWriteAction.h>
72 #include <Inventor/actions/SoSearchAction.h>
73 #include <Inventor/misc/SoChildList.h>
74 #include <Inventor/actions/SoGetMatrixAction.h>
75 #include <Inventor/actions/SoGetPrimitiveCountAction.h>
76 #include <Inventor/actions/SoToVRML2Action.h>
77 #include <Inventor/VRMLnodes/SoVRMLGroup.h>
78 #include <Inventor/VRMLnodes/SoVRMLShape.h>
79 #endif
80 
81 #ifdef VISP_HAVE_OPENCV
82 # if VISP_HAVE_OPENCV_VERSION >= 0x020101
83 # include <opencv2/core/core.hpp>
84 # include <opencv2/imgproc/imgproc.hpp>
85 # include <opencv2/imgproc/imgproc_c.h>
86 # else
87 # include <cv.h>
88 # endif
89 #endif
90 
91 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
92 # include <visp/vpList.h>
93 #endif
94 
267 class VISP_EXPORT vpMbEdgeTracker: virtual public vpMbTracker
268 {
269  protected :
270 
277  double lambda;
278 
282  std::vector< std::list< vpMbtDistanceLine*> > lines;
284  std::vector< std::list< vpMbtDistanceCylinder*> > cylinders;
285 
287  unsigned int nline;
288 
290  unsigned int ncylinder;
291 
294 
297 
299  unsigned int nbvisiblepolygone;
300 
303 
305  std::vector<bool> scales;
306 
308  std::vector< const vpImage<unsigned char>* > Ipyramid;
309 
311  unsigned int scaleLevel;
312 
314  bool useOgre;
315 
317  double angleAppears;
318 
321 
322 public:
323 
324  vpMbEdgeTracker();
325  virtual ~vpMbEdgeTracker();
326 
327  void display(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
328  const vpColor& col , const unsigned int thickness=1, const bool displayFullModel = false);
329  void display(const vpImage<vpRGBa>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
330  const vpColor& col , const unsigned int thickness=1, const bool displayFullModel = false);
331 
333  virtual inline double getAngleAppear() { return angleAppears; }
334 
336  virtual inline double getAngleDisappear() { return angleDisappears; }
337 
340  double getFirstThreshold() { return percentageGdPt;}
341 
342  void getLline(std::list<vpMbtDistanceLine *>& linesList, const unsigned int level = 0);
343  void getLcylinder(std::list<vpMbtDistanceCylinder *>& cylindersList, const unsigned int level = 0);
344 
350  inline void getMovingEdge(vpMe &me ) { me = this->me;}
351 
352  unsigned int getNbPoints(const unsigned int level=0);
353  unsigned int getNbPolygon();
354  vpMbtPolygon* getPolygon(const unsigned int index);
355 
361  std::vector<bool> getScales() const {return scales;}
362 
363  void loadConfigFile(const std::string &configFile);
364  void loadConfigFile(const char* configFile);
365  void loadModel(const std::string &cad_name);
366  void loadModel(const char* cad_name);
367 
368  void reInitModel(const vpImage<unsigned char>& I, const char* cad_name, const vpHomogeneousMatrix& cMo);
369  void resetTracker();
370 
383  virtual inline void setAngleAppear(const double &a) { angleAppears = a; }
384 
397  virtual inline void setAngleDisappear(const double &a) { angleDisappears = a; }
398 
404  virtual void setCameraParameters(const vpCameraParameters& cam) {
405  this->cam = cam;
406 
407  for (unsigned int i = 0; i < scales.size(); i += 1){
408  if(scales[i]){
409  for(std::list<vpMbtDistanceLine*>::const_iterator it=lines[i].begin(); it!=lines[i].end(); ++it){
410  (*it)->setCameraParameters(cam);
411  }
412 
413  for(std::list<vpMbtDistanceCylinder*>::const_iterator it=cylinders[i].begin(); it!=cylinders[i].end(); ++it){
414  (*it)->setCameraParameters(cam);
415  }
416  }
417  }
418  }
419 
430  void setDisplayMovingEdges(const bool displayMe) {displayFeatures = displayMe;}
431 
441  void setFirstThreshold(const double threshold1) {percentageGdPt = threshold1;}
442 
448  inline void setLambda(const double lambda) {this->lambda = lambda;}
449 
450  void setMovingEdge(const vpMe &me);
451 
452  virtual void setOgreVisibilityTest(const bool &v);
453 
454  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix& cdMo);
455 
456  void setScales(const std::vector<bool>& _scales);
457 
458  void track(const vpImage<unsigned char> &I);
459 
460 protected:
461  void addCylinder(const vpPoint &P1, const vpPoint &P2, const double r, const std::string& name = "");
462  void addLine(vpPoint &p1, vpPoint &p2, int polygone = -1, std::string name = "");
463  void addPolygon(vpMbtPolygon &p) ;
464  void cleanPyramid(std::vector<const vpImage<unsigned char>* >& _pyramid);
465  void computeVVS(const vpImage<unsigned char>& _I);
466  void downScale(const unsigned int _scale);
467  void init(const vpImage<unsigned char>& I);
468  virtual void initCylinder(const vpPoint& _p1, const vpPoint _p2, const double _radius, const unsigned int _indexCylinder=0);
469  virtual void initFaceFromCorners(const std::vector<vpPoint>& _corners, const unsigned int _indexFace = -1);
470  void initMovingEdge(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &_cMo) ;
471  void initPyramid(const vpImage<unsigned char>& _I, std::vector<const vpImage<unsigned char>* >& _pyramid);
472  void reInitLevel(const unsigned int _lvl);
473  void reinitMovingEdge(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &_cMo);
474  void removeCylinder(const std::string& name);
475  void removeLine(const std::string& name);
476  void testTracking();
477  void trackMovingEdge(const vpImage<unsigned char> &I) ;
478  void updateMovingEdge(const vpImage<unsigned char> &I) ;
479  void upScale(const unsigned int _scale);
480  void visibleFace(const vpHomogeneousMatrix &_cMo, bool &newvisibleline) ;
481  void visibleFace(const vpImage<unsigned char> &_I, const vpHomogeneousMatrix &_cMo, bool &newvisibleline) ;
482 };
483 
484 #endif
485 
std::vector< bool > getScales() const
void setDisplayMovingEdges(const bool displayMe)
unsigned int ncylinder
Index of the cylinder to add, and total number of polygon extracted so far.
void getMovingEdge(vpMe &me)
virtual void track(const vpImage< unsigned char > &I)=0
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
virtual void setAngleAppear(const double &a)
virtual void initFaceFromCorners(const std::vector< vpPoint > &corners, const unsigned int indexFace=-1)=0
double lambda
The gain of the virtual visual servoing stage.
unsigned int scaleLevel
Current scale level used. This attribute must not be modified outsied of the downScale() and upScale(...
virtual void setAngleDisappear(const double &a)
Class to define colors available for display functionnalities.
Definition: vpColor.h:123
Contains predetermined masks for sites and holds moving edges tracking parameters.
Definition: vpMe.h:70
Make the complete tracking of an object by using its CAD model.
std::vector< const vpImage< unsigned char > * > Ipyramid
Pyramid of image associated to the current image. This pyramid is compted in the init() and in the tr...
double angleDisappears
Angle used to detect a face disparition.
vpMe me
The moving edges parameters.
virtual void resetTracker()=0
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 setFirstThreshold(const double threshold1)
bool useOgre
Use Ogre3d for visibility tests.
Class that defines what is a point.
Definition: vpPoint.h:65
vpCameraParameters cam
The camera parameters.
Definition: vpMbTracker.h:106
virtual void init(const vpImage< unsigned char > &I)=0
int index_polygon
Index of the polygon to add, and total number of polygon extracted so far. Cannot be unsigned because...
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)=0
std::vector< bool > scales
Vector of scale level to use for the multi-scale tracking.
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:67
virtual double getAngleAppear()
virtual double getAngleDisappear()
Generic class defining intrinsic camera parameters.
virtual void loadModel(const std::string &modelFile)
Main methods for a model-based tracker.
Definition: vpMbTracker.h:102
double percentageGdPt
Percentage of good points over total number of points below which tracking is supposed to have failed...
virtual void initCylinder(const vpPoint &p1, const vpPoint p2, const double radius, const unsigned int indexCylinder=0)=0
double angleAppears
Angle used to detect a face apparition.
virtual void loadConfigFile(const std::string &configFile)=0
void setLambda(const double lambda)
double getFirstThreshold()
vpMbHiddenFaces< vpMbtPolygon > & getFaces()
std::vector< std::list< vpMbtDistanceCylinder * > > cylinders
Vector of the tracked cylinders.
virtual void testTracking()=0
unsigned int nbvisiblepolygone
Number of polygon (face) currently visible.
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)=0
virtual void setCameraParameters(const vpCameraParameters &cam)
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
unsigned int nline
Index of the polygon to add, and total number of polygon extracted so far.