40 #include <visp3/core/vpConfig.h> 42 #if (VISP_HAVE_OPENCV_VERSION >= 0x020000) && \ 43 (VISP_HAVE_OPENCV_VERSION < 0x030000) // Require opencv >= 2.0.0 and < 3.0.0 45 #include <visp3/core/vpColor.h> 46 #include <visp3/core/vpDisplay.h> 47 #include <visp3/core/vpImageConvert.h> 48 #include <visp3/core/vpImageTools.h> 49 #include <visp3/vision/vpFernClassifier.h> 57 gen(0, 256, 5, true, 0.6, 1.5, -CV_PI / 2, CV_PI / 2, -CV_PI / 2, CV_PI / 2), hasLearn(false), threshold(20),
58 nbView(2000), dist(2), nbClassfier(100), ClassifierSize(11), nbOctave(2), patchSize(32), radius(7), nbPoints(200),
59 blurImage(true), radiusBlur(7), sigmaBlur(1), nbMinPoint(10),
60 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
65 objKeypoints(), modelROI_Ref(), modelROI(), modelPoints(), imgKeypoints(), refPt(), curPt()
82 gen(0, 256, 5, true, 0.6, 1.5, -CV_PI / 2, CV_PI / 2, -CV_PI / 2, CV_PI / 2),
hasLearn(false),
threshold(20),
85 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
92 this->
load(_dataFile, _objectName);
101 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 103 if (
curImg->width % 8 == 0) {
105 cvReleaseImageHeader(&
curImg);
126 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 150 cv::Mat obj = (cv::Mat)
curImg;
157 std::vector<cv::Mat> objpyr;
158 cv::buildPyramid(obj, objpyr, d.nOctaves - 1);
166 modelROI = cv::Rect(0, 0, objpyr[0].cols, objpyr[0].rows);
170 cv::FernClassifier::COMPRESSION_NONE,
gen);
174 for (
unsigned int i = 0; i <
modelPoints.size(); i += 1) {
225 const unsigned int _height,
const unsigned int _width)
228 vpTRACE(
"Bad size for the subimage");
295 cv::Mat img = this->
curImg;
302 std::vector<cv::Mat> imgPyr;
303 cv::buildPyramid(img, imgPyr,
ldetector.nOctaves - 1);
309 std::vector<int> bestMatches(m, -1);
310 std::vector<float> maxLogProb(m, -FLT_MAX);
311 std::vector<float> signature;
312 unsigned int totalMatch = 0;
318 for (
unsigned int i = 0; i < n; i++) {
320 kpt.pt.x /= (float)(1 << kpt.octave);
321 kpt.pt.y /= (float)(1 << kpt.octave);
322 int k =
fernClassifier(imgPyr[(
unsigned int)kpt.octave], kpt.pt, signature);
323 if (k >= 0 && (bestMatches[(
unsigned int)k] < 0 || signature[(
unsigned int)k] > maxLogProb[(
unsigned int)k])) {
324 maxLogProb[(
unsigned int)k] = signature[(
unsigned int)k];
325 bestMatches[(
unsigned int)k] = (
int)i;
337 for (
unsigned int i = 0; i < m; i++) {
338 if (bestMatches[i] >= 0) {
361 const unsigned int _height,
const unsigned int _width)
364 vpTRACE(
"Bad size for the subimage");
451 std::cout <<
" > Load data for the planar object detector..." << std::endl;
454 cv::FileStorage fs(_dataFile, cv::FileStorage::READ);
455 cv::FileNode node = fs.getFirstTopLevelNode();
457 cv::FileNodeIterator it = node[
"model-roi"].begin(), it_end;
463 const cv::FileNode node_ = node[
"model-points"];
481 cv::FileStorage fs(_dataFile, cv::FileStorage::WRITE);
483 cv::WriteStructContext ws(fs, _objectName, CV_NODE_MAP);
486 cv::WriteStructContext wsroi(fs,
"model-roi", CV_NODE_SEQ + CV_NODE_FLOW);
506 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408) 511 if ((
curImg->width % 8) == 0) {
513 cvReleaseImageHeader(&
curImg);
530 std::cout <<
"!> conversion failed" << std::endl;
536 #elif !defined(VISP_BUILD_SHARED_LIBS) 539 void dummy_vpFernClassifier(){};
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 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.
cv::PatchGenerator gen
The patch generator (OpenCV format).
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.
void set_i(const double ii)
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.
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.
void set_j(const double jj)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
int threshold
Threshold to accept or reject points (usually around 20)
unsigned int getHeight() const
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.
Defines a rectangle in the plane.
int radiusBlur
Radius of the kernel used to blur the image.
std::vector< vpImagePoint > currentImagePointsList
cv::Mat curImg
The current image in the OpenCV format.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
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)
void setImage(const vpImage< unsigned char > &I)
std::vector< cv::KeyPoint > modelPoints
the vector containing the points in the model.
unsigned int getWidth() const
int ClassifierSize
Size of the classifier.
cv::Rect modelROI
the ROI for the reference image.