作者:手机用户2502863305 | 来源:互联网 | 2023-10-11 21:29
本文由编程笔记#小编为大家整理,主要介绍了opencv识别封闭区域 并标记该区域相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author : zhibo.wang
# E-mail : [email protected]
# Time : 2018/8/21 17:24
# Des :
# import imutils
# import numpy as np
import cv2
from PIL import Image, ImageDraw, ImageFont
from skimage.measure import regionprops
# from shapely.geometry import Point, Polygon
img = cv2.imread(‘1.png‘, 0)
ret, labels = cv2.connectedComponents(img)
props = regionprops(labels)
im = Image.open("1.png")
draw = ImageDraw.Draw(im)
for i in props:
# print(i.coords)
# print(props.index(i), i.centroid)
draw.text((i.centroid[-1], i.centroid[0]), "{0}".format(props.index(i)), fill=(255,25,0))#,fOnt=ttfont)
im.show()