本文实例为大家分享了OpenCV学习笔记之针对二值图像的边缘光滑处理(突出部消除),供大家参考,具体内容如下
处理代码分为两部分,第一部分用于去除边缘的突出部,第二部分用于边缘光滑。具体如下所示
1.去除边缘突出部
//去除二值图像边缘的突出部
//uthreshold、vthreshold分别表示突出部的宽度阈值和高度阈值
//type代表突出部的颜色,0表示黑色,1代表白色
void delete_jut(Mat& src, Mat& dst, int uthreshold, int vthreshold, int type)
{
int threshold;
src.copyTo(dst);
int height = dst.rows;
int width = dst.cols;
int k; //用于循环计数传递到外部
for (int i = 0; i < height - 1; i++)
{
uchar* p = dst.ptr(i);
for (int j = 0; j < width - 1; j++)
{
if (type == 0)
{
//行消除
if (p[j] == 255 && p[j + 1] == 0)
{
if (j + uthreshold >= width)
{