void CAssimilation::DeleteObject(float **Data_AssHigh, int height, int width,int *MASK)
 {
 for (int X_pixel = 0; X_pixel <height; X_pixel++)
 {
 for (int Y_pixel = 0; Y_pixel < width; Y_pixel++)
 {
 if (Data_AssHigh[0][X_pixel*width + Y_pixel] > 0)
 {
 MASK[X_pixel*width + Y_pixel] = 255;
 //cout << MASK[X_pixel*width + Y_pixel];
 }
 }

 }

 Mat SrcImage1(height, width, CV_8UC1);
 uchar *ptmp = NULL;
 for (int i = 0; i <height; ++i)
 {
 ptmp = SrcImage1.ptr<uchar>(i);

 for (int j = 0; j < width; ++j)
 {
 ptmp[j] = MASK[i*width + j];
 }
 }
 //cv::Mat SrcImage1 = cv::Mat(height, width, CV_8UC1, MASK);容易出问题,导致转换出现问题,采用上面的方式进行转换;
 Mat thresholdImage;
 cv::threshold(SrcImage1, thresholdImage, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);

 vector< vector< Point> > contours;  //用于保存所有轮廓信息  
 vector< vector< Point> > contours2; //用于保存面积不足100的轮廓  
 //vector<Point> tempV;              //暂存的轮廓  

 cv::findContours(thresholdImage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);

 //轮廓按照面积大小进行升序排序  
 sort(contours.begin(), contours.end(), ascendSort);//升序排序  
 vector<vector<Point> >::iterator itc = contours.begin();
 int i = 0;
 while (itc != contours.end())
 {
 //获得轮廓的矩形边界  
 Rect rect = boundingRect(*itc);
 int x = rect.x;
 int y = rect.y;
 int w = rect.width;
 int h = rect.height;
 //绘制轮廓的矩形边界  
 cv::rectangle(SrcImage1, rect, { 0, 0, 255 }, 1);  
 if (itc->size() < 100)
 {
 contours2.push_back(*itc);  
 //删除轮廓面积不足100的区域,即用黑色填充轮廓面积不足100的区域:  
 cv::drawContours(SrcImage1, contours2, -1, Scalar(0, 0, 0), CV_FILLED);
 }
 ++itc;
 }

 for (int i_0 = 0; i_0 <height; ++i_0)
 {
 for (int j_0 = 0; j_0 < width; ++j_0)
 {
 //if (SrcImage1.at<uchar>(i_0, j_0)==255)
 //{
 MASK[i_0*width + j_0] = SrcImage1.at<uchar>(i_0, j_0);
 //int a = MASK[i_0*width + j_0];
 //}

 }
 }

 //释放内存;
 vector<vector< Point> >().swap(contours);
 vector<vector< Point> >().swap(contours2);
 }
 各位,小弟自定义了一个剔除面积小的区域的函数,但是经过多次调用之后会出现处:有未经处理的异常:  0xC0000374: 堆已损坏。 (参数:  0x00007FFD3C0C97B0)。经过初步定为是 vector< vector< Point> > contours;  //用于保存所有轮廓信息  
 vector< vector< Point> > contours2; //用于保存面积不足100的轮廓  的问题,该怎么处理为好?2018-06-08 15:25:08