快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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

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

成都创新互联2013年至今,先为和静等服务建站,和静等地企业,进行企业商务咨询服务。为和静企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
groundtruth = cv2.imread(groundtruth_path)[:, :, 0]
h2, 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([h2, 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获取二值图像轮廓及中心点坐标的代码-创新互联
分享网址:http://6mz.cn/article/hehis.html

其他资讯