python opencv 轮廓属性

import cv2import numpy as npimg = cv2.imread('zhua.jpg',0)ret,thresh = cv2.threshold(img,100,255,0)image,contours,hierarchy = cv2.findContours(thresh, 1, 2)cnt = contours[0]# 函数cv2.moments()会给你...
摘要由CSDN通过智能技术生成
import cv2
import numpy as np

img = cv2.imread('zhua.jpg',0)
ret,thresh = cv2.threshold(img,100,255,0)
image,contours,hierarchy = cv2.findContours(thresh, 1, 2)
cnt = contours[0]
# 函数cv2.moments()会给你一个字典,包含所有矩值
M = cv2.moments(cnt)

print(M)
{'m00': 6232.5, 'm10': 1447203.0, 'm01': 1809901.1666666665, 'm20': 353678359.9166666, 'm11': 421580616.7083333, 'm02': 560193863.0833333, 'm30': 90102739020.40001, 'm21': 103128286116.0, 'm12': 130864394995.8, 'm03': 184233465551.75, 'mu20': 17633991.972984314, 'mu11': 1316774.2528981566, 'mu02': 34603452.637868285, 'mu30': -211631726.01593018, 'mu21': -190471290.52419376, 'mu12': 21121550.328198433, 'mu03': 1457182366.1941833, 'nu20': 0.45396886101420764, 'nu11': 0.03389898944701885, 'nu02': 0.8908300517114065, 'nu30': -0.06901207029499672, 'nu21': -0.062111755823628025, 'nu12': 0.006887634209812285, 'nu03': 0.4751800393143934}
# 重心
cx=int(M['m10']/M['m00'])
cy=int(M['m01']/M['m00'])
print(cx,cy
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值