Ask Your Question

magarwal's profile - activity

2019-08-20 03:38:55 -0600 received badge  Popular Question (source)
2019-08-20 03:38:55 -0600 received badge  Notable Question (source)
2013-04-16 21:20:06 -0600 commented answer When does the training exactly takes place in FlannBasedMatcher in OpenCV?

True. This is the line where index is built:

flannIndex = new flann::Index( mergedDescriptors.getDescriptors(), *indexParams );

2013-04-16 21:19:37 -0600 received badge  Supporter (source)
2013-02-23 22:41:11 -0600 asked a question When does the training exactly takes place in FlannBasedMatcher in OpenCV?

The following code is in C++ and I am using OpenCV for my experiment. Suppose I am using kd-tree (FlannBasedMatcher) in the following way:

//these are inputs to the code snippet below. 
//They are filled with suitable values
Mat& queryDescriptors;
vector<Training> &trainCollection;
vector< vector<DMatch> >& matches;
int knn;

//setting flann parameters
const Ptr<flann::IndexParams>& indexParams=new flann::KDTreeIndexParams(4);
const Ptr<flann::SearchParams>& searchParams=new flann::SearchParams(64);
FlannBasedMatcher matcher(indexParams, searchParams);

for (int i = 0; i < trainCollection.size();i++){
    Training train = trainCollection.at(i);  
    Mat trainDescriptors(train.trainDescriptors);
    trainDescriptorCollection.push_back(trainDescriptors);
}
matcher.add(trainDescriptorCollection);
matcher.train();

//Now, we may do knnMatch (or anyother matching) 
matcher.knnMatch(queryDescriptors,matches,knn);

In the above code it seems that training takes place (i.e. kd-tree is built) on calling the train() function. But here is the catch, if we look inside the train() function:

void FlannBasedMatcher::train()
{
    if( flannIndex.empty() || mergedDescriptors.size() < addedDescCount )
    {
        mergedDescriptors.set( trainDescCollection );
        flannIndex = new flann::Index( mergedDescriptors.getDescriptors(), *indexParams );
    }
}

Both of these operations (setting training descriptors and flann index, I have already done before calling train()). So when exactly is the kd-tree built?

2012-09-17 23:48:46 -0600 received badge  Student (source)
2012-09-17 18:01:32 -0600 asked a question Installing OpenCV on windows7 machine

After compiling source codes, i tried running Build/bin/Debug/contours.exe but it gave the following error:

image description