As this is the output from the watershed and I want to mark the labels like 1,2,3 etc on the regions identified. I have tried to use cv2.puttext as well by using cv2.boudingrect but the labels are not coming in the center of the region identified
for i in range(2, ret3+1):
a=0
b=0
mask = np.where(markers==i, np.uint8(255), np.uint8(0))
x,y,w,h = cv2.boundingRect(mask)
area = cv2.countNonZero(mask[y:y+h,x:x+w])
print ("Label %d at (%d, %d) size (%d x %d) area %d pixels" % (i,x,y,w,h,area))
# Visualize
color = np.uint8(np.random.random_integers(0, 0, 3)).tolist()
output[mask!=0] = color
cv2.putText(img2,'%d'%i,(int(x), int(y)), cv2.FONT_HERSHEY_SIMPLEX, 3.9, color, 15, cv2.LINE_AA)
plt.imshow(img2, cmap='jet')
plt.show()
Through the above code the generated labels are as follows
What i want is that to mark the labels 3,4,5 etc in the center of the objects identified by watershed.


You can find the center of each region like this:
The result:
Complete example: