MCPcopy Create free account
hub / github.com/PyImageSearch/imutils / label_contour

Function label_contour

imutils/contours.py:31–44  ·  view source on GitHub ↗
(image, c, i, color=(0, 255, 0), thickness=2)

Source from the content-addressed store, hash-verified

29
30
31def label_contour(image, c, i, color=(0, 255, 0), thickness=2):
32 # compute the center of the contour area and draw a circle
33 # representing the center
34 M = cv2.moments(c)
35 cX = int(M["m10"] / M["m00"])
36 cY = int(M["m01"] / M["m00"])
37
38 # draw the contour and label number on the image
39 cv2.drawContours(image, [c], -1, color, thickness)
40 cv2.putText(image, "#{}".format(i + 1), (cX - 20, cY), cv2.FONT_HERSHEY_SIMPLEX,
41 1.0, (255, 255, 255), 2)
42
43 # return the image with the contour number drawn on it
44 return image

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…