gpt4 book ai didi

c++ - opencv namedWindow 泄漏(c++ 和 opencv)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:46:17 24 4
gpt4 key购买 nike

运行 valgrind,我在 opencv 中发现大量内存泄漏,尤其是 namedWindow 的功能。

主要是,我有一个图像 CSImg 和 PGImg:

std::string cs = "Computer Science Students";
std::string pg = "Politics and Government Students";
CSImg.displayImage(cs);
cv::destroyWindow(cs);
PGImg.displayImage(pg);
cv::destroyWindow(pg);

显示图像函数是:

void ImageHandler::displayImage(std::string& windowname){
namedWindow(windowname);
imshow(windowname, m_image);
waitKey(7000);

}

当我执行 displayImage 时,Valgrind 给我带来了巨大的内存泄漏。例如:

==6561== 2,359,544 bytes in 1 blocks are possibly lost in loss record 3,421 of 3,421
==6561== at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6561== by 0x4F6C94C: cv::fastMalloc(unsigned long) (in /usr/lib/libopencv_core.so.2.3.1)
==6561== by 0x4F53650: cvCreateData (in /usr/lib/libopencv_core.so.2.3.1)
==6561== by 0x4F540F0: cvCreateMat (in /usr/lib/libopencv_core.so.2.3.1)
==6561== by 0x56435AF: cvImageWidgetSetImage(_CvImageWidget*, void const*) (in /usr/lib/libopencv_highgui.so.2.3.1)
==6561== by 0x5644C14: cvShowImage (in /usr/lib/libopencv_highgui.so.2.3.1)
==6561== by 0x5642AF7: cv::imshow(std::string const&, cv::_InputArray const&) (in /usr/lib/libopencv_highgui.so.2.3.1)
==6561== by 0x40CED7: ImageHandler::displayImage(std::string&) (imagehandler.cpp:33)
==6561== by 0x408CF5: main (randomU.cpp:601)

imagehandler.cpp,第33行是:

imshow(windowname, m_image); //the full function is written above ^

randomU.cpp 第 601 行是:

CSImg.displayImage(cs);

感谢任何帮助。询问您需要的任何进一步信息。

最佳答案

抱歉,严酷的现实看起来像是 OpenCV 泄漏。根据 Leaks Instrument(XCode 工具),由于 self 引用,它也从其 Qt 界面的一侧泄漏。

其他证明这不仅仅是误报的证据:在我的 Mac 上,Opencv 2.4.3 在处理网络摄像头输入时在内存中不断增长(根据 Activity Monitor)。 (我没有使用任何指针或数据存储,所以理论上我的 OpenCV 程序应该保持恒定大小。)

关于c++ - opencv namedWindow 泄漏(c++ 和 opencv),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13498314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com