官网参见https://docs.opencv.org/3.4.1/d1/d32/tutorial_py_contour_properties.html
本章是在《轮廓特征》基础上的介绍,需要先获得图像的轮廓。
代码中反复出现的cnt通过以下方法获得。
img = cv2.imread('test.jpg',0)
ret,thresh = cv2.threshold(img,127,255,0)
im2,contours,hierarchy = cv2.findContours(thresh, 1, 2)
cnt = contours[0]
内容概要
- 长宽比
- 范围(Extent)
- 密实度(Solidity)
- 当量直径(Equivalent Diameter)
- 方向
- 蒙板和像素点(Mask and Pixel Points)
- 最大值,最小值和它们的位置
- 平均颜色和平均强度(Mean Color or Mean Intensity)
- 极值点(Extreme Points)
1.长宽比
这是对象矩形边界的宽度与高度之比。
A s p e c t R a t i o = W i d t h H e i g h t AspectRatio=\frac {Width} {Height} AspectRatio=HeightWidth
x,y,w,h = cv.boundingRect(cnt)
aspect_ratio = float(w)/h
cv.boundingRect()函数,查找矩形边界,在《轮廓特征》中已经介绍过。https://blog.youkuaiyun.com/weixin_42555985/article/details/97115338
2.范围(Extent)
范围是轮廓区域面积与边界矩形区域面积的比率。