opencv識別封閉區域 並標記該區域
阿新 • • 發佈:2018-08-31
rom coord polygon ted oid read num label region
#!/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()
opencv識別封閉區域 並標記該區域