ViSP  2.6.2
vpMbTracker Class Referenceabstract

#include <vpMbTracker.h>

+ Inheritance diagram for vpMbTracker:

Public Member Functions

 vpMbTracker ()
 
virtual ~vpMbTracker ()
 
virtual void initClick (const vpImage< unsigned char > &_I, const std::string &_initFile, const bool _displayHelp=false)
 
virtual void initClick (const vpImage< unsigned char > &_I, const std::vector< vpPoint > &points3D_list, const std::string &displayFile="")
 
virtual void initFromPoints (const vpImage< unsigned char > &_I, const std::string &_initFile)
 
virtual void initFromPoints (const vpImage< unsigned char > &_I, const std::vector< vpImagePoint > &points2D_list, const std::vector< vpPoint > &points3D_list)
 
virtual void initFromPose (const vpImage< unsigned char > &_I, const std::string &_initFile)
 
virtual void initFromPose (const vpImage< unsigned char > &_I, const vpHomogeneousMatrix &_cMo)
 
virtual void initFromPose (const vpImage< unsigned char > &_I, const vpPoseVector &cPo)
 
virtual void init (const vpImage< unsigned char > &_I)=0
 
virtual void testTracking ()=0
 
virtual void loadConfigFile (const std::string &_configFile)=0
 
virtual void track (const vpImage< unsigned char > &_I)=0
 
virtual void loadModel (const std::string &_modelFile)
 
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
 
virtual void setCameraParameters (const vpCameraParameters &_cam)
 
virtual void setCovarianceComputation (const bool &flag)
 
virtual void getCameraParameters (vpCameraParameters &_cam) const
 
virtual vpMatrix getCovarianceMatrix () const
 
void getPose (vpHomogeneousMatrix &_cMo) const
 
vpHomogeneousMatrix getPose () const
 
void setPoseSavingFilename (const std::string &filename)
 
void savePose (const std::string &filename)
 

Protected Member Functions

virtual void loadVRMLModel (const std::string &_modelFile)
 
virtual void loadCAOModel (const std::string &_modelFile)
 
void computeJTR (const vpMatrix &_J, const vpColVector &_R, vpMatrix &_JTR)
 
virtual void extractFaces (SoVRMLIndexedFaceSet *_face_set)
 
virtual void extractLines (SoVRMLIndexedLineSet *_line_set)
 
virtual void extractCylinders (SoVRMLIndexedFaceSet *_face_set)
 
vpPoint getGravityCenter (const std::vector< vpPoint > &_pts)
 
virtual void initFaceFromCorners (const std::vector< vpPoint > &_corners, const unsigned int _indexFace=-1)=0
 
virtual void initCylinder (const vpPoint &_p1, const vpPoint _p2, const double _radius, const unsigned int _indexCylinder=0)=0
 
Deprecated functions
virtual void init (const vpImage< unsigned char > &_I, const vpHomogeneousMatrix &_c0Mo)=0
 

Protected Attributes

vpCameraParameters cam
 
vpHomogeneousMatrix cMo
 
std::string modelFileName
 
bool modelInitialised
 
bool cameraInitialised
 
bool coinUsed
 
std::string poseSavingFilename
 
bool computeCovariance
 
vpMatrix covarianceMatrix
 

Detailed Description

Main methods for a model-based tracker.

This class provides the main methods for a model based tracker. This pure virtual class must be used in inheritance for a tracker that compute the interaction matrix and the residu vector using a defined information (edge, points of interest, patch, ...)

This class intends to define a common basis for object tracking. This is realised by implementing the main functions:

  • init() : Initialisation of the tracker (it includes re-initialisation). This method is called at the end of the initClick() method.
  • initFaceFromCorners() : Initialisation of a face using its corners.
  • track() : Tracking on the current image
  • testTracking() : Test the tracking. This method throws exception if the tracking failed.
  • display() : Display the model and eventually other informations.

In addition, two flags are declared in this class and may have to be initialised in the child class :

  • modelInitialised : flag to ensure that the model has been loaded.
  • cameraInitialised : flag to ensure that camera parameters have been initialised (either by loading them from a configuration file or by setting them with the setCameraParameters() method).

