一、腐蚀(Erode)
取符合模板的点, 用区域最小值代替中心位置值(锚点)
作用: 平滑对象边缘、弱化对象之间的连接。
opencv 中相关函数:(erode)
1 // C++ 2 /** 3 shape: 形状 4 MORPH_RECT 矩形 5 MORPH_CROSS 交叉形 十字型 6 MORPH_ELLIPSE 椭圆形 7 esize : 大小 8 anchor: 锚点,默认为中心 9 **/ 10 Mat getStructuringElement(int shape, Size esize, Point anchor = Point(-1, -1)); 11 12 /** 13 src: input Mat 14 dst: output Mat 15 element : kernel element 16 完整参数:https://docs.opencv.org/4.1.0/d4/d86/group__imgproc__filter.html#gaeb1e0c1033e3f6b891a25d0511362aeb 17 **/ 18 erode(const Mat& src, Mat&dst , const Mat& element) // 基本参数
1 # python 2 # dst = cv.erode( src, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]] ) 3 4 import cv2 as cv 5 import numpy as np 6 7 im = cv.imread("test.jpg") 8 gray = cv.cvtColor(im,cv.COLOR_BGR2GRAY) 9 ret,binary = cv.threshold(gray,0,255,cv.THRESH_BINARY_INV|cv.THRESH_OTSU) 10 11 # 获取 kerenl element 12 kernel = cv.getStructuringElement(cv.MORPH_RECT,(5,5)) 13 # 腐蚀 14 dst = cv.erode(binary,kernel)