1.横纵比
x,y,w,h = cv.boundingRect(cnt)
aspect_ratio = float(w)/h
2.轮廓面积与边界面积
area = cv.contourArea(cnt)
x,y,w,h = cv.boundingRect(cnt)
rect_area = w*h
extent = float(area)/rect_area
3.轮廓面积与凸面积比值
area = cv.contourArea(cnt)
hull = cv.convexHull(cnt)
hull_area = cv.contourArea(hull)
solidity = float(area)/hull_area
4.直径
area = cv.contourArea(cnt)
equi_diameter = np.sqrt(4*area/np.pi)
5.方向
(x,y),(MA,ma),angle = cv.fitEllipse(cnt)
6.像素点和面具
mask = np.zeros(imgray.shape,np.uint8)
cv.drawContours(mask,[cnt],0,255,-1)
pixelpoints = np.transpose(np.nonzero(mask))
#pixelpoints = cv.findNonZero(mask)
7.极值和位置
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(imgray,mask = mask)
8.色彩和强度均值
mean_val = cv.mean(im,mask = mask)
9.极端值
leftmost = tuple(cnt[cnt[:,:,0].argmin()][0])
rightmost = tuple(cnt[cnt[:,:,0].argmax()][0])
topmost = tuple(cnt[cnt[:,:,1].argmin()][0])
bottommost = tuple(cnt[cnt[:,:,1].argmax()][0])
参考文献:
https://blog.csdn.net/qq_41905045/article/details/81507421
https://docs.opencv.org/3.4.3/d1/d32/tutorial_py_contour_properties.html