有没有opencv大神帮忙看看这个是什么情况?
为什么面积检测后会出来两组数据,分不清楚了
谢谢
# -*- coding: cp936 -*-
import cv2
import numpy as np
#import matplotlib.pyplot as plt
img = cv2.imread('22.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),0)
thresh = cv2.adaptiveThreshold(blur,225,1,1,11,2)
contours,hierarchy = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
Area = []
for cnt in contours:
if cv2.contourArea(cnt)>50: #计算出轮廓面积>50
[x,y,w,h] = cv2.boundingRect(cnt) #包含轮廓的正方框,得到坐标
if h>28:
#cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2) #绘制出轮廓的方框
string = str(cv2.contourArea(cnt))
cv2.putText(img,string,(x,y+100),0,1,(0,255,0))
print w,h
cv2.imshow('im',img)
cv2.waitKey(0)