-1

How can I overlay the results of the following DLib operation onto an OpenCV image?

dets = detector(image, 1)
print("Number of faces detected: {}".format(len(dets)))

for k, d in enumerate(dets):
        shape = predictor(image, d)

I'd like to draw the chin detect in this image..

in the original code there is something like .add_overlay done to a glib window but I have a opencv image. Is there something like cv2.add_overlay(image, shape)?

David Kachlon
  • 599
  • 2
  • 5
  • 17

1 Answers1

0

First we write a method to convert the shape to opencv compatible format like numpy array using :

def shape_to_np(shape, dtype="int"):
    # initialize the list of (x, y)-coordinates
    coords = np.zeros((68, 2), dtype=dtype)

    # loop over the 68 facial landmarks and convert them
    # to a 2-tuple of (x, y)-coordinates
    for i in range(0, 68):
        coords[i] = (shape.part(i).x, shape.part(i).y)

    # return the list of (x, y)-coordinates
    return coords

Then use it like :

shape = shape_to_np(shape)

# loop over the (x, y)-coordinates for the facial landmarks
# and draw them on the image
for (x, y) in shape:
    cv2.circle(image, (x, y), 1, (0, 0, 255), -1)
Amol B.
  • 164
  • 4