内存泄漏使用OpenCV CascadeClassifier

时间:2015-02-22 10:43:41

标签: c++ opencv valgrind cascade-classifier

我正在编写一个使用PCL kinfu的程序,我正在使用openCV人脸检测。我有一些堆问题,所以我隔离了openCV的代码,试图检查问题是否在那边。在评论出几乎所有内容后,我发现了一些奇怪的东西。只有一个'CascadeClassifier'类的全局声明,它会导致valgrind警告可能丢失且仍然可以访问的块。评论此声明可以正常工作。我真的不确定发生了什么,并希望得到任何帮助。 我正在附上我有问题的代码(没有注释掉的部分)。 谢谢!

#include "opencv2/objdetect/objdetect.hpp"

using namespace cv;
CascadeClassifier c;

int main() {
    return 0;
}

**Valgrind output:**
==3316== Memcheck, a memory error detector
==3316== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==3316== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==3316== Command: ./test
==3316== 
==3316== 
==3316== HEAP SUMMARY:
==3316==     in use at exit: 297,370 bytes in 1,393 blocks
==3316==   total heap usage: 3,446 allocs, 2,053 frees, 655,130 bytes allocated
==3316== 
==3316== LEAK SUMMARY:
==3316==    definitely lost: 0 bytes in 0 blocks
==3316==    indirectly lost: 0 bytes in 0 blocks
==3316==      possibly lost: 4,676 bytes in 83 blocks
==3316==    still reachable: 292,694 bytes in 1,310 blocks
==3316==         suppressed: 0 bytes in 0 blocks
==3316== Rerun with --leak-check=full to see details of leaked memory
==3316== 
==3316== For counts of detected and suppressed errors, rerun with: -v
==3316== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

2 个答案:

答案 0 :(得分:1)

对我来说,有两种可能的解释:

  1. 如果您信任Valgrind - 可能是opencv代码中的一些泄漏,因此有人应该从opencv devs中详细调查它(为什么不用这个问题创建一个合适的票证?)
    1. 没有任何泄漏,因为你明显有可能'在那里说。然后你就不在乎了。在您注释掉某些代码之前,您在开始时遇到了什么样的堆问题?
    2. 建议不要在全局范围(静态内存)中使用非POD(普通旧数据)的类。将CascadeClassifier对象移动到本地范围(main())时是否有同样的问题?

答案 1 :(得分:1)

再试一次:

#include "opencv2/objdetect/objdetect.hpp"

using namespace cv;

void testmem() {
    CascadeClassifier c;
}

int main() {
    for (int i=0; i<10; i++)
        testmem();
    return 0;
}
相关问题