Detector doesn't release the KeyPoint-vector [closed]

asked 2014-05-05 07:40:17 -0500

ketza gravatar image

updated 2014-05-05 07:41:52 -0500

Hi there,

I have a weird issue concerning keypoint detection with OpenCV. It seems that the detector doesn't release its KeyPoint vector. The application crashes when the KeyPoint vector goes out of scope. When I declare the KeyPoint vector globally, the memory used by the application grows with every processed image (and with every created KeyPoint-vector) and crashes only when returning from main.

It is certainly not the code, I'm just using the basic examples. Few others also reported the same issue, but they didn't provide a solution. (See or To me it seems like an OpenCV bug, but on the other hand this popular example is working for most people.

I'm using OpenCV 2.4.1, on a Windows 7 machine with cygwin. The precompiled windows libraries (x86/mingw/lib) are used. I also tried OpenCV 2.4.6, no difference.

I'd very much appreciate any hint on what could be wrong here. Thanks!

Here's my code:

#include <opencv2/opencv.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <iostream>

int main(void) {
  std::string image_root = "D:/VZE/Workspace/TestProject/";
  std::vector<std::string> filenames;
  filenames.push_back(image_root + "image.png");
  filenames.push_back(image_root + "image2.png");

  // declaring the keypoint vector here makes the application crash when returning from main
  std::vector<cv::KeyPoint> keypoints;

  for (unsigned int index=0; index < filenames.size(); ++index)
    // read & show image
    cv::Mat mat = cv::imread(filenames[index]);
    cv::namedWindow(filenames[index], CV_WINDOW_AUTOSIZE);
    cv::moveWindow(filenames[index], 0, 0);
    cv::imshow(filenames[index], mat);

    // declaring the keypoint vector here makes the application crash after the first iteration
    // std::vector<cv::KeyPoint> keypoints;

    std::cout << "detecting keypoints:" << std::endl;
    cv::DenseFeatureDetector detector(1, 4, 1.5, 10); // I also tried the FastFeatureDetector, same here
    detector.detect(mat, keypoints);
    std::cout << "done. detected " << keypoints.size() << " keypoints" << std::endl;

    // show keypoints in output image
    cv::Mat output;
    cv::drawKeypoints(mat, keypoints, output);

    cv::namedWindow("Output", CV_WINDOW_AUTOSIZE);
    cv::moveWindow("Output", 640, 0);
    cv::imshow("Output", output);


  std::cout << "Bye!" << std::endl;

  return 0;

Built with:

g++ -g -Wall -I/cygdrive/D/VZE/Tools/OpenCV/build/include   -c -o main.o main.cpp
g++ -o main.exe main.o -L/cygdrive/D/VZE/Tools/OpenCV/build/x86/mingw/lib -lopencv_core241 -lopencv_highgui241 -lopencv_features2d241 -lopencv_nonfree241

Leads to the following output:

detecting keypoints:
done. detected 5302 keypoints
detecting keypoints:
done. detected 5302 keypoints
   1787 [main] main 13616 open_stackdumpfile: Dumping stack trace to main.exe.stackdump
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-17 11:09:27.848812


Did u get any solution ? i'm also facing same problem while using visual studio 2008 when releasing or deleting std::vector<cv::KeyPoint> keypoints.

prasaathviki gravatar imageprasaathviki ( 2014-06-26 10:14:54 -0500 )edit