I'm working with OpenCV 2.4.6 and I need to compute SIFT descriptors at different locations many times on one certain image. The code runs extremely slow. I realize that it's probably because every time I call sift(image, mask, locations, descriptors, true), OpenCV creates an image pyramid. What should I do? PS:The mask option doesn't help.
Part of the code is like this.
Mat image = imread ("test.jpg");
vector<KeyPoint> locations;
Mat descriptors;
for (int i=0 ; i<n ; ++i)
locations.push_back(KeyPoint(x[i],y[i],sigma[i]));
SIFT sift;
sift (image, noArray(), locations, descriptors);
//do something...
locations.clear();
for (int j=n ; j<2*n; ++j)
locations.push_back(KeyPoint(x[j],y[j],sigma[j]));
sift (image, noArray(), locations, descriptors);
I think OpenCV create the same image pyramid twice.
A fast solution is to call
sift(...)
just once with all the locations you use: