(image, shape, colors=None, alpha=0.75)
| 54 | return coords |
| 55 | |
| 56 | def visualize_facial_landmarks(image, shape, colors=None, alpha=0.75): |
| 57 | # create two copies of the input image -- one for the |
| 58 | # overlay and one for the final output image |
| 59 | overlay = image.copy() |
| 60 | output = image.copy() |
| 61 | |
| 62 | # if the colors list is None, initialize it with a unique |
| 63 | # color for each facial landmark region |
| 64 | if colors is None: |
| 65 | colors = [(19, 199, 109), (79, 76, 240), (230, 159, 23), |
| 66 | (168, 100, 168), (158, 163, 32), |
| 67 | (163, 38, 32), (180, 42, 220), (0, 0, 255)] |
| 68 | |
| 69 | # loop over the facial landmark regions individually |
| 70 | for (i, name) in enumerate(FACIAL_LANDMARKS_IDXS.keys()): |
| 71 | # grab the (x, y)-coordinates associated with the |
| 72 | # face landmark |
| 73 | (j, k) = FACIAL_LANDMARKS_IDXS[name] |
| 74 | pts = shape[j:k] |
| 75 | |
| 76 | # check if are supposed to draw the jawline |
| 77 | if name == "jaw": |
| 78 | # since the jawline is a non-enclosed facial region, |
| 79 | # just draw lines between the (x, y)-coordinates |
| 80 | for l in range(1, len(pts)): |
| 81 | ptA = tuple(pts[l - 1]) |
| 82 | ptB = tuple(pts[l]) |
| 83 | cv2.line(overlay, ptA, ptB, colors[i], 2) |
| 84 | |
| 85 | # otherwise, compute the convex hull of the facial |
| 86 | # landmark coordinates points and display it |
| 87 | else: |
| 88 | hull = cv2.convexHull(pts) |
| 89 | cv2.drawContours(overlay, [hull], -1, colors[i], -1) |
| 90 | |
| 91 | # apply the transparent overlay |
| 92 | cv2.addWeighted(overlay, alpha, output, 1 - alpha, 0, output) |
| 93 | |
| 94 | # return the output image |
| 95 | return output |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…