opencv:常用函数详解(一)

简介

本文详解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)

作用:进行二值化处理

参数详解

在这里插入图片描述

返回值

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_43683133/article/details/121341596