简介
本文详解5个函数,分别是:
- f i n d C o n t o u r s findContours findContours
- d r a w C o n t o u r s drawContours drawContours
- 边缘检测
- a p p r o x P o l y D P approxPolyDP approxPolyDP
- t h r e s h o l d threshold threshold
c v 2. f i n d C o n t o u r s ( ) cv2.findContours() cv2.findContours()
cv2.findContours(image, mode, method, contours=None, hierarchy=None, offset=None)
作用:寻找轮廓
参数详解
返回值
d r a w C o n t o u r s drawContours drawContours
cv2.drawContours(image,contours,contourIdx,color,thickness=None,lineType=None,hierarchy=None,maxLevel=None,offset=None)
作用:画出轮廓
参数详解
返回值
无
边 缘 检 测 边缘检测 边缘检测
边缘检测算子
- 一阶导数: R o b e r t s Roberts Roberts、 S o b e l Sobel Sobel、 P r e w i t t Prewitt Prewitt
- 二阶导数: L a p l a c i a n Laplacian Laplacian、 L o g / M a r r Log/Marr Log/Marr、( K i r s c h Kirsch Kirsch、 N e v i t i a Nevitia Nevitia)
- 非微分边缘检测算子: C a n n y Canny Canny
比较
一般二值化步骤
• 彩色图像转换为灰度图像(以灰度图或者单通道图读入)
• 对图像进行高斯模糊(去噪)
• 计算图像梯度,根据梯度计算图像边缘幅值与角度
• 沿梯度方向进行非极大值抑制(边缘细化)
• 双阈值边缘连接处理
• 二值化图像输出结果
a p p r o x P o l y D P approxPolyDP approxPolyDP
approxPolyDP(curve,epsilon,closed,approxCurve=None)
作用:主要功能是把一个连续光滑曲线折线化,对图像轮廓点进行多边形拟合。
参数详解
返回值
t h r e s h o l d threshold threshold
threshold(src,thresh,maxval,type,dst=None)