43 #include <visp/vpConfig.h>
45 #if (VISP_HAVE_OPENCV_VERSION >= 0x020000) // Require opencv >= 2.0.0
47 #include <visp/vpFernClassifier.h>
48 #include <visp/vpImageTools.h>
49 #include <visp/vpImageConvert.h>
50 #include <visp/vpColor.h>
51 #include <visp/vpDisplay.h>
57 vpFernClassifier::vpFernClassifier():
vpBasicKeyPoint(), gen(0, 256, 5, true, 0.6, 1.5, -CV_PI/2, CV_PI/2, -CV_PI/2, CV_PI/2)
75 this->
load(_dataFile, _objectName);
140 std::vector<cv::Mat> objpyr;
141 cv::buildPyramid(obj, objpyr, d.nOctaves-1);
149 modelROI = cv::Rect(0, 0, objpyr[0].cols, objpyr[0].rows);
154 cv::FernClassifier::COMPRESSION_NONE,
gen);
158 for (
unsigned int i = 0; i <
modelPoints.size(); i += 1){
214 const unsigned int _height,
const unsigned int _width)
218 vpTRACE(
"Bad size for the subimage");
220 "Bad size for the subimage"));
225 (
unsigned int)_iP.
get_i(),
226 (
unsigned int)_iP.
get_j(),
227 _height, _width, subImage);
267 (
unsigned int)_rectangle.
getWidth()));
298 std::vector<cv::Mat> imgPyr;
299 cv::buildPyramid(img, imgPyr,
ldetector.nOctaves-1);
306 std::vector<int> bestMatches(m, -1);
307 std::vector<float> maxLogProb(m, -FLT_MAX);
308 std::vector<float> signature;
309 unsigned int totalMatch = 0;
316 for(
unsigned int i = 0; i < n; i++ ){
318 kpt.pt.x /= (float)(1 << kpt.octave);
319 kpt.pt.y /= (float)(1 << kpt.octave);
320 int k =
fernClassifier(imgPyr[(
unsigned int)kpt.octave], kpt.pt, signature);
321 if( k >= 0 && (bestMatches[(
unsigned int)k] < 0 || signature[(
unsigned int)k] > maxLogProb[(
unsigned int)k]) ){
322 maxLogProb[(
unsigned int)k] = signature[(
unsigned int)k];
323 bestMatches[(
unsigned int)k] = (
int)i;
336 for(
unsigned int i = 0; i < m; i++ ){
337 if( bestMatches[i] >= 0 ){
364 const unsigned int _height,
const unsigned int _width)
368 vpTRACE(
"Bad size for the subimage");
370 "Bad size for the subimage"));
376 (
unsigned int)_iP.
get_i(),
377 (
unsigned int)_iP.
get_j(),
378 _height, _width, subImage);
403 (
unsigned int)_rectangle.
getWidth()));
467 std::cout <<
" > Load data for the planar object detector..." << std::endl;
470 cv::FileStorage fs(_dataFile, cv::FileStorage::READ);
471 cv::FileNode node = fs.getFirstTopLevelNode();
473 cv::FileNodeIterator it = node[
"model-roi"].begin(), it_end;
479 const cv::FileNode node_ = node[
"model-points"];
498 cv::FileStorage fs(_dataFile, cv::FileStorage::WRITE);
500 cv::WriteStructContext ws(fs, _objectName, CV_NODE_MAP);
503 cv::WriteStructContext wsroi(fs,
"model-roi", CV_NODE_SEQ + CV_NODE_FLOW);
548 std::cout <<
"!> conversion failed" << std::endl;
void set_j(const double j)
class that defines what is a Keypoint. This class provides all the basic elements to implement classe...
virtual ~vpFernClassifier()
std::vector< cv::KeyPoint > imgKeypoints
the vector containing the points in the current image.
bool blurImage
Flag to specify whether the reference image have to be blurred or not in order to improve the recogni...
unsigned int getWidth() const
bool hasLearn
Flag to indicate whether the classifier has been trained or not.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
virtual unsigned int matchPoint(const vpImage< unsigned char > &I)
Type * bitmap
points toward the bitmap
Class to define colors available for display functionnalities.
int nbClassfier
Number of classifier.
int nbView
Number of view to generate for the training.
cv::Rect modelROI_Ref
the ROI in the reference image.
void setImage(const vpImage< unsigned char > &_I)
void set_i(const double i)
cv::PatchGenerator gen
The patch generator (OpenCV format).
unsigned int nbMinPoint
Number of minimum point below which the homography is not estimated (must be at least four) ...
error that can be emited by ViSP classes.
cv::LDetector ldetector
The points of interest detector.
static const vpColor green
int radius
Radius for the detector.
int nbPoints
Maximal number of points.
std::vector< cv::Point2f > curPt
virtual unsigned int buildReference(const vpImage< unsigned char > &I)
int patchSize
Size of the patch.
int sigmaBlur
Sigma of the kernel used to blur the image.
int nbOctave
Number of octave for the multi scale.
bool _reference_computed
flag to indicate if the reference has been built.
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
std::vector< vpImagePoint > referenceImagePointsList
void record(const std::string &_objectName, const std::string &_dataFile)
record the Ferns classifier in the text file
std::vector< cv::KeyPoint > objKeypoints
keypoints detected in the reference image.
int threshold
Threshold to accept or reject points (usually around 20)
cv::FernClassifier fernClassifier
The Fern classifier.
int dist
Minimal distance between two points.
std::vector< unsigned int > matchedReferencePoints
std::vector< cv::Point2f > refPt
vector in the OpenCV format to be used by the detector.
unsigned int getHeight() const
Defines a rectangle in the plane.
int radiusBlur
Radius of the kernel used to blur the image.
std::vector< vpImagePoint > currentImagePointsList
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
IplImage * curIplImg
The current image in the OpenCV format.
void load(const std::string &_dataFile, const std::string &)
load the Fern classifier
virtual void display(const vpImage< unsigned char > &Iref, const vpImage< unsigned char > &Icurrent, unsigned int size=3)
std::vector< cv::KeyPoint > modelPoints
the vector containing the points in the model.
int ClassifierSize
Size of the classifier.
cv::Rect modelROI
the ROI for the reference image.