Вопрос

I would like to store all my precalculated Keypoints/decriptors of several images in a Mat list/structure or something, so I could be able to use them later to match them with others image descriptors. Do you have an idea?

Apparently, there is a way to use

List<Mat>

but i dont know how.

Это было полезно?

Решение

You store the descriptor of one image in one Mat variable. So, basically you have one Mat for one descriptors. So, if you have 100 descriptors then, all of these decriptors should be present in a single Mat. You can do it as following:

Step-1: Declare a vector of Mat type.

vector<Mat> allDescriptors;

Step-2: Then find descriptors for each image and store it in Mat format

Mat newImageDescriptor;

Step-3: finally, push the descriptor calculated above into the vector.

allDescriptors.push_back(newImageDescriptor);

Repeat step-2 & 3 for all of your images

Now, you can access them as following:

You can access the data in vector as you do it in case of arrays

so allDescriptors[0] will give you the first descriptor in Mat format

So, by using a for loop, you can access all of your descriptors.

for(int i=0; i<allDescriptors.size(); i++)
{
    Mat accessedDescriptor;
    allDescriptors[i].copyTo(accessedDescriptor);
}

Другие советы

If your elements are stored in contiguous array you can assign them to a list at once with:

#include <list>
std::list<Mat> l;
l.assign( ptr, ptr + sz); // where ptr is a pointer to array of Mat s
                          // and sz is the size of array

Create precalculated elements:

Mat mat1;
Mat mat2;

And the list of elements of this type:

#include <list>
std::list<Mat> l;

Add elements to list:

l.push_back( mat1);
l.push_back( mat2)

note: there are other modifiers that you can use to insert elements. You will find a description of them here. There are other containers which usage you can consider. Selection of appropriate container is very important. You have to take into account the operations that will be crucial to you, which will be called most often.

This is regarding to your another question of copying the vector<Mat> to another vector<Mat>

Lets say you have one vector vector<Mat> des1 and you want to copy it to vector<Mat> des2 then you should do the following:

for(int i=0; i<des1.size(); i++)
{
    des1[i].copyTo(des2[i]);
}

Remember that vector<Mat> is something like an arrya of Mat. So, how can you copy a vector to another vector by CopyTo which is used to copy a Matrix.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top