cv2.minAreaRect(polygon),cv2.fitEllipse

该函数生成点集的最小外界矩阵,矩阵的四个角坐标按照顺时针旋转方向,起始点为最下角

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)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值