OpenCV学习笔记(十五)形状检测

1 轮廓检测图像目标中的形状检测是图像识别的重要的技术之一,对物体进行检测并提取,首先要做的就是提取物体的轮廓信息,然后在通过点集特征选择相应的算法进行处理,最后得到物体的形状信息。轮廓形状是我们看到物体最开始的印象,轮廓提取的原理是通过对图像进行二值化,利用边缘点连接的层次差别,提取位于数结构特征高的区域点集构成的集合,这部分最可能是物体的轮廓。主要用到的函数findContours()
摘要由CSDN通过智能技术生成

1 轮廓检测

图像目标中的形状检测是图像识别的重要的技术之一,对物体进行检测并提取,首先要做的就是提取物体的轮廓信息,然后在通过点集特征选择相应的算法进行处理,最后得到物体的形状信息。轮廓形状是我们看到物体最开始的印象,轮廓提取的原理是通过对图像进行二值化,利用边缘点连接的层次差别,提取位于数结构特征高的区域点集构成的集合,这部分最可能是物体的轮廓。

主要用到的函数findContours()对物体轮廓进行检测。

void findContours(InputOutputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset=Point())

  • image – Source, an 8-bit single-channel image. Non-zero pixels are treated as 1’s. Zero pixels remain 0’s, so the image is treated as binary . You can use compare() , inRange() , threshold() , adaptiveThreshold() ,Canny() , and others to create a binary image out of a grayscale or color one. The function modifies the imagewhile extracting the contours.
  • contours – Detected contours. Each contour is stored as a vector of points.
  • hiararchy – Optional output vector containing information about the image topology. It has as many elements as the number of contours. For each contour contours[i] , the elements hierarchy[i][0] , hiearchy[i][1] ,hiearchy[i][2] , and hiearchy[i][3] are set to 0-based indices in contours of the next and previous contours at the same hierarchical level: the first child contourand the parent contour, respectively. If for a contour ithere are no next, previous, parent, or nested contours, the corresponding elements of hierarchy[i] will be negative.
  • mode –

    Contour retrieval mode.

    • CV_RETR_EXTERNAL retrieves only the extreme outer contours. It sets hierarchy[i][2]=hierarchy[i][3]=-1 for all the contours.
    • CV_RETR_LIST retrieves all of the contours without establishing any hierarchical relationships.
    • CV_RETR_CCOMP retrieves all of the contours and organizes them into a two-level hierarchy. At the top level, there are external boundaries of the components. At the second level, there are bound
  • 5
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值