ViSP
2.9.0
|
#include <vpFernClassifier.h>
Public Member Functions | |
vpFernClassifier () | |
vpFernClassifier (const std::string &_dataFile, const std::string &_objectName) | |
virtual | ~vpFernClassifier () |
virtual unsigned int | buildReference (const vpImage< unsigned char > &I) |
virtual unsigned int | buildReference (const vpImage< unsigned char > &I, const vpImagePoint &iP, const unsigned int height, const unsigned int width) |
virtual unsigned int | buildReference (const vpImage< unsigned char > &I, const vpRect &rectangle) |
virtual unsigned int | matchPoint (const vpImage< unsigned char > &I) |
virtual unsigned int | matchPoint (const vpImage< unsigned char > &I, const vpImagePoint &iP, const unsigned int height, const unsigned int width) |
virtual unsigned int | matchPoint (const vpImage< unsigned char > &I, const vpRect &rectangle) |
virtual void | display (const vpImage< unsigned char > &Iref, const vpImage< unsigned char > &Icurrent, unsigned int size=3) |
virtual void | display (const vpImage< unsigned char > &Icurrent, unsigned int size=3, const vpColor &color=vpColor::green) |
void | load (const std::string &_dataFile, const std::string &) |
void | record (const std::string &_objectName, const std::string &_dataFile) |
void | setBlurSetting (const bool _blur) |
void | setBlurSettings (const bool _blur, int _sigma, int _size) |
bool | getBlurSetting () |
int | getBlurSigma () |
int | getBlurSize () |
const std::vector< cv::Point2f > & | getRefPt () const |
const std::vector< cv::Point2f > & | getCurPt () const |
cv::Rect | getModelROI () const |
bool | referenceBuilt () const |
const vpImagePoint * | getAllPointsInReferenceImage () |
void | getReferencePoint (const unsigned int index, vpImagePoint &referencePoint) |
void | getMatchedPoints (const unsigned int index, vpImagePoint &referencePoint, vpImagePoint ¤tPoint) |
unsigned int | getIndexInAllReferencePointList (const unsigned int indexInMatchedPointList) |
unsigned int | getReferencePointNumber () const |
unsigned int | getMatchedPointNumber () const |
const std::vector< vpImagePoint > & | getReferenceImagePointsList () const |
const std::vector< vpImagePoint > & | getCurrentImagePointsList () const |
const std::vector< unsigned int > & | getMatchedReferencePoints () const |
Protected Member Functions | |
void | setImage (const vpImage< unsigned char > &_I) |
void | train () |
virtual void | init () |
Protected Attributes | |
cv::LDetector | ldetector |
cv::FernClassifier | fernClassifier |
cv::PatchGenerator | gen |
bool | hasLearn |
int | threshold |
int | nbView |
int | dist |
int | nbClassfier |
int | ClassifierSize |
int | nbOctave |
int | patchSize |
int | radius |
int | nbPoints |
bool | blurImage |
int | radiusBlur |
int | sigmaBlur |
unsigned int | nbMinPoint |
IplImage * | curIplImg |
std::vector< cv::KeyPoint > | objKeypoints |
cv::Rect | modelROI_Ref |
cv::Rect | modelROI |
std::vector< cv::KeyPoint > | modelPoints |
std::vector< cv::KeyPoint > | imgKeypoints |
std::vector< cv::Point2f > | refPt |
std::vector< cv::Point2f > | curPt |
std::vector< vpImagePoint > | referenceImagePointsList |
std::vector< vpImagePoint > | currentImagePointsList |
std::vector< unsigned int > | matchedReferencePoints |
bool | _reference_computed |
Class that implements the Fern classifier and the YAPE detector thanks to the OpenCV library.
This class provides a way to detect and match point using the YAPE and a Fern Classifiers, thanks to the OpenCV library (version >= 2.0)
This class provides a tool to match points between a model and the current image. The points of interests belonging to the model and the points detected in the current image are given in pixels thanks to the vpImagePoint class.
For more details about the Ferns Classifier and the point detector, see [22] and [14].
To use this class, you first have to detect points in the model and train the associated Fern classifier. Then, for each new grabbed image, You can detect points and try to match them with the model.
As training can requires up to several minutes, it is possible to save (in a file) and load the classifier.
The following small example shows how to use the class.
It is also possible to create the reference thanks to only a part of the reference image (not the whole image) and find points to match in only a part of the current image. The small following example shows how to do this.
Definition at line 177 of file vpFernClassifier.h.
vpFernClassifier::vpFernClassifier | ( | ) |
Basic constructor
Definition at line 57 of file vpFernClassifier.cpp.
vpFernClassifier::vpFernClassifier | ( | const std::string & | _dataFile, |
const std::string & | _objectName | ||
) |
Constructor using the provided data file to load the object given by its name.
If the name of the object does not correspond in the file, a vpException::ioError is thrown.
_dataFile | : the name of the file saved after a training (with the record methods). |
_objectName | : the name of the object to load |
Definition at line 77 of file vpFernClassifier.cpp.
References load().
|
virtual |
|
virtual |
Build the list of reference points. The computation of the points is made all over the image I. It also includes the training of the fern classifier.
_I | : The gray scaled image where the reference points are computed. |
Implements vpBasicKeyPoint.
Definition at line 193 of file vpFernClassifier.cpp.
References vpBasicKeyPoint::_reference_computed, objKeypoints, setImage(), and train().
Referenced by vpPlanarObjectDetector::buildReference(), and buildReference().
|
virtual |
Build the list of reference points. The computation of the points is made only on a part of the image. This part 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 gray scaled image where the reference points are computed. |
_iP | : The top left corner of the rectangle. |
_height | : height of the rectangle (in pixel). |
_width | : width of the rectangle (in pixel). |
Implements vpBasicKeyPoint.
Definition at line 222 of file vpFernClassifier.cpp.
References vpImageTools::createSubImage(), vpImagePoint::get_i(), vpImagePoint::get_j(), vpImagePoint::get_u(), vpImagePoint::get_v(), vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), modelROI_Ref, vpImageException::notInTheImage, objKeypoints, setImage(), train(), and vpTRACE.
|
virtual |
Build the list of reference points. The computation of the points is made only on a part of the image. This part is a rectangle. The parameters of this rectangle must be given in pixel. It also includes the training of the fern classifier.
_I | : The gray scaled image where the reference points are computed. |
_rectangle | : The rectangle which defines the interesting part of the image. |
Implements vpBasicKeyPoint.
Definition at line 269 of file vpFernClassifier.cpp.
References buildReference(), vpRect::getHeight(), vpRect::getLeft(), vpRect::getTop(), vpRect::getWidth(), vpImagePoint::set_i(), and vpImagePoint::set_j().
|
virtual |
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. |
size | : Size in pixels of the cross that is used to display matched points. |
Implements vpBasicKeyPoint.
Definition at line 434 of file vpFernClassifier.cpp.
References vpBasicKeyPoint::currentImagePointsList, vpDisplay::displayCross(), vpColor::green, vpBasicKeyPoint::matchedReferencePoints, vpColor::red, and vpBasicKeyPoint::referenceImagePointsList.
|
virtual |
This function displays only the matched points computed in the current image. They are displayed in the image Icurrent.
_Icurrent | : the gray scaled image for the display |
size | : Size in pixels of the cross that is used to display matched points. |
color | : Color used to display the matched points. |
Implements vpBasicKeyPoint.
Definition at line 456 of file vpFernClassifier.cpp.
References vpBasicKeyPoint::currentImagePointsList, vpDisplay::displayCross(), and vpBasicKeyPoint::matchedReferencePoints.
|
inlineinherited |
Get the pointer to the complete list of reference points. The pointer is const. Thus the points can not be modified
Definition at line 115 of file vpBasicKeyPoint.h.
|
inline |
Return the blur option. The Blur option is used to activate a filter used to blur the input image. The blurring can improve the robustness of the detection.
Definition at line 291 of file vpFernClassifier.h.
Referenced by matchPoint(), and train().
|
inline |
Return the blur sigma (for the filter) option.
Definition at line 298 of file vpFernClassifier.h.
Referenced by matchPoint(), and train().
|
inline |
return the blur size (for the filter) option
Definition at line 305 of file vpFernClassifier.h.
Referenced by matchPoint(), and train().
|
inline |
Return a reference on the vector of current points in the OpenCV format
Definition at line 319 of file vpFernClassifier.h.
Referenced by vpPlanarObjectDetector::matchPoint().
|
inlineinherited |
Return the vector of current image point.
Definition at line 212 of file vpBasicKeyPoint.h.
|
inlineinherited |
Get the nth matched reference point index in the complete list of reference point.
In the code below referencePoint1 and referencePoint2 correspond to the same matched reference point.
Definition at line 173 of file vpBasicKeyPoint.h.
References vpException::fatalError, and vpTRACE.
|
inlineinherited |
Get the number of matched points.
Definition at line 194 of file vpBasicKeyPoint.h.
|
inlineinherited |
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 143 of file vpBasicKeyPoint.h.
References vpException::fatalError, vpImagePoint::set_ij(), and vpTRACE.
|
inlineinherited |
Return the index of the matched associated to the current image point i. The ith element of the vector is the index of the reference image point matching with the current image point.
Definition at line 223 of file vpBasicKeyPoint.h.
|
inline |
Return the region of interest in the OpenCV format
Definition at line 324 of file vpFernClassifier.h.
Referenced by vpPlanarObjectDetector::load().
|
inlineinherited |
Return the vector of reference image point.
Definition at line 203 of file vpBasicKeyPoint.h.
|
inlineinherited |
Get the nth reference point. This point is copied in the vpImagePoint instance given in argument.
index | : The index of the desired reference point. The index must be between 0 and the number of reference points - 1. |
referencePoint | : The coordinates of the desired reference point are copied there. |
Definition at line 125 of file vpBasicKeyPoint.h.
References vpException::fatalError, vpImagePoint::set_ij(), and vpTRACE.
|
inlineinherited |
Get the number of reference points.
Definition at line 187 of file vpBasicKeyPoint.h.
|
inline |
Return a reference on the vector of reference points in the OpenCV format
Definition at line 312 of file vpFernClassifier.h.
Referenced by vpPlanarObjectDetector::matchPoint().
|
protectedvirtual |
initialise any OpenCV parameters
The classifier need to be trained again or to be loaded from an external file.
Implements vpBasicKeyPoint.
Definition at line 111 of file vpFernClassifier.cpp.
References blurImage, ClassifierSize, curIplImg, dist, hasLearn, nbClassfier, nbMinPoint, nbOctave, nbPoints, nbView, patchSize, radius, radiusBlur, sigmaBlur, and threshold.
void vpFernClassifier::load | ( | const std::string & | _dataFile, |
const std::string & | |||
) |
load the Fern classifier
Load and initialize the Fern classifier and load the 3D and 2D keypoints. It can take up to sevral seconds.
_dataFile | : The name of the data filename (very large text file). It can have any file extension. |
Definition at line 475 of file vpFernClassifier.cpp.
References dist, fernClassifier, hasLearn, ldetector, modelPoints, modelROI, nbOctave, nbView, patchSize, radius, and threshold.
Referenced by vpPlanarObjectDetector::load(), and vpFernClassifier().
|
virtual |
Compute the points of interest in the current image and try to match them using the trained classifier. The matched pairs can be found with the getMatchedPointByRef function.
vpException::notInitialised | if the classifier has not been trained. |
_I | : The gray scaled image where the points are computed. |
Implements vpBasicKeyPoint.
Definition at line 292 of file vpFernClassifier.cpp.
References curIplImg, curPt, vpBasicKeyPoint::currentImagePointsList, fernClassifier, getBlurSetting(), getBlurSigma(), getBlurSize(), hasLearn, imgKeypoints, ldetector, vpBasicKeyPoint::matchedReferencePoints, modelPoints, vpException::notInitialized, refPt, setImage(), and vpERROR_TRACE.
Referenced by vpPlanarObjectDetector::matchPoint(), and matchPoint().
|
virtual |
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 |
Implements vpBasicKeyPoint.
Definition at line 372 of file vpFernClassifier.cpp.
References vpImageTools::createSubImage(), vpImagePoint::get_i(), vpImagePoint::get_j(), vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), matchPoint(), vpImageException::notInTheImage, and vpTRACE.
|
virtual |
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 |
Implements vpBasicKeyPoint.
Definition at line 405 of file vpFernClassifier.cpp.
References vpRect::getHeight(), vpRect::getLeft(), vpRect::getTop(), vpRect::getWidth(), matchPoint(), vpImagePoint::set_i(), and vpImagePoint::set_j().
void vpFernClassifier::record | ( | 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 505 of file vpFernClassifier.cpp.
References fernClassifier, ldetector, modelPoints, and modelROI_Ref.
Referenced by vpPlanarObjectDetector::recordDetector().
|
inlineinherited |
Indicate wether the reference has been built or not.
Definition at line 108 of file vpBasicKeyPoint.h.
|
inline |
The image is blurred before being processed. This solution can lead to a better recognition rate.
_blur | : the new option for the blur |
Definition at line 281 of file vpFernClassifier.h.
|
inline |
|
protected |
Set the current image. This method allows to convert a image from the ViSP format to the OpenCV one.
_I | : the input image. |
Definition at line 534 of file vpFernClassifier.cpp.
References vpImage< Type >::bitmap, vpImageConvert::convert(), curIplImg, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), vpException::memoryAllocationError, and vpException::notInitialized.
Referenced by buildReference(), and matchPoint().
|
protected |
Train the classifier.
Definition at line 137 of file vpFernClassifier.cpp.
References curIplImg, dist, fernClassifier, gen, getBlurSetting(), getBlurSigma(), getBlurSize(), hasLearn, ldetector, modelPoints, modelROI, modelROI_Ref, nbOctave, nbView, objKeypoints, patchSize, radius, vpBasicKeyPoint::referenceImagePointsList, and threshold.
Referenced by buildReference().
|
protectedinherited |
flag to indicate if the reference has been built.
Definition at line 249 of file vpBasicKeyPoint.h.
Referenced by vpKeyPointSurf::buildReference(), and buildReference().
|
protected |
Flag to specify whether the reference image have to be blurred or not in order to improve the recognition rate.
Definition at line 215 of file vpFernClassifier.h.
Referenced by init().
|
protected |
|
protected |
The current image in the OpenCV format.
Definition at line 225 of file vpFernClassifier.h.
Referenced by init(), matchPoint(), setImage(), train(), and ~vpFernClassifier().
|
protected |
Definition at line 238 of file vpFernClassifier.h.
Referenced by matchPoint().
|
protectedinherited |
List of the points which belong to the current image and have been matched with points belonging to the reference.
Definition at line 238 of file vpBasicKeyPoint.h.
Referenced by vpKeyPointSurf::display(), display(), vpKeyPointSurf::matchPoint(), and matchPoint().
|
protected |
Minimal distance between two points.
Definition at line 199 of file vpFernClassifier.h.
|
protected |
The Fern classifier.
Definition at line 184 of file vpFernClassifier.h.
Referenced by load(), matchPoint(), record(), and train().
|
protected |
The patch generator (OpenCV format).
Definition at line 187 of file vpFernClassifier.h.
Referenced by train().
|
protected |
Flag to indicate whether the classifier has been trained or not.
Definition at line 191 of file vpFernClassifier.h.
Referenced by init(), load(), matchPoint(), and train().
|
protected |
the vector containing the points in the current image.
Definition at line 236 of file vpFernClassifier.h.
Referenced by matchPoint().
|
protected |
The points of interest detector.
Definition at line 181 of file vpFernClassifier.h.
Referenced by load(), matchPoint(), record(), and train().
|
protectedinherited |
Array containing the index in the array "referenceImagePointsList" of the reference points which have been matched.
The first element of the "currentImagePointsList" array is matched with the nth element of the "referenceImagePointsList" array. The value of n is stored in the first element of the "matchedReferencePoints" array.
Definition at line 246 of file vpBasicKeyPoint.h.
Referenced by vpKeyPointSurf::display(), display(), vpKeyPointSurf::matchPoint(), and matchPoint().
|
protected |
the vector containing the points in the model.
Definition at line 234 of file vpFernClassifier.h.
Referenced by load(), matchPoint(), record(), and train().
|
protected |
the ROI for the reference image.
Definition at line 232 of file vpFernClassifier.h.
|
protected |
the ROI in the reference image.
Definition at line 230 of file vpFernClassifier.h.
Referenced by buildReference(), record(), and train().
|
protected |
|
protected |
Number of minimum point below which the homography is not estimated (must be at least four)
Definition at line 222 of file vpFernClassifier.h.
Referenced by init().
|
protected |
Number of octave for the multi scale.
Definition at line 205 of file vpFernClassifier.h.
|
protected |
|
protected |
Number of view to generate for the training.
Definition at line 197 of file vpFernClassifier.h.
|
protected |
keypoints detected in the reference image.
Definition at line 228 of file vpFernClassifier.h.
Referenced by buildReference(), and train().
|
protected |
Size of the patch.
Definition at line 207 of file vpFernClassifier.h.
|
protected |
Radius for the detector.
Definition at line 209 of file vpFernClassifier.h.
|
protected |
Radius of the kernel used to blur the image.
Definition at line 217 of file vpFernClassifier.h.
Referenced by init().
|
protectedinherited |
List of the points which define the reference.
Definition at line 232 of file vpBasicKeyPoint.h.
Referenced by vpKeyPointSurf::buildReference(), vpKeyPointSurf::display(), display(), vpKeyPointSurf::getDescriptorParamReferencePoint(), vpKeyPointSurf::getDescriptorReferencePoint(), vpKeyPointSurf::getLaplacianReferencePoint(), and train().
|
protected |
vector in the OpenCV format to be used by the detector.
Definition at line 238 of file vpFernClassifier.h.
Referenced by matchPoint().
|
protected |
Sigma of the kernel used to blur the image.
Definition at line 219 of file vpFernClassifier.h.
Referenced by init().
|
protected |
Threshold to accept or reject points (usually around 20)
Definition at line 195 of file vpFernClassifier.h.