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){
215 const unsigned int _height,
const unsigned int _width)
219 vpTRACE(
"Bad size for the subimage");
221 "Bad size for the subimage"));
226 (
unsigned int)_iP.
get_i(),
227 (
unsigned int)_iP.
get_j(),
228 _height, _width, subImage);
268 (
unsigned int)_rectangle.
getWidth()));
299 std::vector<cv::Mat> imgPyr;
300 cv::buildPyramid(img, imgPyr,
ldetector.nOctaves-1);
307 std::vector<int> bestMatches(m, -1);
308 std::vector<float> maxLogProb(m, -FLT_MAX);
309 std::vector<float> signature;
310 unsigned int totalMatch = 0;
317 for(
unsigned int i = 0; i < n; i++ ){
319 kpt.pt.x /= (float)(1 << kpt.octave);
320 kpt.pt.y /= (float)(1 << kpt.octave);
321 int k =
fernClassifier(imgPyr[(
unsigned int)kpt.octave], kpt.pt, signature);
322 if( k >= 0 && (bestMatches[(
unsigned int)k] < 0 || signature[(
unsigned int)k] > maxLogProb[(
unsigned int)k]) ){
323 maxLogProb[(
unsigned int)k] = signature[(
unsigned int)k];
324 bestMatches[(
unsigned int)k] = (
int)i;
337 for(
unsigned int i = 0; i < m; i++ ){
338 if( bestMatches[i] >= 0 ){
365 const unsigned int _height,
const unsigned int _width)
369 vpTRACE(
"Bad size for the subimage");
371 "Bad size for the subimage"));
377 (
unsigned int)_iP.
get_i(),
378 (
unsigned int)_iP.
get_j(),
379 _height, _width, subImage);
404 (
unsigned int)_rectangle.
getWidth()));
468 std::cout <<
" > Load data for the planar object detector..." << std::endl;
471 cv::FileStorage fs(_dataFile, cv::FileStorage::READ);
472 cv::FileNode node = fs.getFirstTopLevelNode();
474 cv::FileNodeIterator it = node[
"model-roi"].begin(), it_end;
480 const cv::FileNode node_ = node[
"model-points"];
499 cv::FileStorage fs(_dataFile, cv::FileStorage::WRITE);
501 cv::WriteStructContext ws(fs, _objectName, CV_NODE_MAP);
504 cv::WriteStructContext wsroi(fs,
"model-roi", CV_NODE_SEQ + CV_NODE_FLOW);
549 std::cout <<
"!> conversion failed" << std::endl;