Definition at line 95 of file vpMbTracker.h.

Constructor & Destructor Documentation

vpMbTracker::vpMbTracker ( )

Basic constructor. Set default values.

Definition at line 94 of file vpMbTracker.cpp.

References cameraInitialised, coinUsed, computeCovariance, and modelInitialised.

vpMbTracker::~vpMbTracker ( )
virtual

Basic destructor.

Definition at line 106 of file vpMbTracker.cpp.

References coinUsed.

Member Function Documentation

void vpMbTracker::computeJTR ( const vpMatrix _interaction,
const vpColVector _error,
vpMatrix _JTR 
)
protected

Compute $ J^T R $, with J the interaction matrix and R the vector of residu.

Exceptions
vpMatrixException::incorrectMatrixSizeErrorif the sizes of the matrices do not allow the computation.
Warning
The JTR matrix is resized.
Parameters
_interaction: The interaction matrix (size Nx6).
_error: The residu vector (size Nx1).
_JTR: The resulting JTR matrix (size 6x1).

Definition at line 1226 of file vpMbTracker.cpp.

References vpMatrix::getCols(), vpMatrix::getRows(), vpMatrixException::incorrectMatrixSizeError, and vpMatrix::resize().

Referenced by vpMbEdgeTracker::computeVVS().

virtual void vpMbTracker::display ( const vpImage< unsigned char > &  _I,
const vpHomogeneousMatrix _cMo,
const vpCameraParameters _cam,
const vpColor _col,
const unsigned int  _l = 1,
const bool  displayFullModel = false 
)
pure virtual

Display the 3D model at a given position using the given camera parameters on a grey level image.

Parameters
_I: The image.
_cMo: Pose used to project the 3D model into the image.
_cam: The camera parameters.
_col: The desired color.
_l: The thickness of the lines.
displayFullModel: If true, the full model is displayed (even the non visible surfaces).

Implemented in vpMbEdgeTracker.

Referenced by initClick().

void vpMbTracker::extractCylinders ( SoVRMLIndexedFaceSet *  _face_set)
protectedvirtual

Extract a cylinder to track from the VMRL model. This method calls the initCylinder() method implemented in the child class.

Warning
This method extract cylinder described using an indexed face set not a cylinder set since software such as AC3D or blender export a cylinder using this data type. the object name is used, if it begins with "cyl" then this method is called otherwise the extractFaces() is used.
Parameters
_face_set: Pointer to the cylinder in the vrml format.

Definition at line 1078 of file vpMbTracker.cpp.

References vpException::badValue, vpException::dimensionError, vpPoint::get_oX(), vpPoint::get_oY(), vpPoint::get_oZ(), getGravityCenter(), initCylinder(), vpMath::maximum(), vpPoint::setWorldCoordinates(), and vpMatrix::sumSquare().

Referenced by loadVRMLModel().

void vpMbTracker::extractFaces ( SoVRMLIndexedFaceSet *  _face_set)
protectedvirtual

Extract a face of the object to track from the VMRL model. This method calls the initFaceFromCorners() method implemented in the child class.

Parameters
_face_set: Pointer to the face in the vrml format.

Definition at line 1028 of file vpMbTracker.cpp.

References initFaceFromCorners(), and vpPoint::setWorldCoordinates().

Referenced by loadVRMLModel().

void vpMbTracker::extractLines ( SoVRMLIndexedLineSet *  _line_set)
protectedvirtual

Extract a line of the object to track from the VMRL model. This method calls the initFaceFromCorners() method implemented in the child class.

Parameters
_line_set: Pointer to the line in the vrml format.

Definition at line 1171 of file vpMbTracker.cpp.

References initFaceFromCorners(), and vpPoint::setWorldCoordinates().

Referenced by loadVRMLModel().

virtual void vpMbTracker::getCameraParameters ( vpCameraParameters _cam) const
inlinevirtual

Get the camera parameters.

Parameters
_cam: copy of the camera parameters used by the tracker.
Examples:
mbtTracking.cpp.

