ViSP  2.6.2
vpMbEdgeTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpMbEdgeTracker.h 2807 2010-09-14 10:14:54Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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 
243 class VISP_EXPORT vpMbEdgeTracker: public vpMbTracker
244 {
245  protected :
246 
253  double lambda;
254 
258  std::vector< std::list< vpMbtDistanceLine*> > lines;
260  std::vector< std::list< vpMbtDistanceCylinder*> > cylinders;
261 
263  unsigned int nline;
264 
266  unsigned int ncylinder;
267 
271  vpMbtHiddenFaces faces;
273  unsigned int nbvisiblepolygone;
274 
276  bool displayMe;
277 
280 
282  std::vector<bool> scales;
283 
285  std::vector< const vpImage<unsigned char>* > Ipyramid;
286 
288  unsigned int scaleLevel;
289 
290  public:
291 
292  vpMbEdgeTracker();
293  virtual ~vpMbEdgeTracker();
294 
300  inline void setLambda(const double lambda) {this->lambda = lambda;}
301 
302  void setMovingEdge(const vpMe &_me);
303  void loadConfigFile(const std::string &filename);
304  void loadConfigFile(const char* filename);
305  void loadModel(const std::string &cad_name);
306  void loadModel(const char* cad_name);
307 
308 private:
309  void init(const vpImage<unsigned char>& I);
310 
311 public:
312  void track(const vpImage<unsigned char> &I);
313  void display(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor& col , const unsigned int l=1, const bool displayFullModel = false);
314  void display(const vpImage<vpRGBa>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor& col , const unsigned int l=1, const bool displayFullModel = false);
315  void resetTracker();
316  void reInitModel(const vpImage<unsigned char>& I, const char* cad_name, const vpHomogeneousMatrix& _cMo);
317 
328  void setDisplayMovingEdges(const bool displayMe) {this->displayMe = displayMe;}
329 
339  void setFirstThreshold(const double threshold1) {percentageGdPt = threshold1;}
340  double getFirstThreshold() { return percentageGdPt;}
341 
342 
348  inline void getMovingEdge(vpMe &_me ) { _me = this->me;}
349 
350  unsigned int getNbPoints(const unsigned int _level=0);
351  vpMbtPolygon* getPolygon(const unsigned int _index);
352  unsigned int getNbPolygon();
353  void getLline(std::list<vpMbtDistanceLine *>& linesList, const unsigned int _level = 0);
354  void getLcylinder(std::list<vpMbtDistanceCylinder *>& cylindersList, const unsigned int _level = 0);
355 
356  void setScales(const std::vector<bool>& _scales);
357 
363  std::vector<bool> getScales() const {return scales;}
364 
365 
366 
372  virtual void setCameraParameters(const vpCameraParameters& _cam) {
373  this->cam = _cam;
374  cameraInitialised = true;
375 
376  for (unsigned int i = 0; i < scales.size(); i += 1){
377  if(scales[i]){
378  for(std::list<vpMbtDistanceLine*>::const_iterator it=lines[i].begin(); it!=lines[i].end(); ++it){
379  (*it)->setCameraParameters(cam);
380  }
381 
382  for(std::list<vpMbtDistanceCylinder*>::const_iterator it=cylinders[i].begin(); it!=cylinders[i].end(); ++it){
383  (*it)->setCameraParameters(cam);
384  }
385  }
386  }
387  }
388 
389  protected:
390  void computeVVS(const vpImage<unsigned char>& _I);
391  void initMovingEdge(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &_cMo) ;
392  void trackMovingEdge(const vpImage<unsigned char> &I) ;
393  void updateMovingEdge(const vpImage<unsigned char> &I) ;
394  void visibleFace(const vpHomogeneousMatrix &cMo, bool &newvisibleline) ;
395  void reinitMovingEdge(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &_cMo);
396  void addPolygon(vpMbtPolygon &p) ;
397  void addLine(vpPoint &p1, vpPoint &p2, int polygone = -1, std::string name = "");
398  void removeLine(const std::string& name);
399  void addCylinder(const vpPoint &P1, const vpPoint &P2, const double r, const std::string& name = "");
400  void removeCylinder(const std::string& name);
401  virtual void initFaceFromCorners(const std::vector<vpPoint>& _corners, const unsigned int _indexFace = -1);
402  virtual void initCylinder(const vpPoint& _p1, const vpPoint _p2, const double _radius, const unsigned int _indexCylinder=0);
403 
404  void testTracking();
405  void initPyramid(const vpImage<unsigned char>& _I, std::vector<const vpImage<unsigned char>* >& _pyramid);
406  void cleanPyramid(std::vector<const vpImage<unsigned char>* >& _pyramid);
407  void reInitLevel(const unsigned int _lvl);
408  void downScale(const unsigned int _scale);
409  void upScale(const unsigned int _scale);
410 
411  public:
412 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
413 
422  vp_deprecated vpList<vpMbtDistanceLine *>* getLline(const unsigned int _level = 0);
428  vp_deprecated vpList<vpMbtDistanceCylinder *>* getLcylinder(const unsigned int _level = 0);
429 
435  vp_deprecated void init(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo) ;
436 #endif
437 
438 
439 };
440 
441 #endif
442 
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.
virtual void loadModel(const std::string &_modelFile)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
Provide simple list management.
Definition: vpList.h:112
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(...
void getMovingEdge(vpMe &_me)
virtual void setCameraParameters(const vpCameraParameters &_cam)
Class to define colors available for display functionnalities.
Definition: vpColor.h:123
bool displayMe
If true, the moving edges are displayed during the track() method.
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...
vpMe me
The moving edges parameters.
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)
virtual void track(const vpImage< unsigned char > &_I)=0
virtual void display(const vpImage< unsigned char > &_I, const vpHomogeneousMatrix &_cMo, const vpCameraParameters &_cam, const vpColor &_col, const unsigned int _l=1, const bool displayFullModel=false)=0
vpMbtHiddenFaces faces
Set of faces describing the object.
Class that defines what is a point.
Definition: vpPoint.h:65
int index_polygon
Index of the polygon to add, and total number of polygon extracted so far. Cannot be unsigned because...
std::vector< bool > scales
Vector of scale level to use for the multi-scale tracking.
Generic class defining intrinsic camera parameters.
Main methods for a model-based tracker.
Definition: vpMbTracker.h:95
double percentageGdPt
Percentage of good points over total number of points below which tracking is supposed to have failed...
void setLambda(const double lambda)
double getFirstThreshold()
virtual void initCylinder(const vpPoint &_p1, const vpPoint _p2, const double _radius, const unsigned int _indexCylinder=0)=0
virtual void loadConfigFile(const std::string &_configFile)=0
std::vector< std::list< vpMbtDistanceCylinder * > > cylinders
Vector of the tracked cylinders.
virtual void init(const vpImage< unsigned char > &_I)=0
virtual void testTracking()=0
unsigned int nbvisiblepolygone
Number of polygon (face) currently visible.
virtual void initFaceFromCorners(const std::vector< vpPoint > &_corners, const unsigned int _indexFace=-1)=0
unsigned int nline
Index of the polygon to add, and total number of polygon extracted so far.