• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

OpenCV实现二值图像的边缘光滑处理

c语言 搞代码 4年前 (2022-01-06) 31次浏览 已收录 0个评论

这篇文章主要为大家详细介绍了OpenCV实现二值图像的边缘光滑处理,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了OpenCV学习笔记之针对二值图像的边缘光滑处理(突出部消除),供大家参考,具体内容如下

处理代码分为两部分,第一部分用于去除边缘的突出部,第二部分用于边缘光滑。具体如下所示

1.去除边缘突出部

 //去除二值图像边缘的突出部 //uthreshold、vthreshold分别表示突出部的宽度阈值和高度阈值 //type代表突出部的颜色,0表示黑色,1代表白色 void delete_jut(Mat& src, Mat& dst, int uthreshold, int vthreshold, int type) { int threshold<strong style="color:transparent">来源gao@daima#com搞(%代@#码网</strong>; 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) { for (int k = j + 1; k <width; k++) p[k] = 255; } else { for (k = j + 2; k <= j + uthreshold; k++) { if (p[k] == 255) break; } if (p[k] == 255) { for (int h = j + 1; h = height) { for (k = j + width; k <j + (height - i)*width; k width) p[k]=255; } else { for (k=j 2 * width; = width) { for (int k = j + 1; k <width; k++) p[k] = 0; } else { for (k = j + 2; k <= j + uthreshold; k++) { if (p[k] == 0) break; } if (p[k] == 0) { for (int h = j + 1; h = height) { for (k = j + width; k <j + (height - i)*width; k width) p[k]=0; } else { for (k=j 2 * width; < vthreshold*width; if (p[k]== 0) break; (int h k; p[h]=0; }<pre></div><p>效果如下:</p><p style="text-align: center"></p><p style="text-align: center"></p><p><strong>2.边缘光滑处理</strong></p><div class="gaodaimacode"><pre class="prettyprint linenums"> //图片边缘光滑处理 //size表示取均值的窗口大小,threshold表示对均值图像进行二值化的阈值 void imageblur(Mat& src, Mat& dst, Size size, int threshold) { int height = src.rows; int width = src.cols; blur(src, dst, size); for (int i = 0; i <height; i++) { uchar* p = dst.ptr(i); for (int j = 0; j <width; j++) { if (p[j] <threshold) p[j] = 0; else p[j] = 255; } } imshow("Blur", dst); }

效果如下:

以上就是OpenCV实现二值图像的边缘光滑处理的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:OpenCV实现二值图像的边缘光滑处理
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址