0

I'm working on a piece of code that performs feature matching with 128 dimensional descriptors.

All descriptors for an image are stored in a std::vector, where InterestPoint contains a member *double desc, which is the descriptorvector.

Now I want to use this structure in a Flann Matrix to later do Approximate Nearest Neighbor feature matching, which I initialize as such:

std::vector<InterestPoint> ip1;
//processing for building vector containing interest points
flann::Matrix<double> input(new double[ip1.size()*128], ip1.size(),  128);

How can I now fill this flann::Matrix with the *double desc members from every element of the ip1 vector? This is what I tried:

for(size_t i = 0; i < ip1.size(); i++)
{
    for(size_t j = 0; j < 128; j++)
    {
        input[i][j] = ip1[i].ivec[j];
    }
}

Compiled but didn't work out. flann offers a way to access every row of the flann::Matrix, using the operator [], the Matrix class is thus row major.

Thanks in advance,

filipsch
  • 195
  • 1
  • 10
  • 2
    Can you clarify what "didn't work out" means? Have you tried stepping through the loop to check that the values of ip1 and input at the indices you're accessing are valid? – aardvarkk Mar 28 '13 at 20:00
  • I did what you told, and indeed, there wasn't a problem putting my pointers in Flann, the problem was that my pointers were, for some reason or the other, not valid in the function I called. Thanks anyway for your time! – filipsch Apr 02 '13 at 11:07

1 Answers1

0

I'm not sure what inside "InterestPoint". But I think this sample code will help.

struct MyPoint
{
    MyPoint (double x, double y, double z) {this->x=x; this->y=y; this->z=z;}
    double x,y,z;
};

std::vector<MyPoint> points;
points.push_back(MyPoint(0, 0, 0));
points.push_back(MyPoint(1, 1, 1));
points.push_back(MyPoint(-1, -1, -1));
flann::Matrix<double> points_mat = flann::Matrix<double>(&points[0].x, points.size(), 3);
GroupDoll
  • 1
  • 1