Definition at line 203 of file vpMbTracker.h.

virtual vpMatrix vpMbTracker::getCovarianceMatrix ( ) const
inlinevirtual

Get the covariance matrix.

Definition at line 208 of file vpMbTracker.h.

References vpTRACE.

vpPoint vpMbTracker::getGravityCenter ( const std::vector< vpPoint > &  _pts)
protected

Compute the center of gravity of a set of point. This is used in the cylinder extraction to find the center of the circles.

Exceptions
vpException::dimensionErrorif the set is empty.
Parameters
_pts: Set of point to extract the center of gravity.
Returns
Center of gravity of the set.

Definition at line 1142 of file vpMbTracker.cpp.

References vpException::dimensionError, vpPoint::get_oX(), and vpPoint::setWorldCoordinates().

Referenced by extractCylinders().

void vpMbTracker::getPose ( vpHomogeneousMatrix _cMo) const
inline

Get the current pose between the object and the camera. cMo is the matrix which can be used to express coordinates from the object frame to camera frame.

Parameters
_cMo: the pose
Examples:
mbtTracking.cpp.

Definition at line 222 of file vpMbTracker.h.

vpHomogeneousMatrix vpMbTracker::getPose ( ) const
inline

Get the current pose between the object and the camera. cMo is the matrix which can be used to express coordinates from the object frame to camera frame.

Returns
the current pose

Definition at line 231 of file vpMbTracker.h.

virtual void vpMbTracker::init ( const vpImage< unsigned char > &  _I)
pure virtual

Initialise the tracking.

Parameters
_I: Input image.

Referenced by initClick(), initFromPoints(), and initFromPose().

virtual void vpMbTracker::init ( const vpImage< unsigned char > &  _I,
const vpHomogeneousMatrix _c0Mo 
)
protectedpure virtual
Deprecated:
This method is deprecated. You should use void initFromPose(const vpImage<unsigned char>&, const vpHomogeneousMatrix&) instead.

Initialise the tracking using the known pose cMo.

Parameters
_I: Input image.
_c0Mo: Initial pose between the camera and the object.

Implemented in vpMbEdgeTracker.

void vpMbTracker::initClick ( const vpImage< unsigned char > &  _I,
const std::string &  _initFile,
const bool  _displayHelp = false 
)
virtual

Initialise the tracking by clicking on the image points corresponding to the 3D points (object frame) in the file _initFile. The structure of this file is (without the comments):

4 // Number of points in the file (minimum is four)
0.01 0.01 0.01 // \
... // | 3D coordinates in the object basis
0.01 -0.01 -0.01 // /
Parameters
_I: Input image
_initFile: File containing the points where to click
_displayHelp: Optionnal display of an image ( '_initFile.ppm' ). This image may be used to show where to click.
Exceptions
vpException::ioError: The file specified in _initFile doesn't exist.
See also
setPathNamePoseSaving()
Examples:
mbtTracking.cpp.

Definition at line 139 of file vpMbTracker.cpp.

References vpPose::addPoint(), vpHomogeneousMatrix::buildFrom(), vpMouseButton::button1, cam, vpPose::clearPoint(), cMo, vpPose::computePose(), vpPose::computeResidual(), vpPixelMeterConversion::convertPoint(), vpPose::DEMENTHON, display(), vpDisplay::display(), vpDisplay::displayCharString(), vpDisplay::displayCross(), vpDisplay::displayFrame(), vpDisplay::displayPoint(), vpDisplay::flush(), vpDisplay::getClick(), vpColor::green, init(), vpDisplayOpenCV::init(), vpException::ioError, vpPose::LAGRANGE, poseSavingFilename, vpImageIo::readPPM(), vpColor::red, savePose(), vpPoint::set_x(), vpPoint::set_y(), vpHomogeneousMatrix::setIdentity(), vpPoint::setWorldCoordinates(), and vpPose::VIRTUAL_VS.

void vpMbTracker::initClick ( const vpImage< unsigned char > &  _I,
const std::vector< vpPoint > &  points3D_list,
const std::string &  displayFile = "" 
)
virtual

