Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why does BinaryDescriptor::compute give segfault when modifying the input KeyLine vector

I am using OpenCV 3.0.0-rc1. I want to detect lines, filter according to line length and compute the descriptors. However, it always gives a segfault and I don't get why it does so. When I don't use the filtered keylines vector (created by the function keylineLengthFilter), but the original keylines vector, it works perfectly. Or when I set min_length = 0.0, it also works. When I set it to, e.g., min_length = 10.0, it still detects a non-zero number of keylines, but segfault occurs. The documentation where I got example code from is here. Any help is greatly appreciated!

My code is:

The length filter:

vector<KeyLine> keylineLengthFilter(vector<KeyLine>& keylines, const float &length)
    {
      /* keyline filter that returns a binary vector of keyline entries with length larger than input value */
      vector<KeyLine> keylines_filtered;
      for (int i = 0; i < (int)keylines.size(); ++i)
      {
        if (keylines[i].lineLength >= length)
        {
          keylines_filtered.push_back(keylines[i]);
        }
      }
      return keylines_filtered;
    }

The Code: (image, min_length and mask are not included here, but that part works fine on my original code)

vector<KeyLine> keylines_filtered;
      /* create a pointer to an LSDDetector object */
      Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor();
      /* create a pointer to a BinaryDescriptor object with default parameters */
      Ptr<LSDDetector> lsd = LSDDetector::createLSDDetector();
      /* compute lines */
      lsd->detect(image, keylines, 2, 1, mask);
      /* filter keylines */
      keylines_filtered = keylineLengthFilter(keylines, min_length);

      // THE SEGFAULT HAPPENS HERE, but only when I use keylines_filtered as argument:
      /* compute descriptors */
      bd->compute(image, keylines_filtered, descriptors); // this gives segfault 
      bd->compute(image, keylines, descriptors); // this works