Dlib + OpenCV Draw Points Landsmark
Dlib + OpenCV Draw Points Landsmark
I would like to draw contour of the cheek, as in the image below:
I am using OpenCV and Dlib to detect the landmarks, And I do not know how to manipulate the Dlib points. Does anyone know how I can make the contour on the cheek?
Here is my code:
import cv2
import dlib
import numpy as np
def imprimePontos (imagem, pontosFaciais):
for p in pontosFaciais.parts():
cv2.circle(imagem, (p.x, p.y), 2, (0, 255,0) ,4)
def imprimeNumeros (imagem, pontosFaciais):
for i, p in enumerate (pontosFaciais.parts()):
cv2.putText(imagem, str(i), (p.x, p.y), fonte, .55, (0, 0, 255),1)
def points (imagem, pontosFaciais): #here where a draw de points
p68 =[[15, 47, False],
[47, 28, False],
[28, 30, False],
[30, 12, False]]
for k in range(0, len(p68)):
pontos =
for i in range(p68[k] [0], p68[k][1] + 1):
ponto = [pontosFaciais.part(i).x, pontosFaciais.part(i).y]
pontos.append(ponto)
pontos = np.array(pontos, dtype=np.int32)
cv2.polylines(imagem, [pontos], p68 [k][2], (255, 0, 0), 2)
fonte = cv2.FONT_HERSHEY_COMPLEX_SMALL
imagem = cv2.imread('1.jpg')
detectorface = dlib.get_frontal_face_detector()
detectorpontosfaciais =
dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
facesDetectadas = detectorface(imagem, 2)
for face in facesDetectadas:
pontos = detectorpontosfaciais(imagem, face)
print(pontos.parts())
#imprimePontos(imagem, pontos)
#imprimeNumeros(imagem, pontos)
points(imagem, pontos)
cv2.imshow("Bucheca", imagem)
cv2.waitKey()
cv2.destroyAllWindows()
This is my output:
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.