Initialise the tracking by clicking on the image points corresponding to the 3D points (object frame) in the list points3D_list.

Parameters
_I: Input image
points3D_list: List of the 3D points (object frame).
displayFile: Path to the image used to display the help.

Definition at line 355 of file vpMbTracker.cpp.

References vpPose::addPoint(), vpMouseButton::button1, cam, vpPose::clearPoint(), cMo, vpPose::computePose(), vpPose::computeResidual(), vpPixelMeterConversion::convertPoint(), vpPose::DEMENTHON, display(), vpDisplay::display(), vpDisplay::displayCharString(), vpDisplay::displayCross(), vpDisplay::displayFrame(), vpDisplay::displayPoint(), vpDisplay::flush(), vpDisplay::getClick(), vpColor::green, init(), vpDisplayOpenCV::init(), vpPose::LAGRANGE, vpImageIo::readPPM(), vpColor::red, vpPoint::set_x(), vpPoint::set_y(), and vpPose::VIRTUAL_VS.

virtual void vpMbTracker::initCylinder ( const vpPoint _p1,
const vpPoint  _p2,
const double  _radius,
const unsigned int  _indexCylinder = 0 
)
protectedpure virtual

Add a cylinder to track from two points on the axis (defining the length of the cylinder) and its radius.

Parameters
_p1: First point on the axis.
_p2: Second point on the axis.
_radius: Radius of the cylinder.
_indexCylinder: Index of the cylinder.

Implemented in vpMbEdgeTracker.

Referenced by extractCylinders(), and loadCAOModel().

virtual void vpMbTracker::initFaceFromCorners ( const std::vector< vpPoint > &  _corners,
const unsigned int  _indexFace = -1 
)
protectedpure virtual

Add a face to track from its corners (in the object frame). This method is called from the loadModel() one to add a face of the object to track. The initialisation of the face depends on the primitive to track.

Parameters
_corners: The vector of corners representing the face.
_indexFace: The index of the face.

Implemented in vpMbEdgeTracker.

Referenced by extractFaces(), extractLines(), and loadCAOModel().

void vpMbTracker::initFromPoints ( const vpImage< unsigned char > &  _I,
const std::string &  _initFile 
)
virtual

Initialise the tracking by reading the 3D points (object frame) and the image points in _initFile. The structure of this file is (without the comments):

4 // Number of 3D points in the file (minimum is four)
0.01 0.01 0.01 // \
... // | 3D coordinates in meters in the object frame
0.01 -0.01 -0.01 // /
4 // Number of image points in the file (has to be the same as the number of 3D points)
100 200 // \
... // | 2D coordinates in pixel in the image
50 10 // /
Parameters
_I: Input image
_initFile: Path to the file containing all the points.

Definition at line 471 of file vpMbTracker.cpp.

References vpPose::addPoint(), cam, cMo, vpPose::computePose(), vpPose::computeResidual(), vpPixelMeterConversion::convertPoint(), vpPose::DEMENTHON, init(), vpException::ioError, vpPose::LAGRANGE, vpPoint::set_x(), vpPoint::set_y(), vpPoint::setWorldCoordinates(), vpPose::VIRTUAL_VS, and vpERROR_TRACE.

void vpMbTracker::initFromPoints ( const vpImage< unsigned char > &  _I,
const std::vector< vpImagePoint > &  points2D_list,
const std::vector< vpPoint > &  points3D_list 
)
virtual

Initialise the tracking with the list of image points (points2D_list) and the list of corresponding 3D points (object frame) (points3D_list).

Parameters
_I: Input image
points2D_list: List of image points.
points3D_list: List of 3D points (object frame).

Definition at line 550 of file vpMbTracker.cpp.

References vpPose::addPoint(), cam, cMo, vpPose::computePose(), vpPose::computeResidual(), vpPixelMeterConversion::convertPoint(), vpPose::DEMENTHON, init(), vpPose::LAGRANGE, vpPoint::set_x(), vpPoint::set_y(), vpPoint::setWorldCoordinates(), vpPose::VIRTUAL_VS, and vpERROR_TRACE.

