Ask Your Question

ianni67's profile - activity

2016-09-16 06:45:06 -0600 received badge  Student (source)
2014-04-09 02:43:15 -0600 commented question Why is SIFT faster than SURF ? It shouldn't be.

Is it SURF which became slower or it's SIFT which has been speeded-up?

2014-03-27 10:26:45 -0600 asked a question error: (-215) (globalDescIdx>=0) && (globalDescIdx < size()) in function getLocalIdx

Hi all, I consistently get this error if I use BOWImgDescriptorExtractor::compute "close to" a read from a video (either from file or from webcam).

error: (-215) (globalDescIdx>=0) && (globalDescIdx < size()) in function getLocalIdx

The frame is not empty and the mad point is that this error is thrown even if I apply the function to an image which is not the one acquired from the video. In other words, the exception is thrown just when the two instructions (image acquisition and compute) appear close to each other in the program, no matter what is the image passed to compute().

I'm stuck, please help. I'm attaching my source code.

#define OPENCV2P4
#include <opencv2/contrib/openfabmap.hpp>
#include <fstream>
#ifdef OPENCV2P4
#include <opencv2/nonfree/nonfree.hpp>
#endif
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/features2d.hpp"

using namespace cv;

void readme(char **av);


of2::FabMap *generateFABMAPInstance(cv::FileStorage &settings);


int main( int argc, char** argv )
{
  int minHessian = 400;
  cv::Ptr<cv::DescriptorExtractor> extractor = NULL;
  cv::Ptr<cv::FeatureDetector> detector = NULL;

  detector = new cv::SurfFeatureDetector(minHessian);

  extractor = new SurfDescriptorExtractor();


cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("FlannBased");

cv::BOWImgDescriptorExtractor bide(extractor, matcher);

  Mat img_object;
  cv::Mat frame;  
  Mat templ_bow;
  Mat scene_bow;
  std::vector<KeyPoint> keypoints_object;
  std::vector<KeyPoint> keypoints_scene;
  Mat descriptors_object;
  bool ref_live = true;
  Mat fabmapTemplateData;
// Loads a vocabulary and a template image.
// Then opens a video stream (live) and matches the template with
// the video, signaling when the template matches the current live frame

  if( (argc <3) || (argc>4) )
  { readme(argv); return -1; }

  cv::FileStorage fs;
  //load vocabulary
  std::cout << "Loading Vocabulary" << std::endl;
  fs.open(argv[2], cv::FileStorage::READ);
  cv::Mat vocab;
  fs["Vocabulary"] >> vocab;
  if (vocab.empty()) {
    std::cerr << argv[2] << ": Vocabulary not found" << std::endl;
    return -1;
  }
  fs.release();
  bide.setVocabulary(vocab);
   //load template
  if( argc == 4 )
  {
    img_object = imread( argv[3] ); 
    if( !img_object.data)
       { std::cout<< " --(!) Error in reading template " << std::endl; return -1; }
    detector->detect(img_object, keypoints_object);

    bide.compute(img_object, keypoints_object, templ_bow); //here it works!

    fabmapTemplateData.push_back(templ_bow);    

    ref_live=false;
    std::cout<< " --Template was correctly read and processed." << std::endl;
  }

  //Load the settings file and init FabMAP
  /*
  std::string settfilename;
  settfilename="settings.yml";
  fs.open(settfilename, cv::FileStorage::READ);
  if (!fs.isOpened()) {
        std::cerr << "Could not open settings file: " << settfilename << 
            std::endl;
        return -1;
    }
  of2::FabMap *fabmap = generateFABMAPInstance(fs);  
  fs.release();
  if(!fabmap) { std::cout<< " --(!) Error reading in fabMAP " << std::endl; return -1; }
  */

  //Init video capture
  VideoCapture capture;
  capture.open(argv[1]);
  //capture.open(atoi(argv[1]));
  if (!capture.isOpened())
  {
     readme(argv);
     std::cout << "capture device " << atoi(argv[1]) << " failed to open!" << std::endl;
     return 1;
  }

  std::vector<of2::IMatch> matches;

  //START LOOP

//bide.compute(img_object, keypoints_object, templ_bow); \\HERE IT DOES NOT WORK

while(capture.read(frame))
    {

    cv::Mat testImageDescs;
    //Calculate and store the BOW representation of the current frame #####QUI
    detector->detect(frame, keypoints_scene);
    std::cout << 100.0*(capture.get(CV_CAP_PROP_POS_FRAMES ...
(more)
2014-03-26 08:35:03 -0600 commented question throwing exception in matching function

Hello did you find a solution? I'm afraid I'm experiencing the same problems.