python-opencv获取二值图像轮廓及中心点坐标的代码

作者:叶晚zd 时间:2021-03-10 01:12:02 

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)
if len(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)

来源:https://blog.csdn.net/u013925378/article/details/90671486

标签:python,opencv,图像轮廓,中心点,坐标
0
投稿

猜你喜欢

  • Python Pandas对缺失值的处理方法

    2021-03-18 19:38:55
  • Microsoft VBScript 运行时错误 错误800a0005 无效的过程调用或参数

    2010-03-25 21:51:00
  • Python 使用tf-idf算法计算文档关键字权重并生成词云的方法

    2022-03-28 13:09:18
  • ajax标签导航实例详解教程

    2008-02-01 10:54:00
  • python3判断url链接是否为404的方法

    2021-11-12 15:17:54
  • Python多进程同步Lock、Semaphore、Event实例

    2021-02-22 17:11:26
  • Python Django Cookie 简单用法解析

    2022-09-15 15:20:03
  • python图形开发GUI库pyqt5的基本使用方法详解

    2022-07-08 02:31:55
  • Flask和Django框架中自定义模型类的表名、父类相关问题分析

    2022-04-04 00:23:17
  • 用Python做的数学四则运算_算术口算练习程序(后添加减乘除)

    2023-04-10 13:27:35
  • 浅谈Python数学建模之数据导入

    2022-08-11 01:10:28
  • 浅谈python在提示符下使用open打开文件失败的原因及解决方法

    2023-12-07 18:31:33
  • Z-Blog垃圾留言判定新方法

    2009-07-06 13:04:00
  • 详解python中@classmethod和@staticmethod方法

    2022-10-24 11:47:16
  • Python之多线程爬虫抓取网页图片的示例代码

    2021-09-01 18:55:03
  • 1500个绚丽主题 谷歌中国个人风格首页发布

    2008-11-12 11:14:00
  • Python实现采用进度条实时显示处理进度的方法

    2021-10-16 07:24:01
  • tensorflow之如何使用GPU而不是CPU问题

    2023-07-06 13:05:48
  • python统计文本文件内单词数量的方法

    2021-09-20 17:51:55
  • python如何建立全零数组

    2023-08-02 09:50:45
  • asp之家 网络编程 m.aspxhome.com