如标题所示。我正在尝试在图像上运行一个简单的面部检测器:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>

using namespace cv;

int main(int argc, char** argv)
{
  Mat image = imread("V2.jpg", 1);
  CascadeClassifier face_cascade;
  face_cascade.load("haarcascade_frontalface_alt.xml");
  vector<Rect> faces;
  face_cascade.detectMultiScale(image, faces);
  return 0;
}

根据valgrind,以下代码从detectMultiScale函数泄漏。我在这里有没有好的习惯?有什么要释放的吗?从逻辑上讲,所有内容都在我的栈顶上,因此应在程序结束时将其释放。

valgrind的输出是:
==4852==    at 0x4C28F9F: malloc (vg_replace_malloc.c:236)
==4852==    by 0x4EB1D90: cv::fastMalloc(unsigned long) (in /usr/lib/libopencv_core.so.2.3.1)
==4852==    by 0x58F175D: ??? (in /usr/lib/libopencv_objdetect.so.2.3.1)
==4852==    by 0x58F8699: cvHaarDetectObjectsForROC(void const*, CvHaarClassifierCascade*, CvMemStorage*, std::vector<int, std::allocator<int> >&, std::vector<double, std::allocator<double> >&, double, int, int, CvSize, CvSize, bool) (in /usr/lib/libopencv_objdetect.so.2.3.1)
==4852==    by 0x58EA38B: cv::CascadeClassifier::detectMultiScale(cv::Mat const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, std::vector<int, std::allocator<int> >&, std::vector<double, std::allocator<double> >&, double, int, int, cv::Size_<int>, cv::Size_<int>, bool) (in /usr/lib/libopencv_objdetect.so.2.3.1)
==4852==    by 0x58DA6B5: cv::CascadeClassifier::detectMultiScale(cv::Mat const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>) (in /usr/lib/libopencv_objdetect.so.2.3.1)

这是在Windows 7 64位上运行64位Kubuntu 11.10的VMware VM上运行的。 OpenCV版本是最新的-2.3.1。

最佳答案

您必须释放可变的面孔

关于c++ - 是否在opencv泄漏内存中使用CascadeClassifier的detectMultiScale?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8370154/

10-11 22:42
查看更多