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

memory leak when creating local opencv mat object

本文关键字:内存 泄漏 对象 mat opencv 创建      更新时间:2023-10-16

我有一个函数,我做了一个mat操作。

  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