# Revision history [back]

### One to Many Images by ID

Hello,

I am seeking to use 2D features to match a large amount of images.

The opencv example of one to many images

https://github.com/opencv/opencv/blob/2.4/samples/cpp/matching_to_many_images.cpp

So all this does is find that all query features were matched to the training set. How to get the id? DMatch does not contain information about the particular image it is from.

    descriptorMatcher->match( queryDescriptors, matches );
tm.stop();
double matchTime = tm.getTimeMilli();

CV_Assert( queryDescriptors.rows == (int)matches.size() || matches.empty() );


I have also looked at FLANN index, but i do not understand it well enough. First create a BOW vocabulary from the features in all training images.

While looping
Mat bowFeature = getBow2(inImg, detector, bow, featureMask2);
trainData.push_back(bowFeature.reshape(1,1));

Ptr<cv::flann::Index> index = train_index(trainData);

int K = 2;
cv::Mat dists, indices;
index->knnSearch(bowTest, indices, dists, K);
float response = indices.at<int>(0, 0)


This should give me the image id right?

I am unsure about how the index is generated.

Are there any samples of one to many image matching by id?