c++ - 创建本地 opencv mat 对象时内存泄漏

标签 c++ opencv memory-management memory-leaks

我有一个功能,可以进行垫操作。

  void my_func()

   {

     vector<Point> my_vect=another_func();

     Mat my_array((int)my_vect.size(),1,CV_8UC1); //This line is reported as leakage

     for(int i=0;i<my_vect.size();i++)

     my_array.at<uchar>(i,1)=Other_image.at<uchar>(my_vect[i]); 

   }

最佳答案

不知道泄漏,但至少还有一个缓冲区溢出。

Mat my_array( 17, 1, CV_8UC1 ); // 17 rows, 1 col
for(int i=0; i<17; i++)
     // should be (i,0) below, (i,1) is already out of bounds
     my_array.at<uchar>(i,1) = Other_image.at<uchar>(my_vect[i]); // <-- this looks broken, too

关于c++ - 创建本地 opencv mat 对象时内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23680127/

相关文章:

macos - 将OpenCV集成到OpenGL应用程序中

c - 是否有一些 "free-able"内存

c++ - SDL2 渲染到 QWidget

当参数为真时 C++ 断言失败

opencv - 使用 cv2.COLOR_BGR2GRAY 或 color.rgb2gray 作为来自 skimage 的 hog 描述符?

c# - 如何跳过数组中的前几个元素?

iphone - 一段时间后应用程序用户界面消失

c++ - 异构可变参数非类型模板参数计数灵活吗?

c++ - 如何在另一个文件的类中声明一个函数

c++ - OpenCV C API 不允许相机释放和重新打开