外包加工网站,网站域名怎么快速备案,中国住房城乡和城乡建设部网站,郴州做网站的欢迎关注 『youcans 的 OpenCV 例程 200 篇』 系列#xff0c;持续更新中 欢迎关注 『youcans 的 OpenCV学习课』 系列#xff0c;持续更新中 【youcans 的 OpenCV 例程 200 篇】126. 形态算法之凸壳
3. 形态学算法
形态学处理的主要应用是提取图像中用来表示和描述形状的元… 欢迎关注 『youcans 的 OpenCV 例程 200 篇』 系列持续更新中 欢迎关注 『youcans 的 OpenCV学习课』 系列持续更新中 【youcans 的 OpenCV 例程 200 篇】126. 形态算法之凸壳
3. 形态学算法
形态学处理的主要应用是提取图像中用来表示和描述形状的元素和成分例如提取边界、连通分量、凸壳和区域骨架。 3.4 凸壳凸包
欧氏几何中如果连接物体 A 内任意两点的直线段都在 A 的内部则称 A 是凸的。数字图像处理中凸集简化为二维平面且以离散坐标形式表达。数字集合 A 是凸的当且仅当它的欧氏凸壳只包含属于 A 的数字点。
任意物体 A 的凸壳是包含 A 的最小凸物体。在二维图像中凸壳可以想象为一条刚好包着所有点的橡皮圈。在凸壳与物体边缘之间的部分称为凸陷Convexity defect。
使用形态学算法令 BiB^iBi 表示 4个特定的结构元反复使用 BiB^iBi 对 A 做击中击不中变换直至收敛就可以得到二值图像 III 中嵌入的前景图像集合 A 的凸壳的近似 C(A)C(A)C(A) Xki(Xk−1i⊛Bi)∪Xk−1i,i1,2,3,4;k1,2,3...C(A)⋃i14DiX_k^i (X_{k-1}^i \circledast B^i) \cup X_{k-1}^i, \ i1,2,3,4;k1,2,3... \\ C(A) \bigcup^{4}_{i1} D^i Xki(Xk−1i⊛Bi)∪Xk−1i, i1,2,3,4;k1,2,3...C(A)i1⋃4Di
OpenCV 中提供了函数 cv.convexHull 可以获取轮廓的凸壳 。
函数说明 cv.convexHull(points[, hull[, clockwise[, returnPoints]]]) - hull参数说明
points输入图像可以为单通道或多通道hull输出凸包凸包点的索引向量或凸包点集的向量clockwise方向标志True 表示顺时针方向输出凸包否则为逆时针方向输出returnPoints操作标志True 表示返回凸包点集否则返回凸包点的索引
进一步地cv.convexHull 函数与 cv.drawContours 函数配合可以用来检测物体是否存在缺陷。 例程 10.14形态算法之凸壳Convex hull
说明本例程改编自 Convex Hull using OpenCV in C and Python | LearnOpenCV
先使用 OpenCV 中的 cv.findContour 函数找到二值图像中的所有轮廓然后使用 cv.convexHull 函数构造轮廓的凸包最后使用 cv.drawContours 函数绘制轮廓和凸包 。 # 10.14 形态算法之凸壳img cv2.imread(../images/imgDemo1.png, flags1) # flags1 读取为彩色图像imgGray cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 灰度图像imgBlur cv2.blur(imgGray, (3, 3)) # 去除噪点ret, imgBin cv2.threshold(imgBlur, 225, 255, cv2.THRESH_BINARY) # 二值化处理img2, contours, hierarchy cv2.findContours(imgBin, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) # 寻找所有的轮廓hullAll [] # 所有的凸包for i in range(len(contours)):hull cv2.convexHull(contours[i], False) # 计算轮廓 contours[i] 的凸包hullAll.append(hull)colorContours (0, 255, 0) # 设置轮廓的颜色colorConvexHull (255, 255, 255) # 设置凸包的颜色imgContours np.zeros(img.shape, np.uint8)for i in range(len(contours)): # 绘制轮廓线cv2.drawContours(imgContours, contours, i, colorContours, 2, 8, hierarchy)imgDrawing imgContours.copy()for i in range(len(contours)): # 绘制凸包线cv2.drawContours(imgDrawing, hullAll, i, colorConvexHull, 2, 8)plt.figure(figsize(9, 6))plt.subplot(221), plt.axis(off), plt.title(origin)plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))plt.subplot(222), plt.title(binary), plt.axis(off)plt.imshow(imgBin, cmapgray, vmin0, vmax255)plt.subplot(223), plt.title(contours), plt.axis(off)plt.imshow(cv2.cvtColor(imgContours, cv2.COLOR_BGR2RGB))plt.subplot(224), plt.title(convex hull), plt.axis(off)plt.imshow(cv2.cvtColor(imgDrawing, cv2.COLOR_BGR2RGB))plt.tight_layout()plt.show()本节完 版权声明
youcansxupt 原创作品转载必须标注原文链接(https://blog.csdn.net/youcans/article/details/123457114)
Copyright 2022 youcans, XUPT Crated2022-3-12 欢迎关注 『youcans 的 OpenCV 例程 200 篇』 系列持续更新中 欢迎关注 『youcans 的 OpenCV学习课』 系列持续更新中 【youcans 的 OpenCV 例程200篇】01. 图像的读取cv2.imread 【youcans 的 OpenCV 例程200篇】02. 图像的保存cv2.imwrite 【youcans 的 OpenCV 例程200篇】03. 图像的显示cv2.imshow 【youcans 的 OpenCV 例程200篇】04. 用 matplotlib 显示图像plt.imshow 【youcans 的 OpenCV 例程200篇】05. 图像的属性np.shape 【youcans 的 OpenCV 例程200篇】06. 像素的编辑img.itemset 【youcans 的 OpenCV 例程200篇】07. 图像的创建np.zeros 【youcans 的 OpenCV 例程200篇】08. 图像的复制np.copy 【youcans 的 OpenCV 例程200篇】09. 图像的裁剪cv2.selectROI 【youcans 的 OpenCV 例程200篇】10. 图像的拼接np.hstack 【youcans 的 OpenCV 例程200篇】11. 图像通道的拆分cv2.split 【youcans 的 OpenCV 例程200篇】12. 图像通道的合并cv2.merge 【youcans 的 OpenCV 例程200篇】13. 图像的加法运算cv2.add 【youcans 的 OpenCV 例程200篇】14. 图像与标量相加cv2.add 【youcans 的 OpenCV 例程200篇】15. 图像的加权加法cv2.addWeight 【youcans 的 OpenCV 例程200篇】16. 不同尺寸的图像加法 【youcans 的 OpenCV 例程200篇】17. 两张图像的渐变切换 【youcans 的 OpenCV 例程200篇】18. 图像的掩模加法 【youcans 的 OpenCV 例程200篇】19. 图像的圆形遮罩 【youcans 的 OpenCV 例程200篇】20. 图像的按位运算 【youcans 的 OpenCV 例程200篇】21. 图像的叠加 【youcans 的 OpenCV 例程200篇】22. 图像添加非中文文字 【youcans 的 OpenCV 例程200篇】23. 图像添加中文文字 【youcans 的 OpenCV 例程200篇】24. 图像的仿射变换 【youcans 的 OpenCV 例程200篇】25. 图像的平移 【youcans 的 OpenCV 例程200篇】26. 图像的旋转以原点为中心 【youcans 的 OpenCV 例程200篇】27. 图像的旋转以任意点为中心 【youcans 的 OpenCV 例程200篇】28. 图像的旋转直角旋转 【youcans 的 OpenCV 例程200篇】29. 图像的翻转cv2.flip 【youcans 的 OpenCV 例程200篇】30. 图像的缩放cv2.resize 【youcans 的 OpenCV 例程200篇】31. 图像金字塔cv2.pyrDown 【youcans 的 OpenCV 例程200篇】32. 图像的扭变错切 【youcans 的 OpenCV 例程200篇】33. 图像的复合变换 【youcans 的 OpenCV 例程200篇】34. 图像的投影变换 【youcans 的 OpenCV 例程200篇】35. 图像的投影变换边界填充 【youcans 的 OpenCV 例程200篇】36. 直角坐标与极坐标的转换 【youcans 的 OpenCV 例程200篇】37. 图像的灰度化处理和二值化处理 【youcans 的 OpenCV 例程200篇】38. 图像的反色变换图像反转 【youcans 的 OpenCV 例程200篇】39. 图像灰度的线性变换 【youcans 的 OpenCV 例程200篇】40. 图像分段线性灰度变换 【youcans 的 OpenCV 例程200篇】41. 图像的灰度变换灰度级分层 【youcans 的 OpenCV 例程200篇】42. 图像的灰度变换比特平面分层 【youcans 的 OpenCV 例程200篇】43. 图像的灰度变换对数变换 【youcans 的 OpenCV 例程200篇】44. 图像的灰度变换伽马变换 【youcans 的 OpenCV 例程200篇】45. 图像的灰度直方图 【youcans 的 OpenCV 例程200篇】46. 直方图均衡化 【youcans 的 OpenCV 例程200篇】47. 图像增强—直方图匹配 【youcans 的 OpenCV 例程200篇】48. 图像增强—彩色直方图匹配 【youcans 的 OpenCV 例程200篇】49. 图像增强—局部直方图处理 【youcans 的 OpenCV 例程200篇】50. 图像增强—直方图统计量图像增强 【youcans 的 OpenCV 例程200篇】51. 图像增强—直方图反向追踪 【youcans 的 OpenCV 例程200篇】52. 图像的相关与卷积运算 【youcans 的 OpenCV 例程200篇】53. Scipy 实现图像二维卷积 【youcans 的 OpenCV 例程200篇】54. OpenCV 实现图像二维卷积 【youcans 的 OpenCV 例程200篇】55. 可分离卷积核 【youcans 的 OpenCV 例程200篇】56. 低通盒式滤波器 【youcans 的 OpenCV 例程200篇】57. 低通高斯滤波器 【youcans 的 OpenCV 例程200篇】58. 非线性滤波—中值滤波 【youcans 的 OpenCV 例程200篇】59. 非线性滤波—双边滤波 【youcans 的 OpenCV 例程200篇】60. 非线性滤波—联合双边滤波 【youcans 的 OpenCV 例程200篇】61. 导向滤波Guided filter 【youcans 的 OpenCV 例程200篇】62. 图像锐化——钝化掩蔽 【youcans 的 OpenCV 例程200篇】63. 图像锐化——Laplacian 算子 【youcans 的 OpenCV 例程200篇】64. 图像锐化——Sobel 算子 【youcans 的 OpenCV 例程200篇】65. 图像锐化——Scharr 算子 【youcans 的 OpenCV 例程200篇】66. 图像滤波之低通/高通/带阻/带通 【youcans 的 OpenCV 例程200篇】67. 空间域图像增强的综合应用 【youcans 的 OpenCV 例程200篇】68. 空间域图像增强的综合应用 【youcans 的 OpenCV 例程200篇】69. 连续非周期信号的傅立叶系数 【youcans 的 OpenCV 例程200篇】70. 一维连续函数的傅里叶变换 【youcans 的 OpenCV 例程200篇】71. 连续函数的取样 【youcans 的 OpenCV 例程200篇】72. 一维离散傅里叶变换 【youcans 的 OpenCV 例程200篇】73. 二维连续傅里叶变换 【youcans 的 OpenCV 例程200篇】74. 图像的抗混叠 【youcans 的 OpenCV 例程200篇】75. Numpy 实现图像傅里叶变换 【youcans 的 OpenCV 例程200篇】76. OpenCV 实现图像傅里叶变换 【youcans 的 OpenCV 例程200篇】77. OpenCV 实现快速傅里叶变换 【youcans 的 OpenCV 例程200篇】78. 频率域图像滤波基础 【youcans 的 OpenCV 例程200篇】79. 频率域图像滤波的基本步骤 【youcans 的 OpenCV 例程200篇】80. 频率域图像滤波详细步骤 【youcans 的 OpenCV 例程200篇】81. 频率域高斯低通滤波器 【youcans 的 OpenCV 例程200篇】82. 频率域巴特沃斯低通滤波器 【youcans 的 OpenCV 例程200篇】83. 频率域低通滤波印刷文本字符修复 【youcans 的 OpenCV 例程200篇】84. 由低通滤波器得到高通滤波器 【youcans 的 OpenCV 例程200篇】85. 频率域高通滤波器的应用 【youcans 的 OpenCV 例程200篇】86. 频率域滤波应用指纹图像处理 【youcans 的 OpenCV 例程200篇】87. 频率域钝化掩蔽 【youcans 的 OpenCV 例程200篇】88. 频率域拉普拉斯高通滤波 【youcans 的 OpenCV 例程200篇】89. 带阻滤波器的传递函数 【youcans 的 OpenCV 例程200篇】90. 频率域陷波滤波器 【youcans 的 OpenCV 例程200篇】91. 高斯噪声、瑞利噪声、爱尔兰噪声 【youcans 的 OpenCV 例程200篇】92. 指数噪声、均匀噪声、椒盐噪声 【youcans 的 OpenCV 例程200篇】93. 噪声模型的直方图 【youcans 的 OpenCV 例程200篇】94. 算术平均滤波器 【youcans 的 OpenCV 例程200篇】95. 几何均值滤波器 【youcans 的 OpenCV 例程200篇】96. 谐波平均滤波器 【youcans 的 OpenCV 例程200篇】97. 反谐波平均滤波器 【youcans 的 OpenCV 例程200篇】98. 统计排序滤波器 【youcans 的 OpenCV 例程200篇】99. 修正阿尔法均值滤波器 【youcans 的 OpenCV 例程200篇】100. 自适应局部降噪滤波器 【youcans 的 OpenCV 例程200篇】101. 自适应中值滤波器 【youcans 的 OpenCV 例程200篇】102. 陷波带阻滤波器的传递函数 【youcans 的 OpenCV 例程200篇】103. 陷波带阻滤波器消除周期噪声干扰 【youcans 的 OpenCV 例程200篇】104. 运动模糊退化模型 【youcans 的 OpenCV 例程200篇】105. 湍流模糊退化模型 【youcans 的 OpenCV 例程200篇】106. 退化图像的逆滤波 【youcans 的 OpenCV 例程200篇】107. 退化图像的维纳滤波 【youcans 的 OpenCV 例程200篇】108. 约束最小二乘方滤波 【youcans 的 OpenCV 例程200篇】109. 几何均值滤波 【youcans 的 OpenCV 例程200篇】110. 投影和雷登变换 【youcans 的 OpenCV 例程200篇】111. 雷登变换反投影重建图像 【youcans 的 OpenCV 例程200篇】112. 滤波反投影重建图像 【youcans 的 OpenCV 例程200篇】113. 形态学操作之腐蚀 【youcans 的 OpenCV 例程200篇】114. 形态学操作之膨胀 【youcans 的 OpenCV 例程200篇】115. 形态学操作之开运算 【youcans 的 OpenCV 例程200篇】116. 形态学操作之闭运算 【youcans 的 OpenCV 例程200篇】117. 形态学操作之顶帽运算 【youcans 的 OpenCV 例程200篇】118. 形态学操作之底帽运算 【youcans 的 OpenCV 例程200篇】119. 图像的形态学梯度 【youcans 的 OpenCV 例程200篇】120. 击中-击不中变换 【youcans 的 OpenCV 例程200篇】121. 击中-击不中用于特征识别 【youcans 的 OpenCV 例程200篇】122. 形态算法之边界提取 【youcans 的 OpenCV 例程200篇】123. 形态算法之孔洞填充 【youcans 的 OpenCV 例程200篇】124. 孔洞填充的泛洪算法 【youcans 的 OpenCV 例程200篇】125. 形态算法之提取连通分量 【youcans 的 OpenCV 例程200篇】126. 形态算法之凸壳