What is `query` and `train` in openCV features2D
Asked Answered
A

3

20

Everywhere in features2D classes I see terms query and train. For example matches have trainIdx and queryIdx, and Matchers have train() method.

I know the definition of words train and query in English, but I can't understand the meaning of this properties or methods.

P.S. I understand, that it's very silly question, but maybe it's because English is not my native language.

Alguire answered 26/5, 2012 at 9:23 Comment(0)
R
22

To complete sansuiso's answer, I suppose the reason for choosing these names should be that in some application we have got a set of images (training images) beforehand, for example 10 images taken inside your office. The features can be extracted and the feature descriptors can be computed for these images. And at run-time an image is given to the system to query the trained database. Hence the query image refers to this image. I really don't like the way they have named these parameters. Where you have a pair of stereo images and you want to match the features, these names don't make sense but you have to chose a convention say always call the left image the query image and the right image as the training image. I did my PhD in computer vision and some naming conventions in OpenCV seem really confusing/silly to me. So if you find these confusing or silly you're not alone.

Rosanarosane answered 26/5, 2012 at 17:28 Comment(4)
To put it even more simple, train is the image you learned (extracted features) beforehand, query is the image that you are trying to match with the ones trained.Marcheshvan
I used to call these things earlier in another way: I called train as ethalon and query as sample.Alguire
@Shambool, i got a question, seems silly, but confused me a lot. if i put 2 trainDescripters trainA and trainB into flann matcher for train. then comes the query image queryC, will the match algorithm be executed for both trainA and trainB with queryC?Blondell
Agree, silly names. Better as srcIdx, dstIdx or firstIdx, secondIdx.Andreeandrei
D
12
  • train: this function builds the classifier inner state in order to make it operational. For example, think of training an SVM, or building a kd-tree from the reference data. Maybe you are confused because this step is often referred to as learning in the literature.

  • query is the action of finding the nearest neighbors to a set of points, and by extension it also refers to the whole set of points for which yo want a nearest neighbor. Recall that you can ask for the neighbors of 1 point, or a whole lot in the same function call (by stacking the feature points in a matrix).

  • trainIdxand queryIdx refer to the index of a pint in the reference / query set respectively, i.e. you ask the matcher for the nearest point (stored at the trainIdx position) to some other point (stored at the queryIdxposition). Of course, trainIdxis known after the function call. If your points are stored in a matrix, the index will be the line of the considered feature.

Deangelo answered 26/5, 2012 at 13:39 Comment(5)
This answer makes it clear that trainIdx and queryIdx refer to the first and second (descriptor/keypoint) sets, respectively.Slurp
@GregKramida I think it is the other way around. When the matches are obtained with matcher.match(descriptors1, descriptors2, matches), then queryIdx will index into keypoints1 and trainIdx into keypoints2. c.f. https://mcmap.net/q/572308/-opencv-drawmatches-queryidx-and-trainidxMerrell
@oarfish, yes, you're right. I wonder if I should remove the comment so it doesn't confuse anybody.Slurp
@greg "First" and "second" in what reference frame? In the knnMatch method the first argument is the query, and second is train: docs.opencv.org/3.2.0/db/d39/…Breach
@dividebyzero, yes.Slurp
B
3

I understand "query" and "train" in a very naive but useful way: "train": a data or image is preprocessed to get a database "query": an input data or image that will be queried in the database which we trained before. Hope it helps u as well.

Blende answered 15/2, 2016 at 10:51 Comment(1)
That's not naive, that is what it is. Or what it should be... It means a single train point may be assigned to more than one query point, for one thing. And also you can assign all the query points, but some train points may never be assigned.Breach

© 2022 - 2024 — McMap. All rights reserved.