0

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.

Bei
  • 71
  • 6
  • Can you give us more details on what you are trying to achieve, small portion of your code, images with desired output? – ivan_a Dec 06 '13 at 06:52
  • hi, I've add a code block to show what I'm doing. – Bei Dec 06 '13 at 13:34
  • I would suggest using other detectors and descriptors with are much faster. Examples of detectors: FAST,BRISK,ORB,STAR, examples of descriptors: BRISK,BRIEF,ORB,FREAK. Those are binary descriptors. I can refer you to some post I wrote about binary descriptors if you'd like. – GilLevi Dec 07 '13 at 19:13
  • that's a common problem... I guess you will have to look at the openCV sourcecode of SIFT implementation and encapsulate the functions in the way you need them [computePyramid => save pyramid => computeFeatures(pyramid) => computeDescriptors(features, pyramid)] and recompile your modified openCV. If unlucky, openCV just gives headers and library because there's a patent on SIFT and it's in nonfree library, don't know. – Micka Dec 09 '13 at 13:52

1 Answers1

0

A fast solution is to call sift(...) just once with all the locations you use:

for (int i=0 ; i<n ; ++i)
  locations.push_back(KeyPoint(x[i],y[i],sigma[i]));
//do something...
const size_t N = locations.size();

for (int j=n ; j<2*n; ++j)
  locations.push_back(KeyPoint(x[j],y[j],sigma[j]));

sift (image, noArray(), locations, descriptors);

// locations[0..N-1] are the first ones, locations[N..size()-1] are the others
ChronoTrigger
  • 8,459
  • 1
  • 36
  • 57
  • Sure, but I can't decide all the locations before some of the descriptors are computed. – Bei Dec 07 '13 at 02:24