def getmarkercenter(image, pos):
mkradius = getapproxmarkerradius(image)
buffer = int(mkradius * 0.15)
roisize = mkradius + buffer # half of the height or width
x = pos[0] - roisize
y = pos[1] - roisize
w = 2 * roisize
h = 2 * roisize
roi = image[y:y+h, x:x+w]
grayroi = getgrayimage(roi)
ret, binimage = cv2.threshold(grayroi,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(binimage)
# stats[0], centroids[0] are for the background label. ignore
lblareas = stats[1:,cv2.CC_STAT_AREA]
ave = np.average(centroids[1:], axis=0, weights=lblareas)
return tuple(np.array([x, y]) + ave) # weighted average pos of centroids
评论列表
文章目录