void vpMbTracker::initFromPose ( const vpImage< unsigned char > &  _I,
const std::string &  _initFile 
)
virtual

Initialise the tracking thanks to the pose in vpPoseVector format, and read in the file _initFile. The structure of this file is (without the comments):

// The six value of the pose vector
0.0000 // \
0.0000 // |
1.0000 // | Exemple of value for the pose vector where Z = 1 meter
0.0000 // |
0.0000 // |
0.0000 // /

Where the three firsts lines refer to the translation and the three last to the rotation in thetaU parametrisation (see vpThetaUVector).

Parameters
_I: Input image
_initFile: Path to the file containing the pose.
Examples:
mbtTracking.cpp.

Definition at line 604 of file vpMbTracker.cpp.

References vpHomogeneousMatrix::buildFrom(), cMo, init(), and vpException::ioError.

Referenced by initFromPose(), and vpMbEdgeTracker::reInitModel().

void vpMbTracker::initFromPose ( const vpImage< unsigned char > &  _I,
const vpHomogeneousMatrix _cMo 
)
virtual

Initialise the tracking thanks to the pose.

Parameters
_I: Input image
_cMo: Pose matrix.

Definition at line 639 of file vpMbTracker.cpp.

References cMo, and init().

void vpMbTracker::initFromPose ( const vpImage< unsigned char > &  _I,
const vpPoseVector cPo 
)
virtual

Initialise the tracking thanks to the pose vector.

Parameters
_I: Input image
cPo: Pose vector.

Definition at line 651 of file vpMbTracker.cpp.

References initFromPose().

void vpMbTracker::loadCAOModel ( const std::string &  _modelFile)
protectedvirtual

Load a 3D model contained in a .cao file.

the structure of the file is (without the comments) :

V1
8 // Number of points describing the object
0.01 0.01 0.01 // \
... // | coordinates of the points in the object frame (in m.)
0.01 0.01 0.01 // /
3 // Number of lines to track.
0 2 // \
1 4 // | Index of the points representing the extremities of the lines
1 5 // /
0 // Number of polygon (face) to track using the line previously described
// Face described as follow : nbLine IndexLine1 indexLine2 ... indexLineN
3 // Number of polygon (face) to track using the line previously described
4 0 2 3 4 // Face described as follow : nbPoint IndexPoint1 IndexPoint2 ... IndexPointN
4 1 3 5 7
3 1 5 6
1 // Number of cylinder
6 7 0.05 // Index of the limits points on the axis (used to know the 'height' of the cylinder) and radius of the cyclinder (in m.)
Parameters
_modelFile: Full name of the .CAO file containing the model.

Definition at line 839 of file vpMbTracker.cpp.

References vpException::badValue, initCylinder(), initFaceFromCorners(), vpException::ioError, vpPoint::setWorldCoordinates(), and vpTRACE.

Referenced by loadModel().

virtual void vpMbTracker::loadConfigFile ( const std::string &  _configFile)
pure virtual

Load a config file to parameterise the behavior of the tracker.

Pure virtual method to adapt to each tracker.

Parameters
_configFile: the (xml) config file to parse

Implemented in vpMbEdgeTracker.

void vpMbTracker::loadModel ( const std::string &  _modelFile)
virtual

Load a 3D model from the file in parameter. This file must either be a vrml file (.wrl) or a CAO file (.cao). CAO format is described in the loadCAOModel() method.

Exceptions
vpException::ioErrorif the file cannot be open, or if its extension is not wrl or cao.
Parameters
_modelFile: the file containing the model.

Reimplemented in vpMbEdgeTracker.

Definition at line 687 of file vpMbTracker.cpp.

References vpIoTools::checkFilename(), vpException::ioError, loadCAOModel(), loadVRMLModel(), modelFileName, and modelInitialised.

Referenced by vpMbEdgeTracker::loadModel().

void vpMbTracker::loadVRMLModel ( const std::string &  _modelFile)
protectedvirtual

Load the 3D model of the object from a vrml file. Only LineSet and FaceSet are extracted from the vrml file.

