簡體   English   中英

在opencv泄漏內存中使用CascadeClassifier的detectMultiScale嗎?

[英]Does using the detectMultiScale of the CascadeClassifier in opencv leak memory?

正如標題所說。 我正試圖在圖像上運行一個簡單的面部檢測器:

#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。

我不確定Valgrind的錯誤信息,但如果有泄漏,那肯定不在你的代碼中。 嘗試更新到2.4.2,它也快得多。

您必須釋放變量面

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM