该函数生成点集的最小外界矩阵,矩阵的四个角坐标按照顺时针旋转方向,起始点为最下角
results = cv2.minAreaRect(polygon)
#中心点
[cx,cy] = results[0]
#宽和高
[w,h] = results[1]
#旋转角度
theta = results[2]
#按照顺时针返回最小外接矩阵的四个点,右下->左下->左上->右上
result2 = cv2.boxPoints(cv2.minAreaRect(polygon))
print(result2)
[[239. 248.], [147. 248.], [147. 134.], [239. 134.]]
cv2.fitEllipse:椭圆拟合
#获得仿射变化矩阵:参数为中心点,角度,缩放因子
R_mat = cv2.getRotationMatrix2D((center[0], center[1]), angle, 1.0)
#对图像进行旋转
rotated_img = cv2.warpAffine(img, R, (img.shape[1], img.shape[0]))
#计算积分图
cv2.integral()
积分图的解释参考自:
https://theailearner.com/tag/cv2-integral/
https://blog.csdn.net/u010807846/article/details/50354000
snap = np.ones((4,4),dtype='uint8')
s=cv2.integral(snap)
s
array([[ 0, 0, 0, 0, 0],
[ 0, 1, 2, 3, 4],
[ 0, 2, 4, 6, 8],
[ 0, 3, 6, 9, 12],
[ 0, 4, 8, 12, 16]], dtype=int32)
snap
array([[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]], dtype=uint8)