opencv-findContours轮廓查找(二十四)

轮廓查找
# 重要API:
    contours,hierarchy = findContours(img,mode,ApproximationMode...)
        两个返回值:contours:查找到所有轮廓的列表
                    hierarchy:层级
            mode:
                RETR_EXTERNAL = 0,表示值检测外轮廓
                RETR_LIST = 1,常用,轮廓不建立等级关系,全放进列表中
                RETR_CCOMP = 2,每层最多两级
                RETR_TREE = 3,按树形存储轮廓
import cv2 as cv
import numpy as np

img = cv.imread('./img/houmo.png')
# print(img.shape)
dst = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
# print(dst.shape)

# 二值化
ret,binary = cv.threshold(dst,127,255,cv.THRESH_BINARY)
# print(binary)

# 轮廓查找
contours,hierarchy = cv.findContours(binary,0,cv.CHAIN_APPROX_SIMPLE)
print(contours)
# print(hierarchy)


cv.imshow('img',img)
cv.imshow('dst',dst)
cv.imshow('binary',binary)

cv.waitKey(0)

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值