opencv图形检测

 

import cv2
txp=cv2.imread("999.png")
ht=txp.copy()
def md (txp):
    yu,oi=cv2.findContours(txp,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_TC89_KCOS)
    for cnt in yu:
        area=cv2.contourArea(cnt)
        if area>1500:
            cv2.drawContours(ht,cnt,-1,(255,0,0),3)
            peri=cv2.arcLength(cnt,True)
            approx=cv2.approxPolyDP(cnt,0.02*peri,True)
            cd=len(approx)
            x,y,w,h=cv2.boundingRect(approx)
            if cd==3:
                Type="Tri"
            elif cd==4:
                asp=w/float(h)
                if asp>0.95 and asp<1.05:
                    Type="squ"
                else:
                    Type="rec"
            elif cd>4:
                Type="cir"
            else:
                Type="None"
            cv2.rectangle(ht,(x,y),(x+w,y+h),(250,250,0),2)
            cv2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值