连通域降噪(转载)2023-12-15 14:52:51原文链接:https://blog.csdn.net/ysc6688 void ContoursRemoveNoise(cv::Mat & srcImage) { int i, j; int color = 1; int nRows = srcImage.rows; int nCols = srcImage.cols; for (i = 0; i < nRows; ++i) { for (j = 0; j < nCols; ++j) { if (!srcImage.at<uchar>(i,j)) { floodFill(srcImage, cv::Point(j, i), cv::Scalar(color)); color++; } } } int ColorCount[255] = { 0 }; for (i = 0; i < nRows; ++i) { for (j = 0; j < nCols; ++j) { if (srcImage.at<uchar>(i, j) != 255) { ColorCount[srcImage.at<uchar>(i, j)]++; } } } for (i = 0; i < nRows; ++i) { for (j = 0; j < nCols; ++j) { if (ColorCount[srcImage.at<uchar>(i, j)] <= 20) { srcImage.at<uchar>(i, j) = 255; } else { srcImage.at<uchar>(i, j) = 0; } } } } 上一篇:php – HTML Purifier:根据属性有条件地删除元素下一篇:absolute元素水平居中