python-opencv获取二值图像轮廓及中心点坐标的代码
python-opencv获取二值图像轮廓及中心点坐标代码:
groundtruth=cv2.imread(groundtruth_path)[:,:,0]
h1,w1=groundtruth.shape
contours,cnt=cv2.findContours(groundtruth.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
iflen(contours)!=1:#轮廓总数
continue
M=cv2.moments(contours[0])#计算第一条轮廓的各阶矩,字典形式
center_x=int(M["m10"]/M["m00"])
center_y=int(M["m01"]/M["m00"])
image=np.zeros([h1,w1],dtype=groundtruth.dtype)
cv2.drawContours(image,contours,0,255,-1)#绘制轮廓,填充
cv2.circle(image,(center_x,center_y),7,128,-1)#绘制中心点
cv2.imwrite("1.png",image)
以上这篇python-opencv获取二值图像轮廓及中心点坐标的代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
1 训练狗狗搜寻
2 如何训练狗狗装死
3 狗狗训练书
6 怎么训练狗狗拜年
8 狗狗训练游戏
10 狗狗嗅觉训练
11 怎么训练狗狗在笼子里不叫
12 怎么训练狗狗站立走路
13 怎么训练狗狗在马桶上
14 狗狗尿尿怎么训练
15 训练狗狗用品
16 泰迪狗狗的训练方法大小便
17 训练狗狗可以打吗
18 王曼丽的狗狗训练