ViSP
2.8.0
|
#include <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 143 of file vpPlanarObjectDetector.h.
vpPlanarObjectDetector::vpPlanarObjectDetector | ( | ) |
Basic constructor
Definition at line 62 of file vpPlanarObjectDetector.cpp.
References currentImagePoints, dst_corners, isCorrect, minNbMatching, ref_corners, and refImagePoints.
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 80 of file vpPlanarObjectDetector.cpp.
|
virtual |
Basic destructor
Definition at line 101 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 159 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 186 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 214 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 114 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 392 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 432 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 485 of file vpPlanarObjectDetector.cpp.
References dst_corners, and vpImagePoint::set_uv().
|
inline |
Return a reference to the classifier.
Definition at line 217 of file vpPlanarObjectDetector.h.
|
inline |
Return the computed homography between the reference image and the current image.
_H | : The computed homography. |
Definition at line 225 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 535 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 268 of file vpPlanarObjectDetector.h.
|
inline |
Return the number of reference points
Definition at line 232 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 526 of file vpPlanarObjectDetector.cpp.
References vpException::fatalError, and refImagePoints.
|
protectedvirtual |
initialise stuff
Definition at line 91 of file vpPlanarObjectDetector.cpp.
|
protected |
Initialise the internal reference corners from the rectangle.
_modelROI | : The rectangle defining the region of interest. |
Definition at line 503 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 456 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 243 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 339 of file vpPlanarObjectDetector.cpp.
References vpImageTools::createSubImage(), 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 371 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 472 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 259 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 166 of file vpPlanarObjectDetector.h.
Referenced by display(), getMatchedPoints(), matchPoint(), and vpPlanarObjectDetector().
|
protected |
The estimated new coordinates of the corners (reprojected using the homography).
Definition at line 154 of file vpPlanarObjectDetector.h.
Referenced by display(), getDetectedCorners(), matchPoint(), and vpPlanarObjectDetector().
|
protected |
Fern Classifier used to match the points between a reference image and the current image.
Definition at line 146 of file vpPlanarObjectDetector.h.
Referenced by buildReference(), load(), matchPoint(), and recordDetector().
|
protected |
Computed homography in the OpenCV format.
Definition at line 151 of file vpPlanarObjectDetector.h.
Referenced by matchPoint().
|
protected |
Computed homography in the ViSP format.
Definition at line 149 of file vpPlanarObjectDetector.h.
Referenced by matchPoint().
|
protected |
Flag to indicate wether the last computed homography is correct or not.
Definition at line 157 of file vpPlanarObjectDetector.h.
Referenced by matchPoint(), and vpPlanarObjectDetector().
|
protected |
Minimal number of point to after the ransac needed to suppose that the homography has been correctly computed.
Definition at line 171 of file vpPlanarObjectDetector.h.
Referenced by matchPoint(), and vpPlanarObjectDetector().
|
protected |
The ROI for the reference image.
Definition at line 163 of file vpPlanarObjectDetector.h.
Referenced by buildReference(), display(), load(), and matchPoint().
|
protected |
The corners in the reference image.
Definition at line 160 of file vpPlanarObjectDetector.h.
Referenced by initialiseRefCorners(), matchPoint(), and vpPlanarObjectDetector().
|
protected |
Vector of the image point in the reference image that match after the deletion of the outliers with the RANSAC.
Definition at line 168 of file vpPlanarObjectDetector.h.
Referenced by display(), getMatchedPoints(), getReferencePoint(), matchPoint(), and vpPlanarObjectDetector().