Visual Servoing Platform
version 3.0.1
|
#include <visp3/vision/vpPlanarObjectDetector.h>
Public Member Functions | |
vpPlanarObjectDetector () | |
vpPlanarObjectDetector (const std::string &dataFile, const std::string &objectName) | |
virtual | ~vpPlanarObjectDetector () |
unsigned int | buildReference (const vpImage< unsigned char > &I) |
unsigned int | buildReference (const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int height, unsigned int width) |
unsigned int | buildReference (const vpImage< unsigned char > &I, const vpRect rectangle) |
bool | matchPoint (const vpImage< unsigned char > &I) |
bool | matchPoint (const vpImage< unsigned char > &I, const vpImagePoint &iP, const unsigned int height, const unsigned int width) |
bool | matchPoint (const vpImage< unsigned char > &I, const vpRect rectangle) |
void | recordDetector (const std::string &objectName, const std::string &dataFile) |
void | load (const std::string &dataFilename, const std::string &objName) |
void | display (vpImage< unsigned char > &I, bool displayKpts=false) |
void | display (vpImage< unsigned char > &Iref, vpImage< unsigned char > &Icurrent, bool displayKpts=false) |
std::vector< vpImagePoint > | getDetectedCorners () const |
vpFernClassifier & | getFernClassifier () |
void | getHomography (vpHomography &_H) const |
unsigned int | getNbRefPoints () |
void | getReferencePoint (const unsigned int _i, vpImagePoint &_imPoint) |
void | getMatchedPoints (const unsigned int _index, vpImagePoint &_referencePoint, vpImagePoint &_currentPoint) |
void | setMinNbPointValidation (const unsigned int _min) |
unsigned int | getMinNbPointValidation () const |
Protected Member Functions | |
virtual void | init () |
void | computeRoi (vpImagePoint *ip, const unsigned int nbpt) |
void | initialiseRefCorners (const cv::Rect &_modelROI) |
Protected Attributes | |
vpFernClassifier | fern |
vpHomography | homography |
cv::Mat | H |
std::vector< cv::Point2f > | dst_corners |
bool | isCorrect |
std::vector< cv::Point2f > | ref_corners |
cv::Rect | modelROI |
std::vector< vpImagePoint > | currentImagePoints |
std::vector< vpImagePoint > | refImagePoints |
unsigned int | minNbMatching |
Class used to detect a planar surface.
This class allows to learn and recognise a surface in an image based on the Fern Classifier or any other point of interest matching class.
It uses the class vpFernClassifier to extract points of interest in a reference image. These points are recorded and a classifier is trained to recognises them.
In this class the points detected are assumed to belong to a planar surface. Therefore an homography can be computed between the reference image and the current image if the object is detected in the image.
A robust method (RANSAC) is used to remove outliers in the matching process.
The following example shows how to use the class.
Definition at line 142 of file vpPlanarObjectDetector.h.
vpPlanarObjectDetector::vpPlanarObjectDetector | ( | ) |
Basic constructor
Definition at line 57 of file vpPlanarObjectDetector.cpp.
vpPlanarObjectDetector::vpPlanarObjectDetector | ( | const std::string & | _dataFile, |
const std::string & | _objectName | ||
) |
Basic constructor, load data from a file.
_dataFile | : the name of the file. |
_objectName | : the name of the object to load. |
Definition at line 71 of file vpPlanarObjectDetector.cpp.
References load().
|
virtual |
Basic destructor
Definition at line 91 of file vpPlanarObjectDetector.cpp.
unsigned int vpPlanarObjectDetector::buildReference | ( | const vpImage< unsigned char > & | _I | ) |
Train the classifier from the entire image (it is therefore assumed that the image is planar).
Depending on the parameters, the training can take up to several minutes.
_I | : The image use to train the classifier. |
Definition at line 149 of file vpPlanarObjectDetector.cpp.
References vpFernClassifier::buildReference(), fern, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), initialiseRefCorners(), and modelROI.
unsigned int vpPlanarObjectDetector::buildReference | ( | const vpImage< unsigned char > & | _I, |
const vpImagePoint & | _iP, | ||
unsigned int | _height, | ||
unsigned int | _width | ||
) |
Train the classifier on a region of the entire image. The region is a rectangle defined by its top left corner, its height and its width. The parameters of this rectangle must be given in pixel. It also includes the training of the fern classifier.
_I | : The image use to train the classifier. |
_iP | : The top left corner of the rectangle defining the region of interest (ROI). |
_height | : The height of the ROI. |
_width | : The width of the ROI. |
Definition at line 176 of file vpPlanarObjectDetector.cpp.
References vpFernClassifier::buildReference(), fern, vpImagePoint::get_u(), vpImagePoint::get_v(), initialiseRefCorners(), and modelROI.
unsigned int vpPlanarObjectDetector::buildReference | ( | const vpImage< unsigned char > & | _I, |
const vpRect | _rectangle | ||
) |
Train the classifier on a region of the entire image. The region is a rectangle. The parameters of this rectangle must be given in pixel. It also includes the training of the fern classifier.
_I | : The image use to train the classifier. |
_rectangle | : The rectangle defining the region of interest (ROI). |
Definition at line 204 of file vpPlanarObjectDetector.cpp.
References vpFernClassifier::buildReference(), fern, vpImagePoint::get_u(), vpImagePoint::get_v(), vpRect::getHeight(), vpRect::getTopLeft(), vpRect::getWidth(), initialiseRefCorners(), and modelROI.
|
protected |
Compute the rectangular ROI from at least 4 points and set the region of interest on the current image.
ip | : the list of image point. |
nbpt | : the number of point. |
Definition at line 104 of file vpPlanarObjectDetector.cpp.
References vpException::badValue, and vpImagePoint::get_j().
void vpPlanarObjectDetector::display | ( | vpImage< unsigned char > & | I, |
bool | displayKpts = false |
||
) |
Display the result of the matching. The plane is displayed in red and the points of interests detected in the image are shown by a red dot surrounded by a green circle (the radius of the circle depends on the octave at which it has been detected).
I | : The gray scaled image for the display. |
displayKpts | : The flag to display keypoints in addition to the surface. |
Definition at line 382 of file vpPlanarObjectDetector.cpp.
References currentImagePoints, vpDisplay::displayCross(), vpDisplay::displayLine(), dst_corners, modelROI, and vpColor::red.
Referenced by display().
void vpPlanarObjectDetector::display | ( | vpImage< unsigned char > & | Iref, |
vpImage< unsigned char > & | Icurrent, | ||
bool | displayKpts = false |
||
) |
This function displays the matched reference points and the matched points computed in the current image. The reference points are displayed in the image Ireference and the matched points coming from the current image are displayed in the image Icurrent. It is possible to set Ireference and Icurrent with the same image when calling the method.
Iref | : The image where the matched reference points are displayed. |
Icurrent | : The image where the matched points computed in the current image are displayed. |
displayKpts | : The flag to display keypoints in addition to the surface. |
Definition at line 422 of file vpPlanarObjectDetector.cpp.
References display(), vpDisplay::displayCross(), vpColor::green, and refImagePoints.
std::vector< vpImagePoint > vpPlanarObjectDetector::getDetectedCorners | ( | ) | const |
Return the positions of the detected corners.
Return the last positions of the detected corners.
Definition at line 475 of file vpPlanarObjectDetector.cpp.
References dst_corners, and vpImagePoint::set_uv().
|
inline |
Return a reference to the classifier.
Definition at line 216 of file vpPlanarObjectDetector.h.
|
inline |
Return the computed homography between the reference image and the current image.
_H | : The computed homography. |
Definition at line 224 of file vpPlanarObjectDetector.h.
void vpPlanarObjectDetector::getMatchedPoints | ( | const unsigned int | _index, |
vpImagePoint & | _referencePoint, | ||
vpImagePoint & | _currentPoint | ||
) |
Get the nth couple of reference point and current point which have been matched. These points are copied in the vpImagePoint instances given in argument.
_index | : The index of the desired couple of reference point and current point . The index must be between 0 and the number of matched points - 1. |
_referencePoint | : The coordinates of the desired reference point are copied here. |
_currentPoint | : The coordinates of the desired current point are copied here. |
Definition at line 525 of file vpPlanarObjectDetector.cpp.
References currentImagePoints, vpException::fatalError, and refImagePoints.
|
inline |
Get the threshold for the minimal number of point to validate the homography. Default value is 10.
Definition at line 267 of file vpPlanarObjectDetector.h.
|
inline |
Return the number of reference points
Definition at line 231 of file vpPlanarObjectDetector.h.
void vpPlanarObjectDetector::getReferencePoint | ( | const unsigned int | _i, |
vpImagePoint & | _imPoint | ||
) |
Get the i-th reference point.
vpException | if _i is out if bound. |
_i | : index of the point to get |
_imPoint | : image point returned by the |
Definition at line 516 of file vpPlanarObjectDetector.cpp.
References vpException::fatalError, and refImagePoints.
|
protectedvirtual |
Initialise stuff. For the moment does nothing.
Definition at line 82 of file vpPlanarObjectDetector.cpp.
|
protected |
Initialise the internal reference corners from the rectangle.
_modelROI | : The rectangle defining the region of interest. |
Definition at line 493 of file vpPlanarObjectDetector.cpp.
References ref_corners.
Referenced by buildReference(), and load().
void vpPlanarObjectDetector::load | ( | const std::string & | dataFilename, |
const std::string & | objName | ||
) |
Load the Fern classifier.
Load and initialize the Fern classifier and load the 3D and 2D keypoints. It can take up to sevral seconds.
dataFilename | : The name of the data filename (very large text file). It can have any file extension. |
objName | : The name of the object. |
Definition at line 446 of file vpPlanarObjectDetector.cpp.
References fern, vpFernClassifier::getModelROI(), initialiseRefCorners(), vpFernClassifier::load(), and modelROI.
Referenced by vpPlanarObjectDetector().
bool vpPlanarObjectDetector::matchPoint | ( | const vpImage< unsigned char > & | I | ) |
Compute the points of interest in the current image and try to recognise them using the trained classifier. The matched pairs can be found with the getMatchedPointByRef function. The homography between the two planar surfaces is also computed.
I | : The gray scaled image where the points are computed. |
Definition at line 233 of file vpPlanarObjectDetector.cpp.
References currentImagePoints, dst_corners, fern, vpFernClassifier::getCurPt(), vpFernClassifier::getRefPt(), H, homography, isCorrect, vpFernClassifier::matchPoint(), minNbMatching, modelROI, ref_corners, refImagePoints, vpImagePoint::set_i(), and vpImagePoint::set_j().
Referenced by matchPoint().
bool vpPlanarObjectDetector::matchPoint | ( | const vpImage< unsigned char > & | I, |
const vpImagePoint & | iP, | ||
const unsigned int | height, | ||
const unsigned int | width | ||
) |
Compute the points of interest in the specified region of the current image and try to recognise them using the trained classifier. The matched pairs can be found with the getMatchedPointByRef function. The homography between the two planar surfaces is also computed.
I | : The gray scaled image where the points are computed. |
iP | : the top left corner of the rectangle defining the ROI |
height | : the height of the ROI |
width | : the width of the ROI |
Definition at line 329 of file vpPlanarObjectDetector.cpp.
References vpImageTools::crop(), vpImagePoint::get_i(), vpImagePoint::get_j(), vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), matchPoint(), vpImageException::notInTheImage, and vpTRACE.
bool vpPlanarObjectDetector::matchPoint | ( | const vpImage< unsigned char > & | I, |
const vpRect | rectangle | ||
) |
Compute the points of interest in the specified region of the current image and try to recognise them using the trained classifier. The matched pairs can be found with the getMatchedPointByRef function. The homography between the two planar surfaces is also computed.
I | : The gray scaled image where the points are computed. |
rectangle | : The rectangle defining the ROI. |
Definition at line 361 of file vpPlanarObjectDetector.cpp.
References vpRect::getHeight(), vpRect::getLeft(), vpRect::getTop(), vpRect::getWidth(), matchPoint(), vpImagePoint::set_i(), and vpImagePoint::set_j().
void vpPlanarObjectDetector::recordDetector | ( | const std::string & | objectName, |
const std::string & | dataFile | ||
) |
Record the Ferns classifier in the text file.
objectName | : The name of the object to store in the data file. |
dataFile | : The name of the data filename (very large text file). It can have any file extension. |
Definition at line 462 of file vpPlanarObjectDetector.cpp.
References fern, and vpFernClassifier::record().
|
inline |
Set the threshold for the minimal number of point to validate the homography. Default value is 10.
_min | : the new threshold. |
Definition at line 258 of file vpPlanarObjectDetector.h.
|
protected |
Vector of the image point in the current image that match after the deletion of the outliers with the RANSAC.
Definition at line 165 of file vpPlanarObjectDetector.h.
Referenced by display(), getMatchedPoints(), and matchPoint().
|
protected |
The estimated new coordinates of the corners (reprojected using the homography).
Definition at line 153 of file vpPlanarObjectDetector.h.
Referenced by display(), getDetectedCorners(), and matchPoint().
|
protected |
Fern Classifier used to match the points between a reference image and the current image.
Definition at line 145 of file vpPlanarObjectDetector.h.
Referenced by buildReference(), load(), matchPoint(), and recordDetector().
|
protected |
Computed homography in the OpenCV format.
Definition at line 150 of file vpPlanarObjectDetector.h.
Referenced by matchPoint().
|
protected |
Computed homography in the ViSP format.
Definition at line 148 of file vpPlanarObjectDetector.h.
Referenced by matchPoint().
|
protected |
Flag to indicate wether the last computed homography is correct or not.
Definition at line 156 of file vpPlanarObjectDetector.h.
Referenced by matchPoint().
|
protected |
Minimal number of point to after the ransac needed to suppose that the homography has been correctly computed.
Definition at line 170 of file vpPlanarObjectDetector.h.
Referenced by matchPoint().
|
protected |
The ROI for the reference image.
Definition at line 162 of file vpPlanarObjectDetector.h.
Referenced by buildReference(), display(), load(), and matchPoint().
|
protected |
The corners in the reference image.
Definition at line 159 of file vpPlanarObjectDetector.h.
Referenced by initialiseRefCorners(), and matchPoint().
|
protected |
Vector of the image point in the reference image that match after the deletion of the outliers with the RANSAC.
Definition at line 167 of file vpPlanarObjectDetector.h.
Referenced by display(), getMatchedPoints(), getReferencePoint(), and matchPoint().