简单的图形识别python

import cv2
import numpy as np
kernel=np.ones ((5,5),np.uint8)
txp=cv2.imread("tx.jfif ")改图片,图片要自己导到项目
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)
print(area)
if area >500:
cv2.drawContours(ht,cnt ,-1,(255,0,0),3)
peri=cv2 .arcLength(cnt ,True )
print(peri)
approx=cv2.approxPolyDP(cnt,0.02*peri ,True )
print(len (approx ))
cd=len(approx )
x,y,w,h=cv2 .boundingRect(approx )
if cd3:Type=“Tri”
elif cd
4:
asp=w/float (h )
if asp>0.95and asp<1.05:Type =“square”
else: Type =“Rectangle”
elif cd>4:Type =“Circles”
else: Type =“None”
cv2.rectangle(ht,(x,y),(x+w,y+h),(0,250,0),2)
cv2.putText(ht ,Type ,
(x+(w//2)-10,y+(h//2)-1

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值