Warning
The cylinders extracted using this method do not use the Cylinder keyword of vrml since vrml exporter such as Blender or AC3D consider a cylinder as an IndexedFaceSet. To test whether an indexedFaceSet is a cylinder or not, the name of the geometry is read. If the name begins with "cyl" then the faceset is supposed to be a cylinder. For example, the line
geometry DEF cyl_cylinder1 IndexedFaceSet
defines a cylinder named cyl_cylinder1.
Exceptions
vpException::fatalErrorif the file cannot be open.
Parameters
_modelFile: The full name of the file containing the 3D model.

Definition at line 734 of file vpMbTracker.cpp.

References coinUsed, extractCylinders(), extractFaces(), extractLines(), vpException::fatalError, and vpERROR_TRACE.

Referenced by loadModel().

void vpMbTracker::savePose ( const std::string &  filename)

Save the pose in the given filename

Parameters
filename: Path to the file used to save the pose.

Definition at line 662 of file vpMbTracker.cpp.

References vpPoseVector::buildFrom(), and cMo.

Referenced by initClick().

virtual void vpMbTracker::setCameraParameters ( const vpCameraParameters _cam)
inlinevirtual

Set the camera parameters.

Parameters
_cam: the new camera parameters

Reimplemented in vpMbEdgeTracker.

Definition at line 189 of file vpMbTracker.h.

virtual void vpMbTracker::setCovarianceComputation ( const bool &  flag)
inlinevirtual

Set if the covaraince matrix has to be computed.

Parameters
flag: True if the covariance has to be computed, false otherwise

Definition at line 196 of file vpMbTracker.h.

void vpMbTracker::setPoseSavingFilename ( const std::string &  filename)
inline

Set the filename used to save the initial pose computed using the initClick() method. It is also used to read a previous pose in the same method. If the file is not set then, the initClick() method will create a .0.pos file in the root directory. This directory is the path to the file given to the method initClick() used to know the coordinates in the object frame.

Parameters
filename: The new filename.

Definition at line 242 of file vpMbTracker.h.

virtual void vpMbTracker::testTracking ( )
pure virtual

Test the quality of the tracking.

Exceptions
vpExceptionif the test fail.

Implemented in vpMbEdgeTracker.

virtual void vpMbTracker::track ( const vpImage< unsigned char > &  _I)
pure virtual

Track the object in the given image

Parameters
_I: The current image.

Implemented in vpMbEdgeTracker.

Member Data Documentation

bool vpMbTracker::cameraInitialised
protected

Flag used to ensure that the camera is set before the initialisation.

Definition at line 107 of file vpMbTracker.h.

Referenced by vpMbTracker().

bool vpMbTracker::coinUsed
protected

Flag used to specify that the Coin library has been loaded in order to load a vrml model (used to free the memory).

Definition at line 109 of file vpMbTracker.h.

Referenced by loadVRMLModel(), vpMbTracker(), and ~vpMbTracker().

bool vpMbTracker::computeCovariance
protected

Flag used to specify if the covariance matrix has to be computed or not.

Definition at line 113 of file vpMbTracker.h.

Referenced by vpMbEdgeTracker::computeVVS(), vpMbEdgeTracker::vpMbEdgeTracker(), and vpMbTracker().

vpMatrix vpMbTracker::covarianceMatrix
protected

Covariance matrix.

Definition at line 115 of file vpMbTracker.h.

Referenced by vpMbEdgeTracker::computeVVS().

std::string vpMbTracker::modelFileName
protected

The name of the file containing the model (it is used to create a file name.0.pos used to store the compute pose in the initClick method).

Definition at line 103 of file vpMbTracker.h.

Referenced by loadModel().

bool vpMbTracker::modelInitialised
protected

Flag used to ensure that the CAD model is loaded before the initialisation.

Definition at line 105 of file vpMbTracker.h.

Referenced by loadModel(), and vpMbTracker().

std::string vpMbTracker::poseSavingFilename
protected

Filename used to save the initial pose computed using the initClick() method. It is also used to read a previous pose in the same method.

Definition at line 111 of file vpMbTracker.h.

Referenced by initClick().