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
OpenCV 去噪算法 opencv去除小面积区域
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Python OpenCV #2 - OpenCV中的GUI功能
本文介绍了OpenCV的基本方发,包括图像读取、显示和写入。
python ide OpenCV -
opencv 去毛细 opencv 去除小面积噪声
图像平滑✔️ 模糊/平滑图片来消除图片噪声✔️ OpenCV函数:cv2.blur(), cv2.GaussianBlur(), cv2.medianBlur(), cv2.bilateralFilter() 2D 卷积✔️ OpenCV中用cv2.filter2D()实现卷积操作,比如我们的核是下面这样(3×3区域像素的和除以10): img = cv2.imread(
opencv 去毛细 opencv 效率 opencv 膨胀 opencv 高通滤波和低通滤波 opencv均值滤波 -
opencv 深度学习去噪 opencv去除噪声
1、噪声类型及生成1.1、类型高斯噪声、椒盐噪声、泊松噪声、乘性噪声,等。高斯噪声 &nb
opencv 深度学习去噪 opencv 人工智能 计算机视觉 像素点